Skip to content

Commit

Permalink
Optimize X25519
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jan 28, 2022
1 parent 3a3a53c commit c744ddb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ verifyBatch x 888 ops/sec @ 1ms/op
Point.fromHex decompression x 11,783 ops/sec @ 84μs/op
ristretto255#fromHash x 5,482 ops/sec @ 182μs/op
ristretto255 round x 5,621 ops/sec @ 177μs/op
curve25519.scalarMultBase x 1,042 ops/sec @ 959μs/op
ed25519.getSharedSecret x 801 ops/sec @ 1ms/op
curve25519.scalarMultBase x 1,113 ops/sec @ 898μs/op
ed25519.getSharedSecret x 844 ops/sec @ 1ms/op
```

Compare to alternative implementations:
Expand Down
14 changes: 7 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,17 +913,17 @@ function montgomeryLadder(pointU: bigint, scalar: bigint): bigint {
z_3 = sw[1];
swap = k_t;

const A = mod(x_2 + z_2);
const A = x_2 + z_2;
const AA = mod(A * A);
const B = mod(x_2 - z_2);
const B = x_2 - z_2;
const BB = mod(B * B);
const E = mod(AA - BB);
const C = mod(x_3 + z_3);
const D = mod(x_3 - z_3);
const E = AA - BB;
const C = x_3 + z_3;
const D = x_3 - z_3;
const DA = mod(D * A);
const CB = mod(C * B);
x_3 = mod(mod(DA + CB) ** _2n);
z_3 = mod(x_1 * mod(DA - CB) ** _2n);
x_3 = mod((DA + CB) ** _2n);
z_3 = mod(x_1 * (DA - CB) ** _2n);
x_2 = mod(AA * BB);
z_2 = mod(E * (AA + mod(a24 * E)));
}
Expand Down

0 comments on commit c744ddb

Please sign in to comment.