Encode¶
Encode module¶
- class fips.FIPS204.encode.ENCODE(parameter)[source]¶
Bases:
objectTranslate keys and signature for MLDSA into byte strings.
- Parameters:
parameter (dict[str, int])
- pkEncode(rho, t1_vec)[source]¶
Algorithm 22
Encodes a
public keyfor MLDSA into abytestring.- Parameters:
rho (
bytes) – The32-byteseed.t1_vec (
list[list[int]]) – The vector ofkpolynomials fort₁.
- Returns:
The final encoded
public keyas abytestring.- Return type:
bytes- Raises:
ValueError – if
rhoort1_vecare 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 ofkpolynomials, each with256 coefficients in the range [0, 2^(bitlen(q-1)-d) - 1].
- Return type:
tuple[bytes,list[list[int]]]- Raises:
ValueError – if
pkis of incorrect type.
- skEncode(rho, K_seed, tr, s1_vec, s2_vec, t0_vec)[source]¶
Algorithm 24
Encodes a
secret keyfor MLDSA into abytestring.- Parameters:
rho (
bytes) – The 32-byte seed.K_seed (
bytes) – The 32-byteKseed.tr (
bytes) – The 64-bytetrvalue.s1_vec (
list[list[int]]) – The vector oflpolynomials fors₁.s2_vec (
list[list[int]]) – The vector ofkpolynomials fors₂.t0_vec (
list[list[int]]) – The vector ofkpolynomials fort₀.
- Returns:
The final encoded private key as a
bytestring.- Return type:
bytes- Raises:
ValueError – if
rho,K_seed,tr,s₁_vec,s2_vec, ort0_vecare 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 theprivate 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
signatureinto abytestring.- Parameters:
c_tilda (
bytes) – The byte string representingc_tilda.z (
list[list[int]]) – The list oflpolynomials representingz.h (
list[list[int]]) – The list representing the hint vectorh.
- Returns:
The final encoded signature as a
bytestring.- Return type:
signature (
bytes)- Raises:
ValueError – if
c_tilda,z, orhare of incorrect types or lengths.
- sigDecode(signature)[source]¶
Algorithm 27
Reverses the procedue
sigEncode.- Parameters:
signature (
bytes) – Thebytestringrepresenting 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.