pyecsca.ec.mod.gmp module

class GMPMod(x, n, ensure=True)[source]

Bases: Mod

An element x of ℤₙ. Implemented by GMP.

n: mpz[source]
x: mpz[source]
bit_length()[source]

Compute the bit length of this element (in its positive integer representation).

Returns:

The bit-length.

inverse()[source]

Invert the element.

Return type:

GMPMod

Returns:

The inverse.

Raises:

NonInvertibleError if the element is not invertible.

is_residue()[source]

Whether this element is a quadratic residue (only implemented for prime modulus).

Return type:

bool

sqrt()[source]

Compute the modular square root of this element (only implemented for prime modulus).

Uses the Tonelli-Shanks algorithm.

Return type:

GMPMod

classmethod random(n)[source]

Generate a random Mod in ℤₙ.

Parameters:

n (int) – The order.

Return type:

Mod

Returns:

The random Mod.