2
0

RSA_generate_key.pod 3.9 KB

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