7979extern "C" {
8080#endif
8181
82+ /* Word size (4 bytes considering 32-bits architectures) */
83+ #define WORD_SIZE 4
8284/* Number of words of 32 bits to represent an element of the the curve p-256: */
8385#define NUM_ECC_DIGITS 8
8486/* 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)
8688
8789/* struct to represent a point of the curve (uses X and Y coordinates): */
8890typedef struct EccPoint {
@@ -218,6 +220,8 @@ void vli_modSquare_fast(uint32_t *p_result, uint32_t *p_left);
218220 * @param p_right IN -- buffer p_right in (p_left * p_right) % p_mod.
219221 * @param p_mod IN -- module.
220222 * @param p_barrett IN -- used for Barrett reduction.
223+ * @note Side-channel countermeasure: algorithm strengthened against timing
224+ * attack.
221225 */
222226void vli_modMult (uint32_t * p_result , uint32_t * p_left , uint32_t * p_right ,
223227 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,
229233 * @param p_input IN -- buffer p_input in (1/p_intput) % p_mod.
230234 * @param p_mod IN -- module.
231235 * @param p_barrett IN -- used for Barrett reduction.
236+ * @note Side-channel countermeasure: algorithm strengthened against timing
237+ * attack.
232238 */
233239void vli_modInv (uint32_t * p_result , uint32_t * p_input ,
234240 uint32_t * p_mod , uint32_t * p_barrett );
235241
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+
236257/*
237258 * @brief Check if a point is zero.
238259 * @return Returns 1 if p_point is the point at infinity, 0 otherwise.
@@ -271,10 +292,26 @@ void EccPoint_add(EccPointJacobi *P1, EccPointJacobi *P2);
271292 * @param p_result OUT -- Product of p_point by p_scalar.
272293 * @param p_point IN -- Elliptic curve point
273294 * @param p_scalar IN -- Scalar integer
295+ * @note Side-channel countermeasure: algorithm strengthened against timing
296+ * attack.
274297 */
275- void EccPoint_mult (EccPointJacobi * p_result , EccPoint * p_point ,
298+ void EccPoint_mult_safe (EccPointJacobi * p_result , EccPoint * p_point ,
276299 uint32_t * p_scalar );
277300
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+
278315/*
279316 * @brief Convert an integer in standard octet representation to native format.
280317 * @return returns TC_CRYPTO_SUCCESS (1)
0 commit comments