commit
efcac86cac
@ -46,6 +46,12 @@ int fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
|
|||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if one of x,y is zero return an error! */
|
||||||
|
if ((mp_iszero(&x) == MP_YES) || (mp_iszero(&y) == MP_YES)) {
|
||||||
|
res = MP_VAL;
|
||||||
|
goto LBL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
/* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
|
/* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
|
||||||
if ((res = mp_copy(&x, &u)) != MP_OKAY) {
|
if ((res = mp_copy(&x, &u)) != MP_OKAY) {
|
||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
|
@ -18,14 +18,14 @@
|
|||||||
/* hac 14.61, pp608 */
|
/* hac 14.61, pp608 */
|
||||||
int mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
|
int mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
|
||||||
{
|
{
|
||||||
/* b cannot be negative */
|
/* b cannot be negative and has to be >1 */
|
||||||
if ((b->sign == MP_NEG) || (mp_iszero(b) == MP_YES)) {
|
if ((b->sign == MP_NEG) || (mp_cmp_d(b, 1) != MP_GT)) {
|
||||||
return MP_VAL;
|
return MP_VAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BN_FAST_MP_INVMOD_C
|
#ifdef BN_FAST_MP_INVMOD_C
|
||||||
/* if the modulus is odd we can use a faster routine instead */
|
/* if the modulus is odd we can use a faster routine instead */
|
||||||
if ((mp_isodd(b) == MP_YES) && (mp_cmp_d(b, 1) != MP_EQ)) {
|
if ((mp_isodd(b) == MP_YES)) {
|
||||||
return fast_mp_invmod(a, b, c);
|
return fast_mp_invmod(a, b, c);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -229,6 +229,15 @@ int main(void)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mp_set_int(&a, 42);
|
||||||
|
mp_set_int(&b, 1);
|
||||||
|
mp_neg(&b, &b);
|
||||||
|
mp_set_int(&c, 1);
|
||||||
|
mp_exptmod(&a, &b, &c, &d);
|
||||||
|
|
||||||
|
mp_set_int(&c, 7);
|
||||||
|
mp_exptmod(&a, &b, &c, &d);
|
||||||
|
|
||||||
|
|
||||||
mp_set_int(&a, 0);
|
mp_set_int(&a, 0);
|
||||||
mp_set_int(&b, 1);
|
mp_set_int(&b, 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user