Hint¶
Hint module¶
- class fips.FIPS204.hint.HINT(parameter)[source]¶
Bases:
objectcontains power2round, highbits, lowbits, makehint and use hint.
- Parameters:
parameter (dict[str, int])
- Power2Round(r)[source]¶
Algorithm 35
Decomposes an integer
rinto (r1, r0) such thatr ≡ r1 * (2 * d) + r0 (mod q)
- Parameters:
r (
int) – An integer coefficient.- Returns:
A tuple containing the
high bits r₁andlow bits r₀.- Return type:
tuple[int,int]
- Power2RoundVector(t_vec)[source]¶
Algorithm 35 modified
Applies
Power2Roundcomponent-wise to avectorof polynomials.- Parameters:
t_vec (
list[list[int]]) – A vector of polynomials.- Returns:
Tuple(t₁, t₀)of two vectors of polynomials, wheret₁contains thehigh bitsandt₀contains thelow bits.- Return type:
tuple[list[list[int]],list[list[int]]]- Raises:
TypeError – If the input is not a
listortuple, or if any polynomial or coefficient isnot an integer.
- Decompose(r)[source]¶
Algorithm 36
Decompose
rinto(r1, r0)such that:r ≡ r1 * (2 * gamma2) + r0 (mod q)
- Parameters:
r (
int) – Integer in the range[0, q - 1].- Return type:
tuple[int,int]- Returns:
r1The high bits.r0The low bits in the range[-2^(d-1)+1, 2^(d-1)].
- Raises:
TypeError – If
ris not an integer.
- HighBits(r)[source]¶
Algorithm 37
Returns
r1from the output ofDecompose(r).- Parameters:
r (
int) – An integer in the range[0, q-1].- Returns:
The high bits
r1.- Return type:
int- Raises:
TypeError – If
ris not an integer.
- LowBits(r)[source]¶
Algorithm 38
Returns
r0from the output ofDecompose(r).- Parameters:
r (
int) – An integer in the range[0, q-1].- Returns:
The low bits
r0.- Return type:
int- Raises:
TypeError – If
ris not an integer.
- MakeHint(z, r)[source]¶
Algorithm 39
Computes
hint bitindicating whether addingztoralters thehigh bitsofr.- Parameters:
z (
int) – An integer in the range[0, q-1].r (
int) – An integer in the range[0, q-1].
- Returns:
True if the high bits change, False otherwise.
- Return type:
bool- Raises:
TypeError – If
zorris not an integer.
- UseHint(h, r)[source]¶
Algorithm 40
Returns the
high bitsofradjusted according tohint h.- Parameters:
h (
bool) – The hint bit.r (
int) – An integer in the range[0, q-1].
- Returns:
The adjusted high bit.
- Return type:
int- Raises:
TypeError – If
hisnot a boolean.TypeError – If
risnot an integer.