Skip to main content

Module sha512

Module sha512 

Source
Expand description

SHA-512 compression worker and multi-worker request pool.

§SHA-512 Modules

The fast signer contains full hardware SHA-512 block compression. The signer builds and pads fixed-format blocks; the modules on this page apply the FIPS 180-4 compression function to one 1024-bit block and a supplied 512-bit chaining state.

§sha512_compress_3phase

Source: crates/rhdl_ed25519_fast_sha512/rtl/sha512_compress_3phase.sv.

One worker executes one SHA-512 round over three registered phases and reuses that datapath for all 80 rounds. It stores only sixteen schedule words in a circular array. One block occupies a worker for 242 cycles: 240 round-phase cycles, one accumulation cycle, and the handoff back to the ready state. This is iterative occupancy, not 242 physical pipeline stages. It is also not a 512-stage pipeline: 512 is the digest width in bits, while the physical round datapath has three reusable phase boundaries.

The module has no overridable parameters. Its state local parameters are:

StateFunction
ST_IDLEAssert ready; capture state_in and the first 16 schedule words when start is high
ST_ARead or begin extending W[t]; compute Sigma/choice, Sigma/majority, and h + K[t] partial sums
ST_BFinish an extended schedule word and form registered T1/T2 bases
ST_CCompute the new a and e, rotate the eight working words, and advance the round
ST_ACCUMAdd the original chaining words to the final working words and pulse valid_out

For every round t, the phase functions are exact:

  1. ST_A reads W[t] for rounds 0-15 or registers the two halves of the circular-schedule recurrence for rounds 16-79. In parallel it calculates Sigma1(e)+Ch(e,f,g), Sigma0(a)+Maj(a,b,c), and h+K[t].
  2. ST_B finishes an expanded schedule word when needed, writes that word back into the circular slot, and registers T1 and T2 bases.
  3. ST_C forms T1, updates a=T1+T2 and e=d+T1, shifts the other six working words, and advances to the next round or accumulation.

The three phases reduce the longest 64-bit adder chain while retaining one compact iterative worker. Throughput comes from four workers operating on different blocks, not from unrolling 80 SHA rounds.

§Ports

PortDirectionMeaning
clkinputRising-edge clock
rstinputSynchronously returns the worker to ST_IDLE and clears output validity
startinputStarts a block when ready is high
readyoutputHigh only in ST_IDLE
state_ininput, 512 bitsEight big-endian 64-bit chaining words packed from the most significant end
block_ininput, 1024 bitsSixteen big-endian 64-bit message words packed from the most significant end
valid_outoutputOne-cycle pulse when state_out is complete
state_outoutput, 512 bitsUpdated chaining state after one compression block

§Helper functions

FunctionInputsResult
rotate_right64-bit value, integer amountCircular right rotation: right-shifted and wrapped portions combined with bitwise OR
small_sigma064-bit valueROTR1(value) xor ROTR8(value) xor SHR7(value), used by the schedule
small_sigma164-bit valueROTR19(value) xor ROTR61(value) xor SHR6(value), used by the schedule
big_sigma064-bit valueROTR28(value) xor ROTR34(value) xor ROTR39(value), used in T2
big_sigma164-bit valueROTR14(value) xor ROTR18(value) xor ROTR41(value), used in T1

The 80 constants are initialized in k_rom. In the current matching-source U280 OOC build, each worker accounts for one RAMB36 constant ROM and 12 DSP48E2s. The DSPs implement registered 64-bit state and adder operations marked with use_dsp; rotate, choice, majority, and XOR logic remains in LUTs. No message padding occurs in this module.

§sha512_compress_pool

Source: crates/rhdl_ed25519_fast_sha512/rtl/sha512_compress_pool4.sv.

The pool instantiates multiple sha512_compress_3phase workers, accepts up to two block requests in one cycle, and emits up to two completions in one cycle. The current signer sets WORKERS=4.

§Parameters

ParameterDefaultMeaning
TAG_BITS8Width of opaque metadata stored beside each accepted block
WORKERS4Number of physical compression workers generated
WORKER_BITS3Width of internal worker indices; it must represent every configured worker index

§Ports

The suffix 0 or 1 identifies one of two independent request/return lanes.

Port familyDirectionMeaning
clk, rstinputShared clock and synchronous reset
request0_valid, request1_validinputRequest-lane validity
request0_ready, request1_readyoutputA free worker has been allocated to that lane
request0_state, request1_stateinput, 512 bitsStarting chaining state
request0_block, request1_blockinput, 1024 bitsMessage block
request0_tag, request1_taginput, TAG_BITSMetadata retained in the allocated worker slot
result0_valid, result1_validoutputCompletion-lane pulse
result0_state, result1_stateoutput, 512 bitsCompleted chaining state
result0_tag, result1_tagoutput, TAG_BITSTag belonging to the completed state

allocate_rr is a round-robin starting point. Request lane 0 chooses the first ready worker; request lane 1 chooses another ready worker and cannot take the worker selected by an active lane-0 request. Tags remain in per-worker registers. The result combiner scans workers in index order and places the first two simultaneous completions on result lanes 0 and 1. There is no output-ready signal, so downstream FIFOs must absorb every completion. Four current workers therefore use four RAMB36s and 48 DSP48E2s in matching OOC synthesis.