Skip to content

Commit

Permalink
remove litterals
Browse files Browse the repository at this point in the history
remove litterals of scalar field modular reduction
- use of n
- define 2^256 mod n for high part of integer to reduce
  • Loading branch information
rdubois-crypto committed Aug 23, 2024
1 parent 62f269a commit 2a42057
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/fields/SCL_wei25519.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ uint256 constant a = 19298681539552699237261830834781317975544997444273427339909
// short weierstrass second coefficient 0x41a3b6bfc668778ebe2954a4b1df36d1485ecef1ea614295796e102240891faa
uint256 constant b =55751746669818908907645289078257140818241103727901012315294400837956729358436;
uint256 constant n = 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed;
//2^256 mod n used for big integer reduction modulo n
uint256 constant _2pow256modn = 0xffffffffffffffffffffffffffffffec6ef5bf4737dcf70d6ec31748d98951d;

uint256 constant nMINUS_2 = 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3eb;

uint256 constant gx=0x2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad245a;
Expand Down
9 changes: 3 additions & 6 deletions src/lib/libSCL_EIP665.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

pragma solidity >=0.8.19 <0.9.0;

import { delta, A, c, a,b,d, p,n, gx, gy, gpow2p128_x, gpow2p128_y, pMINUS_1} from "../fields/SCL_wei25519.sol";
import { _2pow256modn, delta, A, c, a,b,d, p,n, gx, gy, gpow2p128_x, gpow2p128_y, pMINUS_1} from "../fields/SCL_wei25519.sol";
import "../modular/SCL_sqrtMod_5mod8.sol";


Expand Down Expand Up @@ -148,14 +148,11 @@ function SHA512_modq(bytes memory m) internal pure returns (uint256 h)
return h;
}

/* reduce a 512 bit number modulo curve order*/
/* reduce a 512 bit number modulo curve order, val being interpreted as the number val[0]<<256+val*/
function Red512Modq(uint256[2] memory val) internal pure returns (uint256 h)
{

return addmod(mulmod(val[0],
0xffffffffffffffffffffffffffffffec6ef5bf4737dcf70d6ec31748d98951d,
0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed)
,val[1],0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed);
return addmod(mulmod(val[0],_2pow256modn, n),val[1],n);

}

Expand Down

0 comments on commit 2a42057

Please sign in to comment.