• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500-V1.0.1.40_1.0.68/ap/gpl/openssl/fips/rsa/

Lines Matching refs:rsa

1 /* crypto/rsa/rsa_eay.c */
62 #include <openssl/rsa.h>
69 unsigned char *to, RSA *rsa,int padding);
71 unsigned char *to, RSA *rsa,int padding);
73 unsigned char *to, RSA *rsa,int padding);
75 unsigned char *to, RSA *rsa,int padding);
76 static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa);
77 static int RSA_eay_init(RSA *rsa);
78 static int RSA_eay_finish(RSA *rsa);
101 unsigned char *to, RSA *rsa, int padding)
118 num=BN_num_bytes(rsa->n);
149 if (BN_ucmp(&f, rsa->n) >= 0)
156 if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))
161 if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx))
166 if (rsa->_method_mod_n == NULL) /* other thread may have finished first */
169 if (rsa->_method_mod_n == NULL)
171 rsa->_method_mod_n = bn_mont_ctx;
180 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
181 rsa->_method_mod_n)) goto err;
203 static int rsa_eay_blinding(RSA *rsa, BN_CTX *ctx)
208 if(rsa->blinding == NULL)
209 ret = RSA_blinding_on(rsa, ctx);
214 #define BLINDING_HELPER(rsa, ctx, err_instr) \
216 if((!((rsa)->flags & RSA_FLAG_NO_BLINDING)) && \
217 ((rsa)->blinding == NULL) && \
218 !rsa_eay_blinding(rsa, ctx)) \
222 static BN_BLINDING *setup_blinding(RSA *rsa, BN_CTX *ctx)
235 if ((RAND_status() == 0) && rsa->d != NULL && rsa->d->d != NULL)
238 RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0);
239 if (!BN_pseudo_rand_range(A,rsa->n)) goto err;
243 if (!BN_rand_range(A,rsa->n)) goto err;
245 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
247 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
249 ret = BN_BLINDING_new(A,Ai,rsa->n);
258 unsigned char *to, RSA *rsa, int padding)
271 num=BN_num_bytes(rsa->n);
295 if (BN_ucmp(&f, rsa->n) >= 0)
302 BLINDING_HELPER(rsa, ctx, goto err;);
303 blinding = rsa->blinding;
311 if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
326 blinding = setup_blinding(rsa, ctx);
336 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
337 ((rsa->p != NULL) &&
338 (rsa->q != NULL) &&
339 (rsa->dmp1 != NULL) &&
340 (rsa->dmq1 != NULL) &&
341 (rsa->iqmp != NULL)) )
342 { if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; }
345 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) goto err;
374 unsigned char *to, RSA *rsa, int padding)
389 num=BN_num_bytes(rsa->n);
408 if (BN_ucmp(&f, rsa->n) >= 0)
414 BLINDING_HELPER(rsa, ctx, goto err;);
415 blinding = rsa->blinding;
423 if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
438 blinding = setup_blinding(rsa, ctx);
449 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
450 ((rsa->p != NULL) &&
451 (rsa->q != NULL) &&
452 (rsa->dmp1 != NULL) &&
453 (rsa->dmq1 != NULL) &&
454 (rsa->iqmp != NULL)) )
455 { if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; }
458 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL))
507 unsigned char *to, RSA *rsa, int padding)
520 num=BN_num_bytes(rsa->n);
538 if (BN_ucmp(&f, rsa->n) >= 0)
545 if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))
550 if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx))
555 if (rsa->_method_mod_n == NULL) /* other thread may have finished first */
558 if (rsa->_method_mod_n == NULL)
560 rsa->_method_mod_n = bn_mont_ctx;
569 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
570 rsa->_method_mod_n)) goto err;
602 static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
613 if (rsa->flags & RSA_FLAG_CACHE_PRIVATE)
615 if (rsa->_method_mod_p == NULL)
620 if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->p,ctx))
625 if (rsa->_method_mod_p == NULL) /* other thread may have finished first */
628 if (rsa->_method_mod_p == NULL)
630 rsa->_method_mod_p = bn_mont_ctx;
639 if (rsa->_method_mod_q == NULL)
644 if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->q,ctx))
649 if (rsa->_method_mod_q == NULL) /* other thread may have finished first */
652 if (rsa->_method_mod_q == NULL)
654 rsa->_method_mod_q = bn_mont_ctx;
664 if (!BN_mod(&r1,I,rsa->q,ctx)) goto err;
665 if (!rsa->meth->bn_mod_exp(&m1,&r1,rsa->dmq1,rsa->q,ctx,
666 rsa->_method_mod_q)) goto err;
668 if (!BN_mod(&r1,I,rsa->p,ctx)) goto err;
669 if (!rsa->meth->bn_mod_exp(r0,&r1,rsa->dmp1,rsa->p,ctx,
670 rsa->_method_mod_p)) goto err;
676 if (!BN_add(r0,r0,rsa->p)) goto err;
678 if (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err;
679 if (!BN_mod(r0,&r1,rsa->p,ctx)) goto err;
688 if (!BN_add(r0,r0,rsa->p)) goto err;
689 if (!BN_mul(&r1,r0,rsa->q,ctx)) goto err;
692 if (rsa->e && rsa->n)
694 if (!rsa->meth->bn_mod_exp(&vrfy,r0,rsa->e,rsa->n,ctx,NULL)) goto err;
695 /* If 'I' was greater than (or equal to) rsa->n, the operation
700 if (!BN_mod(&vrfy, &vrfy, rsa->n, ctx)) goto err;
702 if (!BN_add(&vrfy, &vrfy, rsa->n)) goto err;
707 if (!rsa->meth->bn_mod_exp(r0,I,rsa->d,rsa->n,ctx,NULL)) goto err;
718 static int RSA_eay_init(RSA *rsa)
720 rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE;
724 static int RSA_eay_finish(RSA *rsa)
726 if (rsa->_method_mod_n != NULL)
727 BN_MONT_CTX_free(rsa->_method_mod_n);
728 if (rsa->_method_mod_p != NULL)
729 BN_MONT_CTX_free(rsa->_method_mod_p);
730 if (rsa->_method_mod_q != NULL)
731 BN_MONT_CTX_free(rsa->_method_mod_q);