@@ -221,7 +221,7 @@ pub const G2 = struct {
221
221
// G2 does *not* have prime order, so we need to perform a secondary subgroup membership check.
222
222
// https://eprint.iacr.org/2022/348, Sec 3.1.
223
223
// [r]P == 0 <==> [x+1]P + ψ([x]P) + ψ²([x]P) = ψ³([2x]P)
224
- const xp : G2 = mulScalar (p , @bitCast ( Fp .constants .x ) );
224
+ const xp : G2 = mulScalar (p , Fp .constants .x );
225
225
226
226
const psi = xp .frob ();
227
227
const psi2 = xp .frob2 ();
@@ -464,16 +464,17 @@ fn dbl(p: anytype) @TypeOf(p) {
464
464
///
465
465
/// https://encrypt.a41.io/primitives/abstract-algebra/elliptic-curve/scalar-multiplication/double-and-add
466
466
/// https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Double-and-add
467
- fn mulScalar (a : anytype , scalar : [ 4 ] u64 ) @TypeOf (a ) {
467
+ fn mulScalar (a : anytype , scalar : u256 ) @TypeOf (a ) {
468
468
// TODO: can be further optimized with GLV and wNAF
469
- const leading = @clz (@as (u256 , @bitCast (scalar )));
469
+ const limbs : [4 ]u64 = @bitCast (scalar );
470
+ const leading = @clz (scalar );
470
471
if (leading == 256 ) return .zero ;
471
472
var i : u8 = @intCast (256 - 1 - leading );
472
473
var r = a ;
473
474
while (i > 0 ) {
474
475
i -= 1 ;
475
476
r = dbl (r );
476
- if (bit (scalar , i )) r = addMixed (r , a );
477
+ if (bit (limbs , i )) r = addMixed (r , a );
477
478
}
478
479
return r ;
479
480
}
@@ -488,7 +489,7 @@ pub fn addSyscall(out: *[64]u8, input: *const [128]u8) !void {
488
489
pub fn mulSyscall (out : * [64 ]u8 , input : * const [96 ]u8 ) ! void {
489
490
const a : G1 = try .fromBytes (input [0.. 64]);
490
491
// Scalar is provided in big-endian and we do *not* validate it.
491
- const b : [ 4 ] u64 = @bitCast (Fp .byteSwap (input [64.. ][0.. 32].* ));
492
+ const b : u256 = @bitCast (Fp .byteSwap (input [64.. ][0.. 32].* ));
492
493
const result = mulScalar (a , b );
493
494
result .toBytes (out );
494
495
}
0 commit comments