DoxigAlpha

powPublic

Returns x^e (mod m), assuming that the exponent is public. The function remains constant time with respect to x.

Function parameters

Parameters

#

An unsigned big integer with a fixed maximum size (`max_bits`), suitable for cryptographic operations.

Functions

#
Uint
An unsigned big integer with a fixed maximum size (`max_bits`), suitable for cryptographic operations.
Modulus
A modulus, defining a finite field.

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 powPublic(self: Self, x: Fe, e: Fe) NullExponentError!Fe {
    var e_normalized = Fe{ .v = e.v.normalize() };
    var buf_: [Fe.encoded_bytes]u8 = undefined;
    var buf = buf_[0 .. math.divCeil(usize, e_normalized.v.limbs_len * t_bits, 8) catch unreachable];
    e_normalized.toBytes(buf, .little) catch unreachable;
    const leading = @clz(e_normalized.v.limbsConst()[e_normalized.v.limbs_len - carry_bits]);
    buf = buf[0 .. buf.len - leading / 8];
    return self.powWithEncodedPublicExponent(x, buf, .little);
}