fromPrimitive
Creates a new big integer from a primitive type. This function may not run in constant time.
Function parameters
Parameters
- T:type
- init_value: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, init_value: T) OverflowError!Self {
var x = init_value;
var out: Self = .{
.limbs_buffer = undefined,
.limbs_len = max_limbs_count,
};
for (&out.limbs_buffer) |*limb| {
limb.* = if (@bitSizeOf(T) > t_bits) @as(TLimb, @truncate(x)) else x;
x = math.shr(T, x, t_bits);
}
if (x != 0) {
return error.Overflow;
}
return out;
}