RSA_generate_key.pod 3.8 KB

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