@@ -69,21 +69,19 @@ export function montgomery(curveDef: CurveType): MontgomeryECDH {
6969 if ( ! is25519 && type !== "x448" ) throw new Error ( "invalid type" ) ;
7070 const randomBytes_ = rand || randomBytesAsync ;
7171
72- const montgomeryBits = is25519 ? 255 : 448 ;
72+ const montgomeryBits = is25519 ? 255n : 448n ;
7373 const fieldLen = is25519 ? 32 : 56 ;
74- const Gu = is25519 ? BigInt ( 9 ) : BigInt ( 5 ) ;
74+ const Gu = is25519 ? 9n : 5n ;
7575 // RFC 7748 #5:
7676 // The constant a24 is (486662 - 2) / 4 = 121665 for curve25519/X25519 and
7777 // (156326 - 2) / 4 = 39081 for curve448/X448
7878 // const a = is25519 ? 156326n : 486662n;
79- const a24 = is25519 ? BigInt ( 121665 ) : BigInt ( 39081 ) ;
79+ const a24 = is25519 ? 121665n : 39081n ;
8080 // RFC: x25519 "the resulting integer is of the form 2^254 plus
8181 // eight times a value between 0 and 2^251 - 1 (inclusive)"
8282 // x448: "2^447 plus four times a value between 0 and 2^445 - 1 (inclusive)"
83- const minScalar = is25519 ? N_2 ** BigInt ( 254 ) : N_2 ** BigInt ( 447 ) ;
84- const maxAdded = is25519
85- ? BigInt ( 8 ) * N_2 ** BigInt ( 251 ) - N_1
86- : BigInt ( 4 ) * N_2 ** BigInt ( 445 ) - N_1 ;
83+ const minScalar = is25519 ? N_2 ** 254n : N_2 ** 447n ;
84+ const maxAdded = is25519 ? 8n * N_2 ** 251n - N_1 : 4n * N_2 ** 445n - N_1 ;
8785 const maxScalar = minScalar + maxAdded + N_1 ; // (inclusive)
8886 const modP = ( n : bigint ) => mod ( n , P ) ;
8987 const GuBytes = encodeU ( Gu ) ;
@@ -152,7 +150,7 @@ export function montgomery(curveDef: CurveType): MontgomeryECDH {
152150 let x_3 = u ;
153151 let z_3 = N_1 ;
154152 let swap = N_0 ;
155- for ( let t = BigInt ( montgomeryBits - 1 ) ; t >= N_0 ; t -- ) {
153+ for ( let t = montgomeryBits - 1n ; t >= N_0 ; t -- ) {
156154 const k_t = ( k >> t ) & N_1 ;
157155 swap ^= k_t ;
158156 ( { x_2, x_3 } = cswap ( swap , x_2 , x_3 ) ) ;
0 commit comments