Hint

Hint module

class fips.FIPS204.hint.HINT(parameter)[source]

Bases: object

contains power2round, highbits, lowbits, makehint and use hint.

Parameters:

parameter (dict[str, int])

Power2Round(r)[source]

Algorithm 35

Decomposes an integer r into (r1, r0) such that

r ≡ r1 * (2 * d) + r0 (mod q)
Parameters:

r (int) – An integer coefficient.

Returns:

A tuple containing the high bits r₁ and low bits r₀.

Return type:

tuple[int, int]

Power2RoundVector(t_vec)[source]

Algorithm 35 modified

Applies Power2Round component-wise to a vector of polynomials.

Parameters:

t_vec (list[list[int]]) – A vector of polynomials.

Returns:

Tuple(t₁, t₀) of two vectors of polynomials, where t₁ contains the high bits and t₀ contains the low bits.

Return type:

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

Raises:

TypeError – If the input is not a list or tuple, or if any polynomial or coefficient is not an integer.

Decompose(r)[source]

Algorithm 36

Decompose r into (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:

  • r1 The high bits.

  • r0 The low bits in the range [-2^(d-1)+1, 2^(d-1)].

Raises:

TypeError – If r is not an integer.

HighBits(r)[source]

Algorithm 37

Returns r1 from the output of Decompose(r).

Parameters:

r (int) – An integer in the range [0, q-1].

Returns:

The high bits r1.

Return type:

int

Raises:

TypeError – If r is not an integer.

LowBits(r)[source]

Algorithm 38

Returns r0 from the output of Decompose(r).

Parameters:

r (int) – An integer in the range [0, q-1].

Returns:

The low bits r0.

Return type:

int

Raises:

TypeError – If r is not an integer.

MakeHint(z, r)[source]

Algorithm 39

Computes hint bit indicating whether adding z to r alters the high bits of r.

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 z or r is not an integer.

UseHint(h, r)[source]

Algorithm 40

Returns the high bits of r adjusted according to hint 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 h is not a boolean.

  • TypeError – If r is not an integer.