diff --git a/lib/std/crypto/ff.zig b/lib/std/crypto/ff.zig index 4e599b67c48fff0e8f7241e821398ce36b2972e8..ea97d69f27aa4bb2ea27a8d35b3079a554028083 100644 --- a/lib/std/crypto/ff.zig +++ b/lib/std/crypto/ff.zig @@ -207,8 +207,8 @@ pub fn Uint(comptime max_bits: comptime_int) type { pub fn compare(x: Self, y: Self) math.Order { return crypto.timing_safe.compare( Limb, - x.limbsConst(), - y.limbsConst(), + &x.limbs_buffer, + &y.limbs_buffer, .little, ); } @@ -223,6 +223,11 @@ pub fn Uint(comptime max_bits: comptime_int) type { return @as(u1, @truncate(x.limbsConst()[0])) != 0; } + pub fn isOne(x: Self) bool { + const x_limbs = x.limbsConst(); + return ct.eql((x_limbs[0] ^ 1) | orLimbs(x_limbs[1..]), 0); + } + /// Adds `y` to `x`, and returns `true` if the operation overflowed. pub fn addWithOverflow(x: *Self, y: Self) u1 { return x.conditionalAddWithOverflow(true, y);