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