@@ -640,7 +640,8 @@ int fp_invmod_mont_ct(fp_int *a, fp_int *b, fp_int *c, fp_digit mp);
640640/* c = [a, b] */
641641/*int fp_lcm(fp_int *a, fp_int *b, fp_int *c);*/
642642
643- /* setups the montgomery reduction */
643+ /* setups the montgomery reduction
644+ * The modulus must be odd: returns FP_VAL if it is even. */
644645int fp_montgomery_setup (fp_int * a , fp_digit * rho );
645646
646647/* computes a = B**n mod b without division or multiplication useful for
@@ -652,7 +653,10 @@ int fp_montgomery_calc_normalization(fp_int *a, fp_int *b);
652653int fp_montgomery_reduce (fp_int * a , fp_int * m , fp_digit mp );
653654int fp_montgomery_reduce_ex (fp_int * a , fp_int * m , fp_digit mp , int ct );
654655
655- /* d = a**b (mod c) */
656+ /* Y = G**X (mod P)
657+ * Only odd moduli are supported (Montgomery reduction is used). An even P
658+ * results in FP_VAL being returned, except for the trivial cases P == 1,
659+ * X == 0 and G == 0, which return the mathematically correct result. */
656660int fp_exptmod (fp_int * G , fp_int * X , fp_int * P , fp_int * Y );
657661int fp_exptmod_ex (fp_int * G , fp_int * X , int minDigits , fp_int * P , fp_int * Y );
658662int fp_exptmod_nct (fp_int * G , fp_int * X , fp_int * P , fp_int * Y );
@@ -702,6 +706,7 @@ enum {
702706
703707/* non-blocking version of timing resistant fp_exptmod function */
704708/* supports cache resistance */
709+ /* P must be odd: returns FP_VAL if it is even. */
705710int fp_exptmod_nb (exptModNb_t * nb , fp_int * G , fp_int * X , fp_int * P , fp_int * Y );
706711
707712#endif /* WC_RSA_NONBLOCK */
@@ -843,6 +848,8 @@ MP_API int mp_addmod_ct (mp_int* a, mp_int* b, mp_int* c, mp_int* d);
843848MP_API int mp_mod (mp_int * a , mp_int * b , mp_int * c );
844849MP_API int mp_invmod (mp_int * a , mp_int * b , mp_int * c );
845850MP_API int mp_invmod_mont_ct (mp_int * a , mp_int * b , mp_int * c , fp_digit mp );
851+ /* mp_exptmod*: modulus p must be odd; an even p returns MP_VAL (see
852+ * fp_exptmod). */
846853MP_API int mp_exptmod (mp_int * g , mp_int * x , mp_int * p , mp_int * y );
847854MP_API int mp_exptmod_ex (mp_int * g , mp_int * x , int minDigits , mp_int * p ,
848855 mp_int * y );
0 commit comments