fn Modulus(comptime max_bits: comptime_int) type
A modulus, defining a finite field. All operations within the field are performed modulo this modulus, without heap allocations. max_bits
represents the number of bits in the maximum value the modulus can be set to.
Functions
fn fromBytes(bytes: []const u8, comptime endian: builtin.Endian) InvalidModulusError || OverflowError!Self
Creates a new modulus from a byte string.
fn fromMontgomery(self: Self, x: *Fe) RepresentationError!void
Takes a field element out of the Montgomery form.
fn fromPrimitive(comptime T: type, x: T) InvalidModulusError || OverflowError!Self
Creates a new modulus from a primitive value. The modulus must be odd and large…
Creates a new modulus from a primitive value. The modulus must be odd and larger than 2.
fn powPublic(self: Self, x: Fe, e: Fe) NullExponentError!Fe
Returns x^e (mod m), assuming that the exponent is public. The function remains…
Returns x^e (mod m), assuming that the exponent is public. The function remains constant time with respect to
x
.fn powWithEncodedExponent(self: Self, x: Fe, e: []const u8, endian: builtin.Endian) NullExponentError!Fe
Returns x^e (mod m), assuming that the exponent is public, and provided as a byt…
Returns x^e (mod m), assuming that the exponent is public, and provided as a byte string. Exponents are usually small, so this function is faster than
powPublic
as a field element doesn’t have to be created if a serialized representation is already available.fn rejectNonCanonical(self: Self, fe: Fe) error{NonCanonical}!void
Rejects field elements that are not in the canonical form.
fn toBytes(self: Self, bytes: []u8, comptime endian: builtin.Endian) OverflowError!void
Serializes the modulus to a byte string.
fn toMontgomery(self: Self, x: *Fe) RepresentationError!void
Converts a field element to the Montgomery form.