Auxilary¶
Auxilary module¶
- class fips.FIPS204.auxilary.AUXILARY(parameter)[source]¶
Bases:
objectThis class provides subroutines utilized by MLDSA, including function for data-type converstions and arithmetic.
- Parameters:
parameter (dict[str, int])
- IntegerToBits(x, alpha)[source]¶
Algorithm 9
Computes the base-2 representation of x mod 2^alpha in
little-endianorder.- Parameters:
x (
int) – Anon-negativeinteger.alpha (
int) – Number ofbitsto represent.
- Returns:
Bitstringof lengthalphainlittle-endianorder.- Return type:
str (
bits)- Raises:
ValueError – If x is
negativeor alpha is not a positive integer.ValueError – If x is
too bigto be represented in alpha bits.TypeError – If x or alpha is
not an integer.
- BitsToInteger(y, alpha)[source]¶
Algorithm 10
Computes the
integervalue expressed by a bit string usinglittle-endianorder.- Parameters:
y (
str) –Bitstringto convert to an integer.alpha (
int) – Number ofbitsto consider.
- Returns:
The
integervalue represented by thebitstring.- Return type:
int- Raises:
ValueError – If the length of
ydoes not match alpha or ifycontains invalid characters.TypeError – If
yis not astringor alpha is not aninteger.
- IntegerToBytes(x, alpha)[source]¶
Algorithm 11
Computes a base-256 representation of x mod 256^alpha in
little-endianorder.- Parameters:
x (
int) – Anon-negativeinteger.alpha (
int) – Number ofbytesin the output.
- Returns:
Bytestringof length alpha inlittle-endianorder.- Return type:
bytes- Raises:
ValueError – x = _ cannot be represented in _ bytes.
- BitsToBytes(y)[source]¶
Algorithm 12
Converts a
bitstringy into abytestringusinglittle-endianorder.- Parameters:
y (
str) –Bitstringconsisting of0and1.- Returns:
Bytestringof length ceil(len(y) / 8).- Return type:
bytes- Raises:
TypeError – If y is
not a string.ValueError – If y contains characters other than
0or1.
- BytesToBits(z)[source]¶
Algorithm 13
Converts a
bytestringzinto abitstringinlittle-endianorder.- Parameters:
z (
bytes) – Abytestring.- Returns:
A
bitstringof length8 * len(z), inlittle-endianorder.- Return type:
str- Raises:
TypeError – If
zis not abytesobject.
- CoeffFromThreeBytes(b0, b1, b2)[source]¶
Algorithm 14
Generates an element of {
0,1,2, … ,q - 1} U {None}- Parameters:
b0 (
int) – first byteb1 (
int) – second byteb2 (
int) – third byte
- Returns:
sampled coefficient or
Noneif rejected.- Return type:
int|None- Raises:
TypeError – if any of
b0,b1,b2isnot an integer.
- CoeffFromHalfByte(b)[source]¶
Algorithm 15
Let
eta∈ {2, 4}.Generates an element of {
-eta,-eta + 1, … ,eta} U {None}- Parameters:
b (
int) – an integer in the range0 - 15.- Returns:
sampled coefficient or
Noneif rejected.- Return type:
int|None- Raises:
TypeError – if b is
not an integer.ValueError – if b is
notin the range0 - 15.
- CenteredModulus(z)[source]¶
Additional Helper Function 1
Computes the centered modulus
z mod± q.Maps each integer
xto the uniquerin[-(q-1)/2, (q-1)/2]
such that
x ≡ r (mod q).
- Parameters:
z (
int) – An integer- Return type:
int- Returns:
CenteredModulus(
int)- Raises:
TypeError – If
zisnot an integer.
- CenteredModulusList(z)[source]¶
Additional Helper Function 2
Computes the centered modulus
z mod± qfor alistofIntegers.Maps each integer
xto the uniquerin[-(q-1)/2, (q-1)/2]
such that
x ≡ r (mod q).
- Parameters:
z (
list[int]) – A list ofintegers.- Return type:
list[int]- Returns:
CenteredModulus(
list[int])- Raises:
TypeError – If
zis not alist[int].
- CenteredModulusMatrix(z)[source]¶
Additional Helper Function 3
Computes the centered modulus
z mod± qfor amatrixofIntegers.Maps each integer
xto the uniquerin[-(q-1)/2, (q-1)/2]
such that
x ≡ r (mod q).
- Parameters:
z (
list[list[int]]) – A matrix ofintegers.- Return type:
list[list[int]]- Returns:
CenteredModulus(
list[list[int]])- Raises:
TypeError – If
zis not alist[list[int]].
- abs_for_list(z)[source]¶
Additional Helper Function 4
Computes the absolute values of a
listof integers.- Parameters:
z (
list[int]) – Alistof integers.- Returns:
A
listcontaining theabsolutevalues of the inputintegers.- Return type:
list[int]
- InfinityNorm(z)[source]¶
Additional Helper Function 5
Compute the
L-Infinity Normof aMatrix.- Parameters:
z (
list[list[int]]) – AMatrixof integers.- Returns:
The infinity norm (
maximumabsolute value) among all lists.- Return type:
int- Raises:
TypeError – If
zis not a list of lists ofintegers.TypeError – If any element in the sublists is
not an integer.TypeError – If elements of
z[x]are not lists.
- CalcOnes(h)[source]¶
Additional Helper Function 6
Compute the number of
1s inside alist[list[int]].- Parameters:
h (
list[list[int]]) – Amatrixcontaining0s and1s.- Returns:
The count of
1s in thematrix.- Return type:
int- Raises:
TypeError – If
his not amatrixof integers.TypeError – If any element in the sublists is not an integer .
TypeError – If elements of
h[x]are not0or1.