fromPrimitive
Creates a field element from a primitive. This function may not run in constant time.
Function parameters
Parameters
- T:type
- m:Modulus(bits)
- x:T
An unsigned big integer with a fixed maximum size (`max_bits`), suitable for cryptographic operations.
Functions
Error sets in this namespace
Error Sets
- OverflowError
- Value is too large for the destination.
- InvalidModulusError
- Invalid modulus.
- NullExponentError
- Exponentiation with a null exponent.
- FieldElementError
- Invalid field element for the given modulus.
- RepresentationError
- Invalid representation (Montgomery vs non-Montgomery domain.)
- Error
- The set of all possible errors `std.crypto.ff` functions can return.
Source
Implementation
pub fn fromPrimitive(comptime T: type, m: Modulus(bits), x: T) (OverflowError || FieldElementError)!Self {
comptime assert(@bitSizeOf(T) <= bits); // Primitive type is larger than the modulus type.
const v = try FeUint.fromPrimitive(T, x);
var fe = Self{ .v = v };
try m.shrink(&fe);
try m.rejectNonCanonical(fe);
return fe;
}