2
0

EVP_PKEY-RSA.pod 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY-RSA, EVP_KEYMGMT-RSA, RSA
  4. - EVP_PKEY RSA keytype and algorithm support
  5. =head1 DESCRIPTION
  6. The B<RSA> keytype is implemented in OpenSSL's default and FIPS providers.
  7. That implementation supports the basic RSA keys, containing the modulus I<n>,
  8. the public exponent I<e>, the private exponent I<d>, and a collection of prime
  9. factors, exponents and coefficient for CRT calculations, of which the first
  10. few are known as I<p> and I<q>, I<dP> and I<dQ>, and I<qInv>.
  11. =head2 Common RSA parameters
  12. In addition to the common parameters that all keytypes should support (see
  13. L<provider-keymgmt(7)/Common parameters>), the B<RSA> keytype implementation
  14. supports the following.
  15. =over 4
  16. =item "n" (B<OSSL_PKEY_PARAM_RSA_N>) <unsigned integer>
  17. The RSA modulus "n" value.
  18. =item "e" (B<OSSL_PKEY_PARAM_RSA_E>) <unsigned integer>
  19. The RSA public exponent "e" value.
  20. This value must always be set when creating a raw key using L<EVP_PKEY_fromdata(3)>.
  21. Note that when a decryption operation is performed, that this value is used for
  22. blinding purposes to prevent timing attacks.
  23. =item "d" (B<OSSL_PKEY_PARAM_RSA_D>) <unsigned integer>
  24. The RSA private exponent "d" value.
  25. =item "rsa-factor1" (B<OSSL_PKEY_PARAM_RSA_FACTOR1>) <unsigned integer>
  26. =item "rsa-factor2" (B<OSSL_PKEY_PARAM_RSA_FACTOR2>) <unsigned integer>
  27. =item "rsa-factor3" (B<OSSL_PKEY_PARAM_RSA_FACTOR3>) <unsigned integer>
  28. =item "rsa-factor4" (B<OSSL_PKEY_PARAM_RSA_FACTOR4>) <unsigned integer>
  29. =item "rsa-factor5" (B<OSSL_PKEY_PARAM_RSA_FACTOR5>) <unsigned integer>
  30. =item "rsa-factor6" (B<OSSL_PKEY_PARAM_RSA_FACTOR6>) <unsigned integer>
  31. =item "rsa-factor7" (B<OSSL_PKEY_PARAM_RSA_FACTOR7>) <unsigned integer>
  32. =item "rsa-factor8" (B<OSSL_PKEY_PARAM_RSA_FACTOR8>) <unsigned integer>
  33. =item "rsa-factor9" (B<OSSL_PKEY_PARAM_RSA_FACTOR9>) <unsigned integer>
  34. =item "rsa-factor10" (B<OSSL_PKEY_PARAM_RSA_FACTOR10>) <unsigned integer>
  35. RSA prime factors. The factors are known as "p", "q" and "r_i" in RFC8017.
  36. Up to eight additional "r_i" prime factors are supported.
  37. =item "rsa-exponent1" (B<OSSL_PKEY_PARAM_RSA_EXPONENT1>) <unsigned integer>
  38. =item "rsa-exponent2" (B<OSSL_PKEY_PARAM_RSA_EXPONENT2>) <unsigned integer>
  39. =item "rsa-exponent3" (B<OSSL_PKEY_PARAM_RSA_EXPONENT3>) <unsigned integer>
  40. =item "rsa-exponent4" (B<OSSL_PKEY_PARAM_RSA_EXPONENT4>) <unsigned integer>
  41. =item "rsa-exponent5" (B<OSSL_PKEY_PARAM_RSA_EXPONENT5>) <unsigned integer>
  42. =item "rsa-exponent6" (B<OSSL_PKEY_PARAM_RSA_EXPONENT6>) <unsigned integer>
  43. =item "rsa-exponent7" (B<OSSL_PKEY_PARAM_RSA_EXPONENT7>) <unsigned integer>
  44. =item "rsa-exponent8" (B<OSSL_PKEY_PARAM_RSA_EXPONENT8>) <unsigned integer>
  45. =item "rsa-exponent9" (B<OSSL_PKEY_PARAM_RSA_EXPONENT9>) <unsigned integer>
  46. =item "rsa-exponent10" (B<OSSL_PKEY_PARAM_RSA_EXPONENT10>) <unsigned integer>
  47. RSA CRT (Chinese Remainder Theorem) exponents. The exponents are known
  48. as "dP", "dQ" and "d_i" in RFC8017.
  49. Up to eight additional "d_i" exponents are supported.
  50. =item "rsa-coefficient1" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT1>) <unsigned integer>
  51. =item "rsa-coefficient2" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT2>) <unsigned integer>
  52. =item "rsa-coefficient3" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT3>) <unsigned integer>
  53. =item "rsa-coefficient4" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT4>) <unsigned integer>
  54. =item "rsa-coefficient5" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT5>) <unsigned integer>
  55. =item "rsa-coefficient6" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT6>) <unsigned integer>
  56. =item "rsa-coefficient7" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT7>) <unsigned integer>
  57. =item "rsa-coefficient8" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT8>) <unsigned integer>
  58. =item "rsa-coefficient9" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT9>) <unsigned integer>
  59. RSA CRT (Chinese Remainder Theorem) coefficients. The coefficients are known as
  60. "qInv" and "t_i".
  61. Up to eight additional "t_i" exponents are supported.
  62. =back
  63. =head2 RSA key generation parameters
  64. When generating RSA keys, the following key generation parameters may be used.
  65. =over 4
  66. =item "bits" (B<OSSL_PKEY_PARAM_RSA_BITS>) <unsigned integer>
  67. The value should be the cryptographic length for the B<RSA> cryptosystem, in
  68. bits.
  69. =item "primes" (B<OSSL_PKEY_PARAM_RSA_PRIMES>) <unsigned integer>
  70. The value should be the number of primes for the generated B<RSA> key. The
  71. default is 2. It isn't permitted to specify a larger number of primes than
  72. 10. Additionally, the number of primes is limited by the length of the key
  73. being generated so the maximum number could be less.
  74. Some providers may only support a value of 2.
  75. =item "e" (B<OSSL_PKEY_PARAM_RSA_E>) <unsigned integer>
  76. The RSA "e" value. The value may be any odd number greater than or equal to
  77. 65537. The default value is 65537.
  78. For legacy reasons a value of 3 is currently accepted but is deprecated.
  79. =item "rsa-derive-from-pq" (B<OSSL_PKEY_PARAM_RSA_DERIVE_FROM_PQ>) <unsigned integer>
  80. Indicate that missing parameters not passed in the parameter list should be
  81. derived if not provided. Setting a nonzero value will cause all
  82. needed exponents and coefficients to be derived if not available. Setting this
  83. option requires at least OSSL_PARAM_RSA_FACTOR1, OSSL_PARAM_RSA_FACTOR2,
  84. and OSSL_PARAM_RSA_N to be provided. This option is ignored if
  85. OSSL_KEYMGMT_SELECT_PRIVATE_KEY is not set in the selection parameter.
  86. =back
  87. =head2 RSA key generation parameters for FIPS module testing
  88. When generating RSA keys, the following additional key generation parameters may
  89. be used for algorithm testing purposes only. Do not use these to generate
  90. RSA keys for a production environment.
  91. =over 4
  92. =item "xp" (B<OSSL_PKEY_PARAM_RSA_TEST_XP>) <unsigned integer>
  93. =item "xq" (B<OSSL_PKEY_PARAM_RSA_TEST_XQ>) <unsigned integer>
  94. These 2 fields are normally randomly generated and are used to generate "p" and
  95. "q".
  96. =item "xp1" (B<OSSL_PKEY_PARAM_RSA_TEST_XP1>) <unsigned integer>
  97. =item "xp2" (B<OSSL_PKEY_PARAM_RSA_TEST_XP2>) <unsigned integer>
  98. =item "xq1" (B<OSSL_PKEY_PARAM_RSA_TEST_XQ1>) <unsigned integer>
  99. =item "xq2" (B<OSSL_PKEY_PARAM_RSA_TEST_XQ2>) <unsigned integer>
  100. These 4 fields are normally randomly generated. The prime factors "p1", "p2",
  101. "q1" and "q2" are determined from these values.
  102. =back
  103. =head2 RSA key parameters for FIPS module testing
  104. The following intermediate values can be retrieved only if the values
  105. specified in L</"RSA key generation parameters for FIPS module testing"> are set.
  106. These should not be accessed in a production environment.
  107. =over 4
  108. =item "p1" (B<OSSL_PKEY_PARAM_RSA_TEST_P1>) <unsigned integer>
  109. =item "p2" (B<OSSL_PKEY_PARAM_RSA_TEST_P2>) <unsigned integer>
  110. =item "q1" (B<OSSL_PKEY_PARAM_RSA_TEST_Q1>) <unsigned integer>
  111. =item "q2" (B<OSSL_PKEY_PARAM_RSA_TEST_Q2>) <unsigned integer>
  112. The auxiliary probable primes.
  113. =back
  114. =head2 RSA key validation
  115. For RSA keys, L<EVP_PKEY_param_check(3)> and L<EVP_PKEY_param_check_quick(3)>
  116. both return 1 unconditionally.
  117. For RSA keys, L<EVP_PKEY_public_check(3)> conforms to the SP800-56Br1 I<public key
  118. check> when the OpenSSL FIPS provider is used. The OpenSSL default provider
  119. performs similar tests but relaxes the keysize restrictions for backwards
  120. compatibility.
  121. For RSA keys, L<EVP_PKEY_public_check_quick(3)> is the same as
  122. L<EVP_PKEY_public_check(3)>.
  123. For RSA keys, L<EVP_PKEY_private_check(3)> conforms to the SP800-56Br1
  124. I<private key test>.
  125. For RSA keys, L<EVP_PKEY_pairwise_check(3)> conforms to the
  126. SP800-56Br1 I<KeyPair Validation check> for the OpenSSL FIPS provider. The
  127. OpenSSL default provider allows testing of the validity of multi-primes.
  128. =head1 CONFORMING TO
  129. =over 4
  130. =item FIPS186-4
  131. Section B.3.6 Generation of Probable Primes with Conditions Based on
  132. Auxiliary Probable Primes
  133. =item RFC 8017, excluding RSA-PSS and RSA-OAEP
  134. =for comment RSA-PSS, and probably also RSA-OAEP, need separate keytypes,
  135. and will be described in separate pages for those RSA keytypes.
  136. =back
  137. =head1 EXAMPLES
  138. An B<EVP_PKEY> context can be obtained by calling:
  139. EVP_PKEY_CTX *pctx =
  140. EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL);
  141. An B<RSA> key can be generated simply like this:
  142. pkey = EVP_RSA_gen(4096);
  143. or like this:
  144. EVP_PKEY *pkey = NULL;
  145. EVP_PKEY_CTX *pctx =
  146. EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL);
  147. EVP_PKEY_keygen_init(pctx);
  148. EVP_PKEY_generate(pctx, &pkey);
  149. EVP_PKEY_CTX_free(pctx);
  150. An B<RSA> key can be generated with key generation parameters:
  151. unsigned int primes = 3;
  152. unsigned int bits = 4096;
  153. OSSL_PARAM params[3];
  154. EVP_PKEY *pkey = NULL;
  155. EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL);
  156. EVP_PKEY_keygen_init(pctx);
  157. params[0] = OSSL_PARAM_construct_uint("bits", &bits);
  158. params[1] = OSSL_PARAM_construct_uint("primes", &primes);
  159. params[2] = OSSL_PARAM_construct_end();
  160. EVP_PKEY_CTX_set_params(pctx, params);
  161. EVP_PKEY_generate(pctx, &pkey);
  162. EVP_PKEY_print_private(bio_out, pkey, 0, NULL);
  163. EVP_PKEY_CTX_free(pctx);
  164. =head1 SEE ALSO
  165. L<EVP_RSA_gen(3)>, L<EVP_KEYMGMT(3)>, L<EVP_PKEY(3)>, L<provider-keymgmt(7)>
  166. =head1 COPYRIGHT
  167. Copyright 2020-2024 The OpenSSL Project Authors. All Rights Reserved.
  168. Licensed under the Apache License 2.0 (the "License"). You may not use
  169. this file except in compliance with the License. You can obtain a copy
  170. in the file LICENSE in the source distribution or at
  171. L<https://www.openssl.org/source/license.html>.
  172. =cut