Lines Matching refs:rsa

30 static int rsa_keygen_pairwise_test(RSA *rsa, OSSL_CALLBACK *cb, void *cbarg);
31 static int rsa_keygen(OSSL_LIB_CTX *libctx, RSA *rsa, int bits, int primes,
41 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb) in RSA_generate_key_ex() argument
43 if (rsa->meth->rsa_keygen != NULL) in RSA_generate_key_ex()
44 return rsa->meth->rsa_keygen(rsa, bits, e_value, cb); in RSA_generate_key_ex()
46 return RSA_generate_multi_prime_key(rsa, bits, RSA_DEFAULT_PRIME_NUM, in RSA_generate_key_ex()
50 int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, in RSA_generate_multi_prime_key() argument
55 if (rsa->meth->rsa_multi_prime_keygen != NULL) { in RSA_generate_multi_prime_key()
56 return rsa->meth->rsa_multi_prime_keygen(rsa, bits, primes, in RSA_generate_multi_prime_key()
58 } else if (rsa->meth->rsa_keygen != NULL) { in RSA_generate_multi_prime_key()
66 return rsa->meth->rsa_keygen(rsa, bits, e_value, cb); in RSA_generate_multi_prime_key()
71 return rsa_keygen(rsa->libctx, rsa, bits, primes, e_value, cb, 0); in RSA_generate_multi_prime_key()
82 int ossl_rsa_multiprime_derive(RSA *rsa, int bits, int primes, in DEFINE_STACK_OF()
99 ctx = BN_CTX_new_ex(rsa->libctx); in DEFINE_STACK_OF()
124 if (BN_copy(r1, rsa->n) == NULL) in DEFINE_STACK_OF()
138 if (BN_mod_inverse(r1, r2, rsa->e, ctx) == NULL) in DEFINE_STACK_OF()
195 if (!BN_mod(dmp1, rsa->d, r1, ctx)) in DEFINE_STACK_OF()
201 if (!BN_mod(dmq1, rsa->d, r2, ctx)) in DEFINE_STACK_OF()
212 if (!BN_mod(newexp, rsa->d, newpd, ctx)) { in DEFINE_STACK_OF()
258 static int rsa_multiprime_keygen(RSA *rsa, int bits, int primes, in rsa_multiprime_keygen() argument
305 ctx = BN_CTX_new_ex(rsa->libctx); in rsa_multiprime_keygen()
322 rsa->dirty_cnt++; in rsa_multiprime_keygen()
325 if (!rsa->n && ((rsa->n = BN_new()) == NULL)) in rsa_multiprime_keygen()
327 if (!rsa->d && ((rsa->d = BN_secure_new()) == NULL)) in rsa_multiprime_keygen()
329 BN_set_flags(rsa->d, BN_FLG_CONSTTIME); in rsa_multiprime_keygen()
330 if (!rsa->e && ((rsa->e = BN_new()) == NULL)) in rsa_multiprime_keygen()
332 if (!rsa->p && ((rsa->p = BN_secure_new()) == NULL)) in rsa_multiprime_keygen()
334 BN_set_flags(rsa->p, BN_FLG_CONSTTIME); in rsa_multiprime_keygen()
335 if (!rsa->q && ((rsa->q = BN_secure_new()) == NULL)) in rsa_multiprime_keygen()
337 BN_set_flags(rsa->q, BN_FLG_CONSTTIME); in rsa_multiprime_keygen()
341 rsa->version = RSA_ASN1_VERSION_MULTI; in rsa_multiprime_keygen()
345 if (rsa->prime_infos != NULL) { in rsa_multiprime_keygen()
347 sk_RSA_PRIME_INFO_pop_free(rsa->prime_infos, in rsa_multiprime_keygen()
350 rsa->prime_infos = prime_infos; in rsa_multiprime_keygen()
361 if (BN_copy(rsa->e, e_value) == NULL) in rsa_multiprime_keygen()
370 prime = rsa->p; in rsa_multiprime_keygen()
372 prime = rsa->q; in rsa_multiprime_keygen()
395 prev_prime = rsa->p; in rsa_multiprime_keygen()
397 prev_prime = rsa->q; in rsa_multiprime_keygen()
411 if (BN_mod_inverse(r1, r2, rsa->e, ctx) != NULL) { in rsa_multiprime_keygen()
432 if (!BN_mul(r1, rsa->p, rsa->q, ctx)) in rsa_multiprime_keygen()
436 if (!BN_mul(r1, rsa->n, prime, ctx)) in rsa_multiprime_keygen()
506 if (i > 1 && BN_copy(pinfo->pp, rsa->n) == NULL) in rsa_multiprime_keygen()
508 if (BN_copy(rsa->n, r1) == NULL) in rsa_multiprime_keygen()
519 if (BN_cmp(rsa->p, rsa->q) < 0) { in rsa_multiprime_keygen()
520 tmp = rsa->p; in rsa_multiprime_keygen()
521 rsa->p = rsa->q; in rsa_multiprime_keygen()
522 rsa->q = tmp; in rsa_multiprime_keygen()
531 if (!BN_sub(r1, rsa->p, BN_value_one())) in rsa_multiprime_keygen()
534 if (!BN_sub(r2, rsa->q, BN_value_one())) in rsa_multiprime_keygen()
551 if (BN_mod_inverse(rsa->d, rsa->e, r0, ctx) == NULL) { in rsa_multiprime_keygen()
556 if (!ossl_rsa_multiprime_derive(rsa, bits, primes, e_value, in rsa_multiprime_keygen()
570 rsa->dmp1 = sk_BIGNUM_delete(exps, 0); in rsa_multiprime_keygen()
571 rsa->dmq1 = sk_BIGNUM_delete(exps, 0); in rsa_multiprime_keygen()
572 rsa->iqmp = sk_BIGNUM_delete(coeffs, 0); in rsa_multiprime_keygen()
604 static int rsa_keygen(OSSL_LIB_CTX *libctx, RSA *rsa, int bits, int primes, in rsa_keygen() argument
610 ok = ossl_rsa_sp800_56b_generate_key(rsa, bits, e_value, cb); in rsa_keygen()
620 ok = ossl_rsa_sp800_56b_generate_key(rsa, bits, e_value, cb); in rsa_keygen()
622 ok = rsa_multiprime_keygen(rsa, bits, primes, e_value, cb); in rsa_keygen()
630 ok = rsa_keygen_pairwise_test(rsa, stcb, stcbarg); in rsa_keygen()
634 BN_clear_free(rsa->d); in rsa_keygen()
635 BN_clear_free(rsa->p); in rsa_keygen()
636 BN_clear_free(rsa->q); in rsa_keygen()
637 BN_clear_free(rsa->dmp1); in rsa_keygen()
638 BN_clear_free(rsa->dmq1); in rsa_keygen()
639 BN_clear_free(rsa->iqmp); in rsa_keygen()
640 rsa->d = NULL; in rsa_keygen()
641 rsa->p = NULL; in rsa_keygen()
642 rsa->q = NULL; in rsa_keygen()
643 rsa->dmp1 = NULL; in rsa_keygen()
644 rsa->dmq1 = NULL; in rsa_keygen()
645 rsa->iqmp = NULL; in rsa_keygen()
677 static int rsa_keygen_pairwise_test(RSA *rsa, OSSL_CALLBACK *cb, void *cbarg) in rsa_keygen_pairwise_test() argument
701 plaintxt_len = RSA_size(rsa); in rsa_keygen_pairwise_test()
711 ciphertxt_len = RSA_public_encrypt(plaintxt_len, plaintxt, ciphertxt, rsa, in rsa_keygen_pairwise_test()
718 decoded_len = RSA_private_decrypt(ciphertxt_len, ciphertxt, decoded, rsa, in rsa_keygen_pairwise_test()