Encode

Encode module

class fips.FIPS204.encode.ENCODE(parameter)[source]

Bases: object

Translate keys and signature for MLDSA into byte strings.

Parameters:

parameter (dict[str, int])

pkEncode(rho, t1_vec)[source]

Algorithm 22

Encodes a public key for MLDSA into a bytestring.

Parameters:
  • rho (bytes) – The 32-byte seed.

  • t1_vec (list[list[int]]) – The vector of k polynomials for t₁.

Returns:

The final encoded public key as a bytestring.

Return type:

bytes

Raises:

ValueError – if rho or t1_vec are of incorrect types or lengths.

pkDecode(pk)[source]

Algorithm 23

Reverses the procedure pkEncode.

Parameters:

pk (bytes) –

public key bytestring:

Byte string of length 32 + k * length_p, where length_p = ceil(256 * bitlen(q-1)-d / 8)

Returns:

32-byte seed rho.

t1(list[int]): List of k polynomials, each with

256 coefficients in the range [0, 2^(bitlen(q-1)-d) - 1].

Return type:

tuple[bytes, list[list[int]]]

Raises:

ValueError – if pk is of incorrect type.

skEncode(rho, K_seed, tr, s1_vec, s2_vec, t0_vec)[source]

Algorithm 24

Encodes a secret key for MLDSA into a bytestring.

Parameters:
  • rho (bytes) – The 32-byte seed.

  • K_seed (bytes) – The 32-byte K seed.

  • tr (bytes) – The 64-byte tr value.

  • s1_vec (list[list[int]]) – The vector of l polynomials for s₁.

  • s2_vec (list[list[int]]) – The vector of k polynomials for s₂.

  • t0_vec (list[list[int]]) – The vector of k polynomials for t₀.

Returns:

The final encoded private key as a bytestring.

Return type:

bytes

Raises:

ValueError – if rho, K_seed, tr, s₁_vec, s2_vec, or t0_vec are of incorrect types or lengths.

skDecode(private_key)[source]

Algorithm 25

Reverses the procedure performed by skEncode.

Parameters:

private_key (bytes) – The byte string representing the private key.

Returns:

A tuple containing (rho, K_seed, tr, s₁, s2, t0_vec).

Return type:

(Tuple[ bytes, bytes, bytes, list, list , list])

Raises:

ValueError – if private_key is of incorrect type.

sigEncode(c_tilda, z, h)[source]

Algorithm 26

Encodes a signature into a bytestring.

Parameters:
  • c_tilda (bytes) – The byte string representing c_tilda.

  • z (list[list[int]]) – The list of l polynomials representing z.

  • h (list[list[int]]) – The list representing the hint vector h.

Returns:

The final encoded signature as a bytestring.

Return type:

signature (bytes)

Raises:

ValueError – if c_tilda, z, or h are of incorrect types or lengths.

sigDecode(signature)[source]

Algorithm 27

Reverses the procedue sigEncode.

Parameters:

signature (bytes) – The bytestring representing the signature.

Returns:

A tuple containing the decoded components.

Return type:

tuple[bytes | bytearray, list[list[int]], list[list[int]] | None]

Raises:

ValueError – if signature is of incorrect type.

w1Encode(w)[source]

Algorithm 28

Encodes a polynomial vector w₁ into a bytestring.

Parameters:

w (list[list[int]]) – The list of k polynomials representing w.

Returns:

The encoded byte string w₁.

Return type:

w₁ (bytes)

Raises:

ValueError – if w is of incorrect type or length.