Home | History | Annotate | Line # | Download | only in man3
      1 =pod
      2 
      3 =head1 NAME
      4 
      5 EVP_RSA_gen,
      6 RSA_generate_key_ex, RSA_generate_key,
      7 RSA_generate_multi_prime_key - generate RSA key pair
      8 
      9 =head1 SYNOPSIS
     10 
     11  #include <openssl/rsa.h>
     12 
     13  EVP_PKEY *EVP_RSA_gen(unsigned int bits);
     14 
     15 The following functions have been deprecated since OpenSSL 3.0, and can be
     16 hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
     17 see L<openssl_user_macros(7)>:
     18 
     19  int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
     20  int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb);
     21 
     22 The following function has been deprecated since OpenSSL 0.9.8, and can be
     23 hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
     24 see L<openssl_user_macros(7)>:
     25 
     26  RSA *RSA_generate_key(int bits, unsigned long e,
     27                        void (*callback)(int, int, void *), void *cb_arg);
     28 
     29 =head1 DESCRIPTION
     30 
     31 EVP_RSA_gen() generates a new RSA key pair with modulus size I<bits>.
     32 
     33 All of the functions described below are deprecated.
     34 Applications should instead use EVP_RSA_gen(), L<EVP_PKEY_Q_keygen(3)>, or
     35 L<EVP_PKEY_keygen_init(3)> and L<EVP_PKEY_keygen(3)>.
     36 
     37 RSA_generate_key_ex() generates a 2-prime RSA key pair and stores it in the
     38 B<RSA> structure provided in I<rsa>.
     39 
     40 RSA_generate_multi_prime_key() generates a multi-prime RSA key pair and stores
     41 it in the B<RSA> structure provided in I<rsa>. The number of primes is given by
     42 the I<primes> parameter.
     43 If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
     44 external circumstances (see L<RAND(7)>), the operation will fail.
     45 
     46 The modulus size will be of length I<bits>, the number of primes to form the
     47 modulus will be I<primes>, and the public exponent will be I<e>. Key sizes
     48 with I<num> E<lt> 1024 should be considered insecure. The exponent is an odd
     49 number, typically 3, 17 or 65537.
     50 
     51 In order to maintain adequate security level, the maximum number of permitted
     52 I<primes> depends on modulus bit length:
     53 
     54    <1024 | >=1024 | >=4096 | >=8192
     55    ------+--------+--------+-------
     56      2   |   3    |   4    |   5
     57 
     58 A callback function may be used to provide feedback about the
     59 progress of the key generation. If I<cb> is not NULL, it
     60 will be called as follows using the BN_GENCB_call() function
     61 described on the L<BN_generate_prime(3)> page.
     62 
     63 RSA_generate_key() is similar to RSA_generate_key_ex() but
     64 expects an old-style callback function; see
     65 L<BN_generate_prime(3)> for information on the old-style callback.
     66 
     67 =over 2
     68 
     69 =item *
     70 
     71 While a random prime number is generated, it is called as
     72 described in L<BN_generate_prime(3)>.
     73 
     74 =item *
     75 
     76 When the n-th randomly generated prime is rejected as not
     77 suitable for the key, I<BN_GENCB_call(cb, 2, n)> is called.
     78 
     79 =item *
     80 
     81 When a random p has been found with p-1 relatively prime to I<e>,
     82 it is called as I<BN_GENCB_call(cb, 3, 0)>.
     83 
     84 =back
     85 
     86 The process is then repeated for prime q and other primes (if any)
     87 with I<BN_GENCB_call(cb, 3, i)> where I<i> indicates the i-th prime.
     88 
     89 =head1 RETURN VALUES
     90 
     91 EVP_RSA_gen() returns an I<EVP_PKEY> or NULL on failure.
     92 
     93 RSA_generate_multi_prime_key() returns 1 on success or 0 on error.
     94 RSA_generate_key_ex() returns 1 on success or 0 on error.
     95 The error codes can be obtained by L<ERR_get_error(3)>.
     96 
     97 RSA_generate_key() returns a pointer to the RSA structure or
     98 NULL if the key generation fails.
     99 
    100 =head1 BUGS
    101 
    102 I<BN_GENCB_call(cb, 2, x)> is used with two different meanings.
    103 
    104 =head1 SEE ALSO
    105 
    106 L<EVP_PKEY_Q_keygen(3)>
    107 L<BN_generate_prime(3)>, L<ERR_get_error(3)>,
    108 L<RAND_bytes(3)>, L<RAND(7)>
    109 
    110 =head1 HISTORY
    111 
    112 EVP_RSA_gen() was added in OpenSSL 3.0.
    113 All other functions described here were deprecated in OpenSSL 3.0.
    114 For replacement see L<EVP_PKEY-RSA(7)>.
    115 
    116 =head1 COPYRIGHT
    117 
    118 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
    119 
    120 Licensed under the Apache License 2.0 (the "License").  You may not use
    121 this file except in compliance with the License.  You can obtain a copy
    122 in the file LICENSE in the source distribution or at
    123 L<https://www.openssl.org/source/license.html>.
    124 
    125 =cut
    126