Skip to main content

Module encode

Module encode 

Source
Expand description

Encoding and decoding of keys, signatures, and polynomials. Encoding and decoding algorithms for ML-DSA (FIPS 204, Algorithms 9-28).

Provides bit-level packing and unpacking of polynomials and polynomial vectors into compact byte representations, as well as the Power2Round decomposition used during key generation.

All vector functions accept slices (&[[i32; N]]) instead of &Vec<...> to avoid requiring heap-allocated containers.

§Stability (hazmat tier)

This module is part of the hazmat expert building-block layer: it is public only with the hazmat Cargo feature, for KAT/test-vector tooling and research. Read each function’s invariants before use. No stability, misuse-resistance, or side-channel promise applies to this tier — its API may change in any release. The typed facade is the guaranteed API.

Functions§

bit_pack
Pack a polynomial whose coefficients lie in [-a, b].
bit_unpack
Unpack a polynomial whose coefficients lie in [-a, b].
hint_bit_pack
Pack a hint vector into bytes.
hint_bit_unpack
Unpack a hint vector from bytes.
pk_decode
Decode a public key from bytes.
pk_encode
Encode a public key as bytes.
power2round
Decompose a coefficient into high and low parts using a power-of-2 divisor.
power2round_vec
Apply power2round to every coefficient of a polynomial vector.
sig_decode
Decode a signature from bytes.
sig_encode
Encode a signature as bytes.
simple_bit_pack
Pack a polynomial whose coefficients lie in [0, b].
simple_bit_unpack
Unpack a polynomial whose coefficients lie in [0, b].
sk_decode
Decode a secret key from bytes.
sk_decode_s1
Decode a single polynomial of s1 from the packed secret key.
sk_decode_s2
Decode a single polynomial of s2 from the packed secret key.
sk_decode_seeds
Decode only the seeds (rho, K, tr) from a secret key, without unpacking any polynomial. Returns 128 bytes of stack.
sk_decode_t0
Decode a single polynomial of t0 from the packed secret key.
sk_encode
Encode a secret key as bytes.
w1_encode
Encode the high-order bits vector w1 as bytes.

Type Aliases§

DecodedSecretKey
Decoded ML-DSA secret-key components (rho, K, tr, s1, s2, t0) (FIPS 204 skDecode).
DecodedSignature
Decoded ML-DSA signature components (c_tilde, z, h) (FIPS 204 sigDecode).