DoxigAlpha

add

Adds two field elements (mod m).

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 add(self: Self, x: Fe, y: Fe) Fe {
    var out = x;
    const overflow = out.v.addWithOverflow(y.v);
    const underflow: u1 = @bitCast(ct.limbsCmpLt(out.v, self.v));
    const need_sub = ct.eql(overflow, underflow);
    _ = out.v.conditionalSubWithOverflow(need_sub, self.v);
    return out;
}