1*b077aed3SPierre Pronchery=pod 2*b077aed3SPierre Pronchery 3*b077aed3SPierre Pronchery=head1 NAME 4*b077aed3SPierre Pronchery 5*b077aed3SPierre ProncheryEVP_PKEY-RSA, EVP_KEYMGMT-RSA, RSA 6*b077aed3SPierre Pronchery- EVP_PKEY RSA keytype and algorithm support 7*b077aed3SPierre Pronchery 8*b077aed3SPierre Pronchery=head1 DESCRIPTION 9*b077aed3SPierre Pronchery 10*b077aed3SPierre ProncheryThe B<RSA> keytype is implemented in OpenSSL's default and FIPS providers. 11*b077aed3SPierre ProncheryThat implementation supports the basic RSA keys, containing the modulus I<n>, 12*b077aed3SPierre Proncherythe public exponent I<e>, the private exponent I<d>, and a collection of prime 13*b077aed3SPierre Proncheryfactors, exponents and coefficient for CRT calculations, of which the first 14*b077aed3SPierre Proncheryfew are known as I<p> and I<q>, I<dP> and I<dQ>, and I<qInv>. 15*b077aed3SPierre Pronchery 16*b077aed3SPierre Pronchery=head2 Common RSA parameters 17*b077aed3SPierre Pronchery 18*b077aed3SPierre ProncheryIn addition to the common parameters that all keytypes should support (see 19*b077aed3SPierre ProncheryL<provider-keymgmt(7)/Common parameters>), the B<RSA> keytype implementation 20*b077aed3SPierre Proncherysupports the following. 21*b077aed3SPierre Pronchery 22*b077aed3SPierre Pronchery=over 4 23*b077aed3SPierre Pronchery 24*b077aed3SPierre Pronchery=item "n" (B<OSSL_PKEY_PARAM_RSA_N>) <unsigned integer> 25*b077aed3SPierre Pronchery 26*b077aed3SPierre ProncheryThe RSA modulus "n" value. 27*b077aed3SPierre Pronchery 28*b077aed3SPierre Pronchery=item "e" (B<OSSL_PKEY_PARAM_RSA_E>) <unsigned integer> 29*b077aed3SPierre Pronchery 30*b077aed3SPierre ProncheryThe RSA public exponent "e" value. 31*b077aed3SPierre ProncheryThis value must always be set when creating a raw key using L<EVP_PKEY_fromdata(3)>. 32*b077aed3SPierre ProncheryNote that when a decryption operation is performed, that this value is used for 33*b077aed3SPierre Proncheryblinding purposes to prevent timing attacks. 34*b077aed3SPierre Pronchery 35*b077aed3SPierre Pronchery=item "d" (B<OSSL_PKEY_PARAM_RSA_D>) <unsigned integer> 36*b077aed3SPierre Pronchery 37*b077aed3SPierre ProncheryThe RSA private exponent "d" value. 38*b077aed3SPierre Pronchery 39*b077aed3SPierre Pronchery=item "rsa-factor1" (B<OSSL_PKEY_PARAM_RSA_FACTOR1>) <unsigned integer> 40*b077aed3SPierre Pronchery 41*b077aed3SPierre Pronchery=item "rsa-factor2" (B<OSSL_PKEY_PARAM_RSA_FACTOR2>) <unsigned integer> 42*b077aed3SPierre Pronchery 43*b077aed3SPierre Pronchery=item "rsa-factor3" (B<OSSL_PKEY_PARAM_RSA_FACTOR3>) <unsigned integer> 44*b077aed3SPierre Pronchery 45*b077aed3SPierre Pronchery=item "rsa-factor4" (B<OSSL_PKEY_PARAM_RSA_FACTOR4>) <unsigned integer> 46*b077aed3SPierre Pronchery 47*b077aed3SPierre Pronchery=item "rsa-factor5" (B<OSSL_PKEY_PARAM_RSA_FACTOR5>) <unsigned integer> 48*b077aed3SPierre Pronchery 49*b077aed3SPierre Pronchery=item "rsa-factor6" (B<OSSL_PKEY_PARAM_RSA_FACTOR6>) <unsigned integer> 50*b077aed3SPierre Pronchery 51*b077aed3SPierre Pronchery=item "rsa-factor7" (B<OSSL_PKEY_PARAM_RSA_FACTOR7>) <unsigned integer> 52*b077aed3SPierre Pronchery 53*b077aed3SPierre Pronchery=item "rsa-factor8" (B<OSSL_PKEY_PARAM_RSA_FACTOR8>) <unsigned integer> 54*b077aed3SPierre Pronchery 55*b077aed3SPierre Pronchery=item "rsa-factor9" (B<OSSL_PKEY_PARAM_RSA_FACTOR9>) <unsigned integer> 56*b077aed3SPierre Pronchery 57*b077aed3SPierre Pronchery=item "rsa-factor10" (B<OSSL_PKEY_PARAM_RSA_FACTOR10>) <unsigned integer> 58*b077aed3SPierre Pronchery 59*b077aed3SPierre ProncheryRSA prime factors. The factors are known as "p", "q" and "r_i" in RFC8017. 60*b077aed3SPierre ProncheryUp to eight additional "r_i" prime factors are supported. 61*b077aed3SPierre Pronchery 62*b077aed3SPierre Pronchery=item "rsa-exponent1" (B<OSSL_PKEY_PARAM_RSA_EXPONENT1>) <unsigned integer> 63*b077aed3SPierre Pronchery 64*b077aed3SPierre Pronchery=item "rsa-exponent2" (B<OSSL_PKEY_PARAM_RSA_EXPONENT2>) <unsigned integer> 65*b077aed3SPierre Pronchery 66*b077aed3SPierre Pronchery=item "rsa-exponent3" (B<OSSL_PKEY_PARAM_RSA_EXPONENT3>) <unsigned integer> 67*b077aed3SPierre Pronchery 68*b077aed3SPierre Pronchery=item "rsa-exponent4" (B<OSSL_PKEY_PARAM_RSA_EXPONENT4>) <unsigned integer> 69*b077aed3SPierre Pronchery 70*b077aed3SPierre Pronchery=item "rsa-exponent5" (B<OSSL_PKEY_PARAM_RSA_EXPONENT5>) <unsigned integer> 71*b077aed3SPierre Pronchery 72*b077aed3SPierre Pronchery=item "rsa-exponent6" (B<OSSL_PKEY_PARAM_RSA_EXPONENT6>) <unsigned integer> 73*b077aed3SPierre Pronchery 74*b077aed3SPierre Pronchery=item "rsa-exponent7" (B<OSSL_PKEY_PARAM_RSA_EXPONENT7>) <unsigned integer> 75*b077aed3SPierre Pronchery 76*b077aed3SPierre Pronchery=item "rsa-exponent8" (B<OSSL_PKEY_PARAM_RSA_EXPONENT8>) <unsigned integer> 77*b077aed3SPierre Pronchery 78*b077aed3SPierre Pronchery=item "rsa-exponent9" (B<OSSL_PKEY_PARAM_RSA_EXPONENT9>) <unsigned integer> 79*b077aed3SPierre Pronchery 80*b077aed3SPierre Pronchery=item "rsa-exponent10" (B<OSSL_PKEY_PARAM_RSA_EXPONENT10>) <unsigned integer> 81*b077aed3SPierre Pronchery 82*b077aed3SPierre ProncheryRSA CRT (Chinese Remainder Theorem) exponents. The exponents are known 83*b077aed3SPierre Proncheryas "dP", "dQ" and "d_i in RFC8017". 84*b077aed3SPierre ProncheryUp to eight additional "d_i" exponents are supported. 85*b077aed3SPierre Pronchery 86*b077aed3SPierre Pronchery=item "rsa-coefficient1" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT1>) <unsigned integer> 87*b077aed3SPierre Pronchery 88*b077aed3SPierre Pronchery=item "rsa-coefficient2" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT2>) <unsigned integer> 89*b077aed3SPierre Pronchery 90*b077aed3SPierre Pronchery=item "rsa-coefficient3" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT3>) <unsigned integer> 91*b077aed3SPierre Pronchery 92*b077aed3SPierre Pronchery=item "rsa-coefficient4" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT4>) <unsigned integer> 93*b077aed3SPierre Pronchery 94*b077aed3SPierre Pronchery=item "rsa-coefficient5" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT5>) <unsigned integer> 95*b077aed3SPierre Pronchery 96*b077aed3SPierre Pronchery=item "rsa-coefficient6" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT6>) <unsigned integer> 97*b077aed3SPierre Pronchery 98*b077aed3SPierre Pronchery=item "rsa-coefficient7" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT7>) <unsigned integer> 99*b077aed3SPierre Pronchery 100*b077aed3SPierre Pronchery=item "rsa-coefficient8" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT8>) <unsigned integer> 101*b077aed3SPierre Pronchery 102*b077aed3SPierre Pronchery=item "rsa-coefficient9" (B<OSSL_PKEY_PARAM_RSA_COEFFICIENT9>) <unsigned integer> 103*b077aed3SPierre Pronchery 104*b077aed3SPierre ProncheryRSA CRT (Chinese Remainder Theorem) coefficients. The coefficients are known as 105*b077aed3SPierre Pronchery"qInv" and "t_i". 106*b077aed3SPierre ProncheryUp to eight additional "t_i" exponents are supported. 107*b077aed3SPierre Pronchery 108*b077aed3SPierre Pronchery=back 109*b077aed3SPierre Pronchery 110*b077aed3SPierre Pronchery=head2 RSA key generation parameters 111*b077aed3SPierre Pronchery 112*b077aed3SPierre ProncheryWhen generating RSA keys, the following key generation parameters may be used. 113*b077aed3SPierre Pronchery 114*b077aed3SPierre Pronchery=over 4 115*b077aed3SPierre Pronchery 116*b077aed3SPierre Pronchery=item "bits" (B<OSSL_PKEY_PARAM_RSA_BITS>) <unsigned integer> 117*b077aed3SPierre Pronchery 118*b077aed3SPierre ProncheryThe value should be the cryptographic length for the B<RSA> cryptosystem, in 119*b077aed3SPierre Proncherybits. 120*b077aed3SPierre Pronchery 121*b077aed3SPierre Pronchery=item "primes" (B<OSSL_PKEY_PARAM_RSA_PRIMES>) <unsigned integer> 122*b077aed3SPierre Pronchery 123*b077aed3SPierre ProncheryThe value should be the number of primes for the generated B<RSA> key. The 124*b077aed3SPierre Proncherydefault is 2. It isn't permitted to specify a larger number of primes than 125*b077aed3SPierre Pronchery10. Additionally, the number of primes is limited by the length of the key 126*b077aed3SPierre Proncherybeing generated so the maximum number could be less. 127*b077aed3SPierre ProncherySome providers may only support a value of 2. 128*b077aed3SPierre Pronchery 129*b077aed3SPierre Pronchery=item "e" (B<OSSL_PKEY_PARAM_RSA_E>) <unsigned integer> 130*b077aed3SPierre Pronchery 131*b077aed3SPierre ProncheryThe RSA "e" value. The value may be any odd number greater than or equal to 132*b077aed3SPierre Pronchery65537. The default value is 65537. 133*b077aed3SPierre ProncheryFor legacy reasons a value of 3 is currently accepted but is deprecated. 134*b077aed3SPierre Pronchery 135*b077aed3SPierre Pronchery=back 136*b077aed3SPierre Pronchery 137*b077aed3SPierre Pronchery=head2 RSA key generation parameters for FIPS module testing 138*b077aed3SPierre Pronchery 139*b077aed3SPierre ProncheryWhen generating RSA keys, the following additional key generation parameters may 140*b077aed3SPierre Proncherybe used for algorithm testing purposes only. Do not use these to generate 141*b077aed3SPierre ProncheryRSA keys for a production environment. 142*b077aed3SPierre Pronchery 143*b077aed3SPierre Pronchery=over 4 144*b077aed3SPierre Pronchery 145*b077aed3SPierre Pronchery=item "xp" (B<OSSL_PKEY_PARAM_RSA_TEST_XP>) <unsigned integer> 146*b077aed3SPierre Pronchery 147*b077aed3SPierre Pronchery=item "xq" (B<OSSL_PKEY_PARAM_RSA_TEST_XQ>) <unsigned integer> 148*b077aed3SPierre Pronchery 149*b077aed3SPierre ProncheryThese 2 fields are normally randomly generated and are used to generate "p" and 150*b077aed3SPierre Pronchery"q". 151*b077aed3SPierre Pronchery 152*b077aed3SPierre Pronchery=item "xp1" (B<OSSL_PKEY_PARAM_RSA_TEST_XP1>) <unsigned integer> 153*b077aed3SPierre Pronchery 154*b077aed3SPierre Pronchery=item "xp2" (B<OSSL_PKEY_PARAM_RSA_TEST_XP2>) <unsigned integer> 155*b077aed3SPierre Pronchery 156*b077aed3SPierre Pronchery=item "xq1" (B<OSSL_PKEY_PARAM_RSA_TEST_XQ1>) <unsigned integer> 157*b077aed3SPierre Pronchery 158*b077aed3SPierre Pronchery=item "xq2" (B<OSSL_PKEY_PARAM_RSA_TEST_XQ2>) <unsigned integer> 159*b077aed3SPierre Pronchery 160*b077aed3SPierre ProncheryThese 4 fields are normally randomly generated. The prime factors "p1", "p2", 161*b077aed3SPierre Pronchery"q1" and "q2" are determined from these values. 162*b077aed3SPierre Pronchery 163*b077aed3SPierre Pronchery=back 164*b077aed3SPierre Pronchery 165*b077aed3SPierre Pronchery=head2 RSA key parameters for FIPS module testing 166*b077aed3SPierre Pronchery 167*b077aed3SPierre ProncheryThe following intermediate values can be retrieved only if the values 168*b077aed3SPierre Proncheryspecified in L</"RSA key generation parameters for FIPS module testing"> are set. 169*b077aed3SPierre ProncheryThese should not be accessed in a production environment. 170*b077aed3SPierre Pronchery 171*b077aed3SPierre Pronchery=over 4 172*b077aed3SPierre Pronchery 173*b077aed3SPierre Pronchery=item "p1" (B<OSSL_PKEY_PARAM_RSA_TEST_P1>) <unsigned integer> 174*b077aed3SPierre Pronchery 175*b077aed3SPierre Pronchery=item "p2" (B<OSSL_PKEY_PARAM_RSA_TEST_P2>) <unsigned integer> 176*b077aed3SPierre Pronchery 177*b077aed3SPierre Pronchery=item "q1" (B<OSSL_PKEY_PARAM_RSA_TEST_Q1>) <unsigned integer> 178*b077aed3SPierre Pronchery 179*b077aed3SPierre Pronchery=item "q2" (B<OSSL_PKEY_PARAM_RSA_TEST_Q2>) <unsigned integer> 180*b077aed3SPierre Pronchery 181*b077aed3SPierre ProncheryThe auxiliary probable primes. 182*b077aed3SPierre Pronchery 183*b077aed3SPierre Pronchery=back 184*b077aed3SPierre Pronchery 185*b077aed3SPierre Pronchery=head2 RSA key validation 186*b077aed3SPierre Pronchery 187*b077aed3SPierre ProncheryFor RSA keys, L<EVP_PKEY_param_check(3)> and L<EVP_PKEY_param_check_quick(3)> 188*b077aed3SPierre Proncheryboth return 1 unconditionally. 189*b077aed3SPierre Pronchery 190*b077aed3SPierre ProncheryFor RSA keys, L<EVP_PKEY_public_check(3)> conforms to the SP800-56Br1 I<public key 191*b077aed3SPierre Proncherycheck> when the OpenSSL FIPS provider is used. The OpenSSL default provider 192*b077aed3SPierre Proncheryperforms similiar tests but relaxes the keysize restrictions for backwards 193*b077aed3SPierre Proncherycompatibility. 194*b077aed3SPierre Pronchery 195*b077aed3SPierre ProncheryFor RSA keys, L<EVP_PKEY_public_check_quick(3)> is the same as 196*b077aed3SPierre ProncheryL<EVP_PKEY_public_check(3)>. 197*b077aed3SPierre Pronchery 198*b077aed3SPierre ProncheryFor RSA keys, L<EVP_PKEY_private_check(3)> conforms to the SP800-56Br1 199*b077aed3SPierre ProncheryI<private key test>. 200*b077aed3SPierre Pronchery 201*b077aed3SPierre ProncheryFor RSA keys, L<EVP_PKEY_pairwise_check(3)> conforms to the 202*b077aed3SPierre ProncherySP800-56Br1 I<KeyPair Validation check> for the OpenSSL FIPS provider. The 203*b077aed3SPierre ProncheryOpenSSL default provider allows testing of the validity of multi-primes. 204*b077aed3SPierre Pronchery 205*b077aed3SPierre Pronchery=head1 CONFORMING TO 206*b077aed3SPierre Pronchery 207*b077aed3SPierre Pronchery=over 4 208*b077aed3SPierre Pronchery 209*b077aed3SPierre Pronchery=item FIPS186-4 210*b077aed3SPierre Pronchery 211*b077aed3SPierre ProncherySection B.3.6 Generation of Probable Primes with Conditions Based on 212*b077aed3SPierre ProncheryAuxiliary Probable Primes 213*b077aed3SPierre Pronchery 214*b077aed3SPierre Pronchery=item RFC 8017, excluding RSA-PSS and RSA-OAEP 215*b077aed3SPierre Pronchery 216*b077aed3SPierre Pronchery=for comment RSA-PSS, and probably also RSA-OAEP, need separate keytypes, 217*b077aed3SPierre Proncheryand will be described in separate pages for those RSA keytypes. 218*b077aed3SPierre Pronchery 219*b077aed3SPierre Pronchery=back 220*b077aed3SPierre Pronchery 221*b077aed3SPierre Pronchery=head1 EXAMPLES 222*b077aed3SPierre Pronchery 223*b077aed3SPierre ProncheryAn B<EVP_PKEY> context can be obtained by calling: 224*b077aed3SPierre Pronchery 225*b077aed3SPierre Pronchery EVP_PKEY_CTX *pctx = 226*b077aed3SPierre Pronchery EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL); 227*b077aed3SPierre Pronchery 228*b077aed3SPierre ProncheryAn B<RSA> key can be generated simply like this: 229*b077aed3SPierre Pronchery 230*b077aed3SPierre Pronchery pkey = EVP_RSA_gen(4096); 231*b077aed3SPierre Pronchery 232*b077aed3SPierre Proncheryor like this: 233*b077aed3SPierre Pronchery 234*b077aed3SPierre Pronchery EVP_PKEY *pkey = NULL; 235*b077aed3SPierre Pronchery EVP_PKEY_CTX *pctx = 236*b077aed3SPierre Pronchery EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL); 237*b077aed3SPierre Pronchery 238*b077aed3SPierre Pronchery EVP_PKEY_keygen_init(pctx); 239*b077aed3SPierre Pronchery EVP_PKEY_generate(pctx, &pkey); 240*b077aed3SPierre Pronchery EVP_PKEY_CTX_free(pctx); 241*b077aed3SPierre Pronchery 242*b077aed3SPierre ProncheryAn B<RSA> key can be generated with key generation parameters: 243*b077aed3SPierre Pronchery 244*b077aed3SPierre Pronchery unsigned int primes = 3; 245*b077aed3SPierre Pronchery unsigned int bits = 4096; 246*b077aed3SPierre Pronchery OSSL_PARAM params[3]; 247*b077aed3SPierre Pronchery EVP_PKEY *pkey = NULL; 248*b077aed3SPierre Pronchery EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL); 249*b077aed3SPierre Pronchery 250*b077aed3SPierre Pronchery EVP_PKEY_keygen_init(pctx); 251*b077aed3SPierre Pronchery 252*b077aed3SPierre Pronchery params[0] = OSSL_PARAM_construct_uint("bits", &bits); 253*b077aed3SPierre Pronchery params[1] = OSSL_PARAM_construct_uint("primes", &primes); 254*b077aed3SPierre Pronchery params[2] = OSSL_PARAM_construct_end(); 255*b077aed3SPierre Pronchery EVP_PKEY_CTX_set_params(pctx, params); 256*b077aed3SPierre Pronchery 257*b077aed3SPierre Pronchery EVP_PKEY_generate(pctx, &pkey); 258*b077aed3SPierre Pronchery EVP_PKEY_print_private(bio_out, pkey, 0, NULL); 259*b077aed3SPierre Pronchery EVP_PKEY_CTX_free(pctx); 260*b077aed3SPierre Pronchery 261*b077aed3SPierre Pronchery=head1 SEE ALSO 262*b077aed3SPierre Pronchery 263*b077aed3SPierre ProncheryL<EVP_RSA_gen(3)>, L<EVP_KEYMGMT(3)>, L<EVP_PKEY(3)>, L<provider-keymgmt(7)> 264*b077aed3SPierre Pronchery 265*b077aed3SPierre Pronchery=head1 COPYRIGHT 266*b077aed3SPierre Pronchery 267*b077aed3SPierre ProncheryCopyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved. 268*b077aed3SPierre Pronchery 269*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 270*b077aed3SPierre Proncherythis file except in compliance with the License. You can obtain a copy 271*b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at 272*b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>. 273*b077aed3SPierre Pronchery 274*b077aed3SPierre Pronchery=cut 275