Pack¶
Pack module¶
- class fips.FIPS204.pack.PACK(parameter)[source]¶
Bases:
objectThese functions efficiently translate an element w belonging to R into a byte string and vica versa under the assumption that the coefficients of w are in a restricted range.
- Parameters:
parameter (dict[str, int])
- SimpleBitPack(w, b)[source]¶
Algorithm 16
Encodes a polynomial w into a byte string.
- Parameters:
w (
list[int]) – Polynomial coefficients, must be of length256.b (
int) – Upper bound of coefficients. Must be≥ 1.
- Returns:
bytestring of length
32 * bitlen(b), representing packedbits.- Return type:
bytes- Raises:
TypeError – If types are invalid.
ValueError – If values/lengths are out of expected bounds.
- BitPack(w, a, b)[source]¶
Algorithm 17
Encodes a polynomial
winto abytestring. :param w: List of256polynomial coefficients in[-a, b]. :type w:list[int] :param a: Lower bound (non-negative). :type a:int:param b: Upper bound (non-negative). :type b:int- Returns:
Packed byte string of length
32 * bitlen(a + b).- Return type:
bytes- Raises:
TypeError – If
wis not a list of integers ora/bare not integers.ValueError – If length of
w ≠ 256, or any coefficient is out of range.
- Parameters:
w (list[int])
a (int)
b (int)
- SimpleBitUnpack(v, b)[source]¶
Algorithm 18
Reverses a procedure
SimpleBitPack.- Parameters:
v (
bytes) – Byte string of length32 * bitlen(b), result of simple_bit_pack.b (
int) – Upper bound for the original coefficients (must be≥ 1).
- Returns:
List of
256unpacked coefficients in range[0, b].- Return type:
list[int]- Raises:
TypeError – If
vis not bytes orbis not integer.ValueError – If
vhas invalid length orbis invalid.
- BitUnpack(v, a, b)[source]¶
Algorithm 19
Reverses the procedure BitPack.
- Parameters:
v (
bytes) – Packed byte string (length =32 * bitlen(a + b)).a (
int) – Non-negative integer (lower bound).b (
int) – Non-negative integer (upper bound).
- Returns:
List of
256coefficients in the range[-a, b].- Return type:
list[int]- Raises:
TypeError – If input types are incorrect.
ValueError – If
vis invalid length ora/bare negative.
- HintBitPack(h)[source]¶
Algorithm 20
Encodes a polynomial vector
hwith binary coefficients into abytestring.- Parameters:
h (
list[list[int]]) – A list ofkpolynomials, each of256binary coefficients.- Returns:
Byte string of length
omega + krepresenting the packed hint vector.- Return type:
bytes- Raises:
ValueError – If h is malformed or contains more than omega number of 1s.
- HintBitUnpack(y)[source]¶
Algorithm 21
Reverses the procedure HintBitPack.
- Parameters:
y (
bytes) –Bytestringof lengthomega + kthat encodesh.- Returns:
h, a list ofkpolynomials, each being a list ofw-bitcoefficients.- Return type:
Matrix (
list[list[int]])- Raises:
ValueError – If
yis malformed or does not conform to expected structure.