nmod.h – integers mod n (word-size n)¶
Modular reduction and arithmetic¶
-
void
nmod_init(nmod_t *mod, mp_limb_t n)¶ Initialises the given
nmod_tstructure for reduction modulo \(n\) with a precomputed inverse.
-
NMOD_BITS(mod)¶ Macro giving the number of bits in
mod.n.
-
NMOD_CAN_USE_SHOUP(mod)¶ Macro returning whether Shoup’s algorithm can be used for preconditioned multiplication mod
mod.n.
-
NMOD_RED2(r, a_hi, a_lo, mod)¶ Macro to set \(r\) to \(a\) reduced modulo
mod.n, where \(a\) consists of two limbs(a_hi, a_lo). Themodparameter must be a validnmod_tstructure. It is assumed thata_hiis already reduced modulomod.n.
-
NMOD_RED(r, a, mod)¶ Macro to set \(r\) to \(a\) reduced modulo
mod.n. Themodparameter must be a validnmod_tstructure.
-
NMOD2_RED2(r, a_hi, a_lo, mod)¶ Macro to set \(r\) to \(a\) reduced modulo
mod.n, where \(a\) consists of two limbs(a_hi, a_lo). Themodparameter must be a validnmod_tstructure. No assumptions are made abouta_hi.
-
NMOD_RED3(r, a_hi, a_me, a_lo, mod)¶ Macro to set \(r\) to \(a\) reduced modulo
mod.n, where \(a\) consists of three limbs(a_hi, a_me, a_lo). Themodparameter must be a validnmod_tstructure. It is assumed thata_hiis already reduced modulomod.n.
-
NMOD_MUL_PRENORM(res, a, b, mod)¶ Macro to set \(r\) to \(ab\) modulo
mod.n. Themodparameter must be a validnmod_tstructure. It is assumed that \(a\), \(b\) are already reduced modulomod.nand that either \(a\) or \(b\) is prenormalised by left-shifting bymod.norm.
-
NMOD_MUL_FULLWORD(res, a, b, mod)¶ Macro to set \(r\) to \(ab\) modulo
mod.n. Themodparameter must be a validnmod_tstructure. It is assumed that \(a\), \(b\) are already reduced modulomod.nand thatmod.nis exactlyFLINT_BITSbits large.
-
NMOD_ADDMUL(r, a, b, mod)¶ Macro to set \(r\) to \(r + ab\) reduced modulo
mod.n. Themodparameter must be a validnmod_tstructure. It is assumed that \(r\), \(a\), \(b\) are already reduced modulomod.n.
-
mp_limb_t
_nmod_add(mp_limb_t a, mp_limb_t b, nmod_t mod)¶ Returns \(a + b\) modulo
mod.n. It is assumed thatmodis no more thanFLINT_BITS - 1bits. It is assumed that \(a\) and \(b\) are already reduced modulomod.n.
-
mp_limb_t
nmod_add(mp_limb_t a, mp_limb_t b, nmod_t mod)¶ Returns \(a + b\) modulo
mod.n. No assumptions are made aboutmod.n. It is assumed that \(a\) and \(b\) are already reduced modulomod.n.
-
mp_limb_t
_nmod_sub(mp_limb_t a, mp_limb_t b, nmod_t mod)¶ Returns \(a - b\) modulo
mod.n. It is assumed thatmodis no more thanFLINT_BITS - 1bits. It is assumed that \(a\) and \(b\) are already reduced modulomod.n.
-
mp_limb_t
nmod_sub(mp_limb_t a, mp_limb_t b, nmod_t mod)¶ Returns \(a - b\) modulo
mod.n. No assumptions are made aboutmod.n. It is assumed that \(a\) and \(b\) are already reduced modulomod.n.
-
mp_limb_t
nmod_neg(mp_limb_t a, nmod_t mod)¶ Returns \(-a\) modulo
mod.n. It is assumed that \(a\) is already reduced modulomod.n, but no assumptions are made about the latter.
-
mp_limb_t
nmod_mul(mp_limb_t a, mp_limb_t b, nmod_t mod)¶ Returns \(ab\) modulo
mod.n. No assumptions are made aboutmod.n. It is assumed that \(a\) and \(b\) are already reduced modulomod.n.
-
mp_limb_t
_nmod_mul_fullword(mp_limb_t a, mp_limb_t b, nmod_t mod)¶ Returns \(ab\) modulo
mod.n. Requires thatmod.nis exactlyFLINT_BITSlarge. It is assumed that \(a\) and \(b\) are already reduced modulomod.n.
-
mp_limb_t
nmod_inv(mp_limb_t a, nmod_t mod)¶ Returns \(a^{-1}\) modulo
mod.n. The inverse is assumed to exist.
-
mp_limb_t
nmod_div(mp_limb_t a, mp_limb_t b, nmod_t mod)¶ Returns \(ab^{-1}\) modulo
mod.n. The inverse of \(b\) is assumed to exist. It is assumed that \(a\) is already reduced modulomod.n.
-
mp_limb_t
nmod_pow_ui(mp_limb_t a, ulong e, nmod_t mod)¶ Returns \(a^e\) modulo
mod.n. No assumptions are made aboutmod.n. It is assumed that \(a\) is already reduced modulomod.n.
Discrete Logarithms via Pohlig-Hellman¶
-
void
nmod_discrete_log_pohlig_hellman_init(nmod_discrete_log_pohlig_hellman_t L)¶ Initialize
L. Upon initializationLis not ready for computation.
-
void
nmod_discrete_log_pohlig_hellman_clear(nmod_discrete_log_pohlig_hellman_t L)¶ Free any space used by
L.
-
double
nmod_discrete_log_pohlig_hellman_precompute_prime(nmod_discrete_log_pohlig_hellman_t L, mp_limb_t p)¶ Configure
Lfor discrete logarithms modulopto an internally chosen base. It is assumed thatpis prime. The return is an estimate on the number of multiplications needed for one run.
-
mp_limb_t
nmod_discrete_log_pohlig_hellman_primitive_root(const nmod_discrete_log_pohlig_hellman_t L)¶ Return the internally stored base.
-
ulong
nmod_discrete_log_pohlig_hellman_run(const nmod_discrete_log_pohlig_hellman_t L, mp_limb_t y)¶ Return the logarithm of
ywith respect to the internally stored base.yis expected to be reduced modulo thep. The function is undefined if the logarithm does not exist.