Lines Matching refs:rsa

55 int ossl_rsa_fips186_4_gen_prob_primes(RSA *rsa, RSA_ACVP_TEST *test,  in ossl_rsa_fips186_4_gen_prob_primes()  argument
112 if (rsa->p == NULL) in ossl_rsa_fips186_4_gen_prob_primes()
113 rsa->p = BN_secure_new(); in ossl_rsa_fips186_4_gen_prob_primes()
114 if (rsa->q == NULL) in ossl_rsa_fips186_4_gen_prob_primes()
115 rsa->q = BN_secure_new(); in ossl_rsa_fips186_4_gen_prob_primes()
116 if (rsa->p == NULL || rsa->q == NULL) in ossl_rsa_fips186_4_gen_prob_primes()
118 BN_set_flags(rsa->p, BN_FLG_CONSTTIME); in ossl_rsa_fips186_4_gen_prob_primes()
119 BN_set_flags(rsa->q, BN_FLG_CONSTTIME); in ossl_rsa_fips186_4_gen_prob_primes()
122 if (!ossl_bn_rsa_fips186_4_gen_prob_primes(rsa->p, Xpo, p1, p2, Xp, Xp1, Xp2, in ossl_rsa_fips186_4_gen_prob_primes()
127 if (!ossl_bn_rsa_fips186_4_gen_prob_primes(rsa->q, Xqo, q1, q2, Xq, Xq1, in ossl_rsa_fips186_4_gen_prob_primes()
139 ok = ossl_rsa_check_pminusq_diff(tmp, rsa->p, rsa->q, nbits); in ossl_rsa_fips186_4_gen_prob_primes()
146 rsa->dirty_cnt++; in ossl_rsa_fips186_4_gen_prob_primes()
154 BN_clear_free(rsa->p); in ossl_rsa_fips186_4_gen_prob_primes()
155 rsa->p = NULL; in ossl_rsa_fips186_4_gen_prob_primes()
156 BN_clear_free(rsa->q); in ossl_rsa_fips186_4_gen_prob_primes()
157 rsa->q = NULL; in ossl_rsa_fips186_4_gen_prob_primes()
237 int ossl_rsa_sp800_56b_derive_params_from_pq(RSA *rsa, int nbits, in ossl_rsa_sp800_56b_derive_params_from_pq() argument
258 if (ossl_rsa_get_lcm(ctx, rsa->p, rsa->q, lcm, gcd, p1, q1, p1q1) != 1) in ossl_rsa_sp800_56b_derive_params_from_pq()
266 BN_free(rsa->e); in ossl_rsa_sp800_56b_derive_params_from_pq()
267 rsa->e = BN_dup(e); in ossl_rsa_sp800_56b_derive_params_from_pq()
268 if (rsa->e == NULL) in ossl_rsa_sp800_56b_derive_params_from_pq()
271 BN_clear_free(rsa->d); in ossl_rsa_sp800_56b_derive_params_from_pq()
273 rsa->d = BN_secure_new(); in ossl_rsa_sp800_56b_derive_params_from_pq()
274 if (rsa->d == NULL) in ossl_rsa_sp800_56b_derive_params_from_pq()
276 BN_set_flags(rsa->d, BN_FLG_CONSTTIME); in ossl_rsa_sp800_56b_derive_params_from_pq()
277 if (BN_mod_inverse(rsa->d, e, lcm, ctx) == NULL) in ossl_rsa_sp800_56b_derive_params_from_pq()
281 if (BN_num_bits(rsa->d) <= (nbits >> 1)) { in ossl_rsa_sp800_56b_derive_params_from_pq()
287 if (rsa->n == NULL) in ossl_rsa_sp800_56b_derive_params_from_pq()
288 rsa->n = BN_new(); in ossl_rsa_sp800_56b_derive_params_from_pq()
289 if (rsa->n == NULL || !BN_mul(rsa->n, rsa->p, rsa->q, ctx)) in ossl_rsa_sp800_56b_derive_params_from_pq()
294 if (rsa->dmp1 == NULL) in ossl_rsa_sp800_56b_derive_params_from_pq()
295 rsa->dmp1 = BN_secure_new(); in ossl_rsa_sp800_56b_derive_params_from_pq()
296 if (rsa->dmp1 == NULL) in ossl_rsa_sp800_56b_derive_params_from_pq()
298 BN_set_flags(rsa->dmp1, BN_FLG_CONSTTIME); in ossl_rsa_sp800_56b_derive_params_from_pq()
299 if (!BN_mod(rsa->dmp1, rsa->d, p1, ctx)) in ossl_rsa_sp800_56b_derive_params_from_pq()
303 if (rsa->dmq1 == NULL) in ossl_rsa_sp800_56b_derive_params_from_pq()
304 rsa->dmq1 = BN_secure_new(); in ossl_rsa_sp800_56b_derive_params_from_pq()
305 if (rsa->dmq1 == NULL) in ossl_rsa_sp800_56b_derive_params_from_pq()
307 BN_set_flags(rsa->dmq1, BN_FLG_CONSTTIME); in ossl_rsa_sp800_56b_derive_params_from_pq()
308 if (!BN_mod(rsa->dmq1, rsa->d, q1, ctx)) in ossl_rsa_sp800_56b_derive_params_from_pq()
312 BN_free(rsa->iqmp); in ossl_rsa_sp800_56b_derive_params_from_pq()
313 rsa->iqmp = BN_secure_new(); in ossl_rsa_sp800_56b_derive_params_from_pq()
314 if (rsa->iqmp == NULL) in ossl_rsa_sp800_56b_derive_params_from_pq()
316 BN_set_flags(rsa->iqmp, BN_FLG_CONSTTIME); in ossl_rsa_sp800_56b_derive_params_from_pq()
317 if (BN_mod_inverse(rsa->iqmp, rsa->q, rsa->p, ctx) == NULL) in ossl_rsa_sp800_56b_derive_params_from_pq()
320 rsa->dirty_cnt++; in ossl_rsa_sp800_56b_derive_params_from_pq()
324 BN_free(rsa->e); in ossl_rsa_sp800_56b_derive_params_from_pq()
325 rsa->e = NULL; in ossl_rsa_sp800_56b_derive_params_from_pq()
326 BN_free(rsa->d); in ossl_rsa_sp800_56b_derive_params_from_pq()
327 rsa->d = NULL; in ossl_rsa_sp800_56b_derive_params_from_pq()
328 BN_free(rsa->n); in ossl_rsa_sp800_56b_derive_params_from_pq()
329 rsa->n = NULL; in ossl_rsa_sp800_56b_derive_params_from_pq()
330 BN_free(rsa->iqmp); in ossl_rsa_sp800_56b_derive_params_from_pq()
331 rsa->iqmp = NULL; in ossl_rsa_sp800_56b_derive_params_from_pq()
332 BN_free(rsa->dmq1); in ossl_rsa_sp800_56b_derive_params_from_pq()
333 rsa->dmq1 = NULL; in ossl_rsa_sp800_56b_derive_params_from_pq()
334 BN_free(rsa->dmp1); in ossl_rsa_sp800_56b_derive_params_from_pq()
335 rsa->dmp1 = NULL; in ossl_rsa_sp800_56b_derive_params_from_pq()
365 int ossl_rsa_sp800_56b_generate_key(RSA *rsa, int nbits, const BIGNUM *efixed, in ossl_rsa_sp800_56b_generate_key() argument
376 info = rsa->acvp_test; in ossl_rsa_sp800_56b_generate_key()
384 if (!rsa_validate_rng_strength(RAND_get0_private(rsa->libctx), nbits)) in ossl_rsa_sp800_56b_generate_key()
387 ctx = BN_CTX_new_ex(rsa->libctx); in ossl_rsa_sp800_56b_generate_key()
403 if (!ossl_rsa_fips186_4_gen_prob_primes(rsa, info, nbits, e, ctx, cb)) in ossl_rsa_sp800_56b_generate_key()
407 if (info == NULL && BN_cmp(rsa->p, rsa->q) < 0) { in ossl_rsa_sp800_56b_generate_key()
408 tmp = rsa->p; in ossl_rsa_sp800_56b_generate_key()
409 rsa->p = rsa->q; in ossl_rsa_sp800_56b_generate_key()
410 rsa->q = tmp; in ossl_rsa_sp800_56b_generate_key()
414 ok = ossl_rsa_sp800_56b_derive_params_from_pq(rsa, nbits, e, ctx); in ossl_rsa_sp800_56b_generate_key()
423 ret = ossl_rsa_sp800_56b_pairwise_test(rsa, ctx); in ossl_rsa_sp800_56b_generate_key()
437 int ossl_rsa_sp800_56b_pairwise_test(RSA *rsa, BN_CTX *ctx) in ossl_rsa_sp800_56b_pairwise_test() argument
450 && BN_mod_exp(tmp, k, rsa->e, rsa->n, ctx) in ossl_rsa_sp800_56b_pairwise_test()
451 && BN_mod_exp(tmp, tmp, rsa->d, rsa->n, ctx) in ossl_rsa_sp800_56b_pairwise_test()