79
79
extern "C" {
80
80
#endif
81
81
82
+ /* Word size (4 bytes considering 32-bits architectures) */
83
+ #define WORD_SIZE 4
82
84
/* Number of words of 32 bits to represent an element of the the curve p-256: */
83
85
#define NUM_ECC_DIGITS 8
84
86
/* Number of bytes to represent an element of the the curve p-256: */
85
- #define NUM_ECC_BYTES (4 *NUM_ECC_DIGITS)
87
+ #define NUM_ECC_BYTES (WORD_SIZE *NUM_ECC_DIGITS)
86
88
87
89
/* struct to represent a point of the curve (uses X and Y coordinates): */
88
90
typedef struct EccPoint {
@@ -218,6 +220,8 @@ void vli_modSquare_fast(uint32_t *p_result, uint32_t *p_left);
218
220
* @param p_right IN -- buffer p_right in (p_left * p_right) % p_mod.
219
221
* @param p_mod IN -- module.
220
222
* @param p_barrett IN -- used for Barrett reduction.
223
+ * @note Side-channel countermeasure: algorithm strengthened against timing
224
+ * attack.
221
225
*/
222
226
void vli_modMult (uint32_t * p_result , uint32_t * p_left , uint32_t * p_right ,
223
227
uint32_t * p_mod , uint32_t * p_barrett );
@@ -229,10 +233,27 @@ void vli_modMult(uint32_t *p_result, uint32_t *p_left, uint32_t *p_right,
229
233
* @param p_input IN -- buffer p_input in (1/p_intput) % p_mod.
230
234
* @param p_mod IN -- module.
231
235
* @param p_barrett IN -- used for Barrett reduction.
236
+ * @note Side-channel countermeasure: algorithm strengthened against timing
237
+ * attack.
232
238
*/
233
239
void vli_modInv (uint32_t * p_result , uint32_t * p_input ,
234
240
uint32_t * p_mod , uint32_t * p_barrett );
235
241
242
+ /*
243
+ * @brief modular reduction based on Barrett's method
244
+ * @param p_result OUT -- p_product % p_mod.
245
+ * @param p_product IN -- buffer p_product in (p_product % p_mod).
246
+ * @param p_mod IN -- buffer p_mod in (p_product % p_mod).
247
+ * @param p_barrett -- used for Barrett reduction.
248
+ * @note Side-channel countermeasure: algorithm strengthened against timing
249
+ * attack.
250
+ */
251
+ void vli_mmod_barrett (
252
+ uint32_t * p_result ,
253
+ uint32_t * p_product ,
254
+ uint32_t * p_mod ,
255
+ uint32_t * p_barrett );
256
+
236
257
/*
237
258
* @brief Check if a point is zero.
238
259
* @return Returns 1 if p_point is the point at infinity, 0 otherwise.
@@ -271,10 +292,26 @@ void EccPoint_add(EccPointJacobi *P1, EccPointJacobi *P2);
271
292
* @param p_result OUT -- Product of p_point by p_scalar.
272
293
* @param p_point IN -- Elliptic curve point
273
294
* @param p_scalar IN -- Scalar integer
295
+ * @note Side-channel countermeasure: algorithm strengthened against timing
296
+ * attack.
274
297
*/
275
- void EccPoint_mult (EccPointJacobi * p_result , EccPoint * p_point ,
298
+ void EccPoint_mult_safe (EccPointJacobi * p_result , EccPoint * p_point ,
276
299
uint32_t * p_scalar );
277
300
301
+ /*
302
+ * @brief Fast elliptic curve scalar multiplication with result in Jacobi
303
+ * coordinates
304
+ * @note non constant time
305
+ * @param p_result OUT -- Product of p_point by p_scalar.
306
+ * @param p_point IN -- Elliptic curve point
307
+ * @param p_scalar IN -- Scalar integer
308
+ * @note algorithm NOT strengthened against timing attack.
309
+ */
310
+ void EccPoint_mult_unsafe (
311
+ EccPointJacobi * p_result ,
312
+ EccPoint * p_point ,
313
+ uint32_t * p_scalar );
314
+
278
315
/*
279
316
* @brief Convert an integer in standard octet representation to native format.
280
317
* @return returns TC_CRYPTO_SUCCESS (1)
0 commit comments