fe25519 module
Pure-Python data structure for working with Ed25519 (and Ristretto) field elements and operations.
- class fe25519(ns: Sequence[int])[source]
Bases:
objectClass for creating and operating on field elements. The public interface of this class is determined primarily by the needs of the ge25519 library. However, use of some built-in Python operators is supported via special methods.
- d = fe25519([929955233495203, 466365720129213, 1662059464998953, 2033849074728123, 1442794654840575])
- d2 = fe25519([1859910466990425, 932731440258426, 1072319116312658, 1815898335770999, 633789495995903])
- sqrtm1 = fe25519([1718705420411056, 234908883556509, 2233514472574048, 2117202627021982, 765476049583133])
- invsqrtamd = fe25519([278908739862762, 821645201101625, 8113234426968, 1777959178193151, 2118520810568447])
- onemsqd = fe25519([1136626929484150, 1998550399581263, 496427632559748, 118527312129759, 45110755273534])
- sqdmone = fe25519([1507062230895904, 1572317787530805, 683053064812840, 317374165784489, 1572899562415810])
- sqrtadm1 = fe25519([2241493124984347, 425987919032274, 2207028919301688, 1220490630685848, 974799131293748])
- curve25519_A = fe25519([486662, 0, 0, 0, 0])
- static zero() fe25519[source]
Constant corresponding to the zero element.
>>> fe25519.zero() + fe25519.one() == fe25519.one() True
- static one() fe25519[source]
Constant corresponding to the multiplicative identity element.
>>> fe25519.one() * fe25519.one() == fe25519.one() True
- copy() fe25519[source]
Create a copy of this element instance.
>>> fe25519.one().copy() == fe25519.one() True
- reduce() fe25519[source]
Reduce this element to a canonical representation.
>>> (~fe25519.one()).reduce() fe25519([1, 0, 0, 0, 0])
- __add__(other: fe25519) fe25519[source]
Compute the sum of this element and another element.
>>> fe25519.zero() + fe25519.zero() == fe25519.zero() True
- __neg__() fe25519[source]
Compute the negation of this element.
>>> fe25519.one().cneg(1) != fe25519.one() True
- cmov(g: fe25519, b: int) fe25519[source]
Conditionally select this element or another based on a boolean integer.
- cneg(b: int) fe25519[source]
Compute the conditional negation of this element.
>>> fe25519.one().cneg(0) == fe25519.one() True >>> (fe25519.one().cneg(1) + fe25519.one()).is_zero() 1
- __abs__() fe25519[source]
Compute the absolute value of this element.
>>> abs(-fe25519.one()).is_negative() 0
- __sub__(other: fe25519) fe25519[source]
Compute the result of subtracting another element from this element.
>>> fe25519.zero() - fe25519.one() == fe25519.one().cneg(1) True
- __mul__(other: fe25519) fe25519[source]
Compute the product of this element and another element.
>>> fe25519.one() * fe25519.zero() == fe25519.zero() True
- sq() fe25519[source]
Compute the square of this element.
>>> two = fe25519.one() + fe25519.one() >>> four = two + two >>> two.sq() == four True
- sq2() fe25519[source]
Compute the element that is twice the square of this element.
>>> two = fe25519.one() + fe25519.one() >>> two.sq2() == two.sq() + two.sq() True
- pow22523() fe25519[source]
Compute the result of the exponentiation of this element by a special fixed exponent.
- invert() fe25519[source]
Compute the multiplicative inverse of this element.
>>> two = fe25519.one() + fe25519.one() >>> (two.invert() * two).reduce() == fe25519.one() True
- __invert__() fe25519[source]
Compute the multiplicative inverse of this element.
>>> two = fe25519.one() + fe25519.one() >>> (((~two) * two) - fe25519.one()).is_zero() 1
- __pow__(e: int) fe25519[source]
Exponentiation is a synonym for squaring and inversion.
>>> two = fe25519.one() + fe25519.one() >>> two**2 == two * two == two.sq() True >>> ~fe25519.one() == fe25519.one() ** (-1) True
- sqrt_ratio_m1_ristretto255(v: fe25519) Tuple[fe25519, int][source]
Compute the result of a specialized root operation.
- __eq__(other: fe25519) bool[source]
Determine whether this element and another are equivalent.
>>> fe25519.zero() == fe25519.one() False >>> fe25519.one() == fe25519.one() True
- is_zero() int[source]
Determine whether this element is zero.
>>> fe25519.zero().is_zero() 1 >>> fe25519.one().is_zero() 0
- is_negative() int[source]
Determine whether the negation bit is set in this element.
>>> fe25519.zero().is_negative() 0
- static from_bytes(bs: bytes) fe25519[source]
Assemble an element instance from its byte representation.
>>> s = '0100000000000000000000000000000000000000000000000000000000000000' >>> fe25519.from_bytes(bytes.fromhex(s)) fe25519([1, 0, 0, 0, 0])
- to_bytes() bytes[source]
Build the byte representation of this element.
>>> fe25519.one().to_bytes().hex() '0100000000000000000000000000000000000000000000000000000000000000'
- __bytes__() bytes[source]
Build the byte representation of this element.
>>> bytes(fe25519.one()).hex() '0100000000000000000000000000000000000000000000000000000000000000'