Lines Matching refs:rsa
74 static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb);
81 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb) in RSA_generate_key_ex() argument
84 if (FIPS_mode() && !(rsa->meth->flags & RSA_FLAG_FIPS_METHOD) in RSA_generate_key_ex()
85 && !(rsa->flags & RSA_FLAG_NON_FIPS_ALLOW)) in RSA_generate_key_ex()
91 if(rsa->meth->rsa_keygen) in RSA_generate_key_ex()
92 return rsa->meth->rsa_keygen(rsa, bits, e_value, cb); in RSA_generate_key_ex()
95 return FIPS_rsa_generate_key_ex(rsa, bits, e_value, cb); in RSA_generate_key_ex()
97 return rsa_builtin_keygen(rsa, bits, e_value, cb); in RSA_generate_key_ex()
100 static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb) in rsa_builtin_keygen() argument
121 if(!rsa->n && ((rsa->n=BN_new()) == NULL)) goto err; in rsa_builtin_keygen()
122 if(!rsa->d && ((rsa->d=BN_new()) == NULL)) goto err; in rsa_builtin_keygen()
123 if(!rsa->e && ((rsa->e=BN_new()) == NULL)) goto err; in rsa_builtin_keygen()
124 if(!rsa->p && ((rsa->p=BN_new()) == NULL)) goto err; in rsa_builtin_keygen()
125 if(!rsa->q && ((rsa->q=BN_new()) == NULL)) goto err; in rsa_builtin_keygen()
126 if(!rsa->dmp1 && ((rsa->dmp1=BN_new()) == NULL)) goto err; in rsa_builtin_keygen()
127 if(!rsa->dmq1 && ((rsa->dmq1=BN_new()) == NULL)) goto err; in rsa_builtin_keygen()
128 if(!rsa->iqmp && ((rsa->iqmp=BN_new()) == NULL)) goto err; in rsa_builtin_keygen()
130 BN_copy(rsa->e, e_value); in rsa_builtin_keygen()
135 if(!BN_generate_prime_ex(rsa->p, bitsp, 0, NULL, NULL, cb)) in rsa_builtin_keygen()
137 if (!BN_sub(r2,rsa->p,BN_value_one())) goto err; in rsa_builtin_keygen()
138 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err; in rsa_builtin_keygen()
153 if(!BN_generate_prime_ex(rsa->q, bitsq, 0, NULL, NULL, cb)) in rsa_builtin_keygen()
155 } while((BN_cmp(rsa->p, rsa->q) == 0) && (++degenerate < 3)); in rsa_builtin_keygen()
162 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err; in rsa_builtin_keygen()
163 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err; in rsa_builtin_keygen()
171 if (BN_cmp(rsa->p,rsa->q) < 0) in rsa_builtin_keygen()
173 tmp=rsa->p; in rsa_builtin_keygen()
174 rsa->p=rsa->q; in rsa_builtin_keygen()
175 rsa->q=tmp; in rsa_builtin_keygen()
179 if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) goto err; in rsa_builtin_keygen()
182 if (!BN_sub(r1,rsa->p,BN_value_one())) goto err; /* p-1 */ in rsa_builtin_keygen()
183 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err; /* q-1 */ in rsa_builtin_keygen()
185 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) in rsa_builtin_keygen()
192 if (!BN_mod_inverse(rsa->d,rsa->e,pr0,ctx)) goto err; /* d */ in rsa_builtin_keygen()
195 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) in rsa_builtin_keygen()
198 BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME); in rsa_builtin_keygen()
201 d = rsa->d; in rsa_builtin_keygen()
204 if (!BN_mod(rsa->dmp1,d,r1,ctx)) goto err; in rsa_builtin_keygen()
207 if (!BN_mod(rsa->dmq1,d,r2,ctx)) goto err; in rsa_builtin_keygen()
210 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) in rsa_builtin_keygen()
213 BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME); in rsa_builtin_keygen()
216 p = rsa->p; in rsa_builtin_keygen()
217 if (!BN_mod_inverse(rsa->iqmp,rsa->q,p,ctx)) goto err; in rsa_builtin_keygen()