@@ -63,6 +63,11 @@ static inline void p256_montjscalarmul_selector(uint64_t res[S2N_BIGNUM_STATIC 1
63
63
else { p256_montjscalarmul (res , scalar , point ); }
64
64
}
65
65
66
+ // Montgomery inverse modulo p_256 = 2^256 - 2^224 + 2^192 + 2^96 - 1
67
+ // z = x^-1 mod p_256.
68
+ // The function is constant-time.
69
+ extern void bignum_montinv_p256 (uint64_t z [S2N_BIGNUM_STATIC 4 ], const uint64_t x [S2N_BIGNUM_STATIC 4 ]);
70
+
66
71
// Add modulo p_384, z := (x + y) mod p_384, assuming x and y reduced
67
72
// Inputs x[6], y[6]; output z[6]
68
73
extern void bignum_add_p384 (uint64_t z [S2N_BIGNUM_STATIC 6 ], const uint64_t x [S2N_BIGNUM_STATIC 6 ], const uint64_t y [S2N_BIGNUM_STATIC 6 ]);
@@ -124,6 +129,11 @@ static inline void p384_montjscalarmul_selector(uint64_t res[S2N_BIGNUM_STATIC 1
124
129
else { p384_montjscalarmul (res , scalar , point ); }
125
130
}
126
131
132
+ // Montgomery inverse modulo p_384 = 2^384 - 2^128 - 2^96 + 2^32 - 1
133
+ // z = x^-1 mod p_384.
134
+ // The function is constant-time.
135
+ extern void bignum_montinv_p384 (uint64_t z [S2N_BIGNUM_STATIC 6 ], const uint64_t x [S2N_BIGNUM_STATIC 6 ]);
136
+
127
137
// Convert 6-digit (384-bit) bignum from little-endian form
128
138
// Input x[6]; output z[6]
129
139
extern void bignum_fromlebytes_6 (uint64_t z [S2N_BIGNUM_STATIC 6 ], const uint8_t x [S2N_BIGNUM_STATIC 48 ]);
@@ -185,6 +195,11 @@ static inline void p521_jscalarmul_selector(uint64_t res[S2N_BIGNUM_STATIC 27],
185
195
else { p521_jscalarmul (res , scalar , point ); }
186
196
}
187
197
198
+ // Modular inverse modulo p_521 = 2^521 - 1
199
+ // z = x^-1 mod p_521.
200
+ // The function is constant-time.
201
+ extern void bignum_inv_p521 (uint64_t z [S2N_BIGNUM_STATIC 9 ], const uint64_t x [S2N_BIGNUM_STATIC 9 ]);
202
+
188
203
// curve25519_x25519_byte and curve25519_x25519_byte_alt computes the x25519
189
204
// function specified in https://www.rfc-editor.org/rfc/rfc7748. |scalar| is the
190
205
// scalar, |point| is the u-coordinate of the elliptic curve
0 commit comments