Skip to main content

Module point_codec

Module point_codec 

Source
Expand description

Projective Edwards point compression and paired batch inversion.

§Edwards Point Compression

Ed25519 compression converts a projective point (X:Y:Z) to affine x=X/Z, y=Y/Z, then emits the 255-bit canonical y value with the parity of x in bit 255. The active backend compresses two points with one inversion:

u = 1 / (Za * Zr)
1 / Za = u * Zr
1 / Zr = u * Za

The inversion is a fixed addition chain for exponent p-2. No data-dependent loop or early exit is used.

§point_compress_pair_stream

Source: crates/rhdl_ed25519_fast_point_codec/rtl/point_compress_pair_stream.sv.

One instance retains several point pairs and interleaves their multiplication steps through one II=1 radix51_field_mul_pipe.

§Parameters

ParameterDefaultActive per-way valueMeaning
TAG_BITS1614 for the current signer pair tagMetadata width
CONTEXTS124Number of pair-compression contexts retained by one instance
CONTEXT_BITS42Context index width; active settings match log2(CONTEXTS)
FIELD_LATENCY1717Context/tag delay matching the field multiplier

The three local states are ST_FREE for allocation, ST_READY for a context eligible to issue its next multiplication, and ST_WAIT while that result is in flight.

§Ports

PortDirectionMeaning
clk, rstinputClock and synchronous reset
valid_ininputQualifies both projective points and tag_in
ready_inoutputAt least one pair context is free
a_x_in, a_y_in, a_z_ininput, 255 bits eachFirst projective point, conventionally public-key point A during legacy use
r_x_in, r_y_in, r_z_ininput, 255 bits eachSecond projective point, conventionally nonce point R
tag_ininput, TAG_BITSOpaque pair metadata
valid_outoutputOne-cycle pulse when both encodings are ready
tag_outoutput, TAG_BITSDelayed pair tag
a_compressed_outoutput, 256 bits{parity(Xa/Za), Ya/Za}
r_compressed_outoutput, 256 bits{parity(Xr/Zr), Yr/Zr}

§Scheduler and retained state

Allocation chooses the first ST_FREE context. The issue scheduler advances by context pairs and toggles issue_pair_prefer_odd, giving both contexts in a pair an opportunity before moving on. context_pipe and tag_valid_pipe track the 17-position field result. Per context, step, squares_left, and after_square control the fixed exponentiation sequence; temp0 through temp2 hold named powers.

§Addition-chain steps

The first request multiplies Za*Zr and labels the completion as step 31. Steps 0 through 14 then compute its inverse with a standard Curve25519 fixed chain:

Completion stepNext operation or retained value
31Save Za*Zr as base; square it
0Save square as temp0; square again
1Square again
2Multiply by base
3Save in temp1; multiply by temp0
4Save in temp0; square
5Multiply by temp1
6Save in temp1; schedule 5 squarings, then multiply by temp1
7Save in temp1; schedule 10 squarings, then multiply by temp1
8Save in temp2; schedule 20 squarings, then multiply by temp2
9Schedule 10 squarings, then multiply by temp1
10Save in temp2; schedule 50 squarings, then multiply by temp2
11Save in temp1; schedule 100 squarings, then multiply by temp1
12Schedule 50 squarings, then multiply by temp2
13Schedule 5 squarings, then multiply by temp0
14The result is 1/(Za*Zr); begin affine recovery

Affine recovery uses steps 15 through 20:

StepOperation and use
15Multiply inverse product by Zr to obtain 1/Za
16Multiply inverse product by Za to obtain 1/Zr
17Multiply Xa by 1/Za; retain bit 0 as affine_a_sign
18Multiply Ya by 1/Za; retain affine ya in base
19Multiply Xr by 1/Zr; retain bit 0 as affine_r_sign
20/default completionMultiply Yr by 1/Zr, assemble both encodings, pulse valid, and free the context

The state schedule is fixed for every input point pair.

§point_compress_pair_parallel4

Source: crates/rhdl_ed25519_fast_point_codec/rtl/point_compress_pair_stream.sv.

The active signer instantiates this wrapper. It creates four physical point_compress_pair_stream ways, each configured for four contexts and one field multiplier. Thus 16 point pairs can be in flight without one global 16-way operand mux.

§Parameters

ParameterDefaultMeaning
TAG_BITS16Pair metadata width passed unchanged into every way
FIELD_LATENCY17Field multiplier return delay passed to every way
LANES4Number of independent pair-compression ways

The local constant QUEUE_DEPTH=4 fixes each way’s result FIFO depth. The active signer retains the four-lane default.

§Ports

The wrapper has the same clk, rst, valid_in, ready_in, two point input triples, tag_in, valid_out, tag_out, and two compressed outputs as point_compress_pair_stream. ready_in means at least one way is ready.

input_rr distributes accepted pairs round-robin among ready ways. Each way can finish several resident inversion chains close together, so its outputs enter a four-entry local queue. output_rr drains nonempty queues round-robin and emits at most one pair per cycle. A simulation-only fatal check detects queue overflow; there is no output backpressure port.

Current matching-source OOC synthesis attributes 84,295 LUTs, 67,702 registers, no block RAM, and 2,092 DSP48E2s to the four-way codec. The DSP total is exactly four 523-DSP field multipliers. The integrated signer profile issues and completes 257 pair requests while processing one key point and 512 nonce points. A focused throughput test currently overrides LANES=6 and reports 223.659 cycles/pair for that six-lane experiment; it is not the service interval of this active four-lane wrapper.

§Legacy point_compress_stream

Source: crates/rhdl_ed25519_fast_point_codec/rtl/point_compress_stream.sv.

This predecessor compresses one point per context rather than sharing one inversion across two points. It is not instantiated by the active core.

§Parameters

ParameterDefaultMeaning
TAG_BITS16Metadata width
CONTEXTS16Number of interleaved inversion contexts
CONTEXT_BITS4Context index width
FIELD_LATENCY16Multiplier result/tag delay

§Ports

Inputs are clk, rst, valid_in, projective x_in, y_in, z_in, and tag_in. Outputs are ready_in, valid_out, tag_out, and 256-bit compressed_out.

States ST_FREE, ST_CHAIN_READY, and ST_CHAIN_WAIT manage inversion; ST_AFFINE_READY and ST_AFFINE_WAIT issue X/Z and Y/Z. It runs the same steps 0 through 14 over z, then schedules two affine products. The first result supplies the sign bit; the second supplies affine y and completes compressed_out = {x_parity,y}.