X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fbn%2Fbn_mont2.c;h=bd4c01f6cbaf39ec0264b912a4aee0ec14d41f04;hp=871282400c65e89995b1a404fb2b50c2c3e945be;hb=5acaa49504153ecdd9734ac80aeb9153fde94e48;hpb=535b9b5724e08f27c722982bbf775a862134a22d diff --git a/crypto/bn/bn_mont2.c b/crypto/bn/bn_mont2.c index 871282400c..bd4c01f6cb 100644 --- a/crypto/bn/bn_mont2.c +++ b/crypto/bn/bn_mont2.c @@ -277,98 +277,3 @@ err: ctx->tos -= 2; return 0; } - -int BN_mont_mod_add(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_MONTGOMERY *mont) -{ - assert(r != NULL && x != NULL && y != NULL && mont != NULL); - assert(mont->p != NULL); - assert(BN_cmp(x, mont->p) < 0); - assert(BN_cmp(y, mont->p) < 0); - assert(!x->neg); - assert(!y->neg); - - if (!BN_add(r, x, y)) return 0; - if (BN_cmp(r, mont->p) >= 0) - { - if (!BN_sub(r, r, mont->p)) return 0; - } - - return 1; -} - - -int BN_mont_mod_sub(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_MONTGOMERY *mont) -{ - assert(r != NULL && x != NULL && y != NULL && mont != NULL); - assert(mont->p != NULL); - assert(BN_cmp(x, mont->p) < 0); - assert(BN_cmp(y, mont->p) < 0); - assert(!x->neg); - assert(!y->neg); - - if (!BN_sub(r, x, y)) return 0; - if (r->neg) - { - if (!BN_add(r, r, mont->p)) return 0; - } - - return 1; -} - -int BN_mont_mod_lshift1(BIGNUM *r, BIGNUM *x, BN_MONTGOMERY *mont) -{ - assert(r != NULL && x != NULL && mont != NULL); - assert(mont->p != NULL); - assert(BN_cmp(x, mont->p) < 0); - assert(!x->neg); - - if (!BN_lshift1(r, x)) return 0; - - if (BN_cmp(r, mont->p) >= 0) - { - if (!BN_sub(r, r, mont->p)) return 0; - } - - return 1; -} - -int BN_mont_mod_lshift(BIGNUM *r, BIGNUM *x, int n, BN_MONTGOMERY *mont) -{ - int sh_nb; - - assert(r != NULL && x != NULL && mont != NULL); - assert(mont->p != NULL); - assert(BN_cmp(x, mont->p) < 0); - assert(!x->neg); - assert(n > 0); - - if (r != x) - { - if (BN_copy(r, x) == NULL) return 0; - } - - while (n) - { - sh_nb = BN_num_bits(mont->p) - BN_num_bits(r); - if (sh_nb > n) sh_nb = n; - - if (sh_nb) - { - if(!BN_lshift(r, r, sh_nb)) return 0; - } - else - { - sh_nb = 1; - if (!BN_lshift1(r, r)) return 0; - } - - if (BN_cmp(r, mont->p) >= 0) - { - if (!BN_sub(r, r, mont->p)) return 0; - } - - n -= sh_nb; - } - - return 1; -}