1*4724848cSchristos=pod 2*4724848cSchristos 3*4724848cSchristos=head1 NAME 4*4724848cSchristos 5*4724848cSchristosRSA_check_key_ex, RSA_check_key - validate private RSA keys 6*4724848cSchristos 7*4724848cSchristos=head1 SYNOPSIS 8*4724848cSchristos 9*4724848cSchristos #include <openssl/rsa.h> 10*4724848cSchristos 11*4724848cSchristos int RSA_check_key_ex(RSA *rsa, BN_GENCB *cb); 12*4724848cSchristos 13*4724848cSchristos int RSA_check_key(RSA *rsa); 14*4724848cSchristos 15*4724848cSchristos=head1 DESCRIPTION 16*4724848cSchristos 17*4724848cSchristosRSA_check_key_ex() function validates RSA keys. 18*4724848cSchristosIt checks that B<p> and B<q> are 19*4724848cSchristosin fact prime, and that B<n = p*q>. 20*4724848cSchristos 21*4724848cSchristosIt does not work on RSA public keys that have only the modulus 22*4724848cSchristosand public exponent elements populated. 23*4724848cSchristosIt also checks that B<d*e = 1 mod (p-1*q-1)>, 24*4724848cSchristosand that B<dmp1>, B<dmq1> and B<iqmp> are set correctly or are B<NULL>. 25*4724848cSchristosIt performs integrity checks on all 26*4724848cSchristosthe RSA key material, so the RSA key structure must contain all the private 27*4724848cSchristoskey data too. 28*4724848cSchristosTherefore, it cannot be used with any arbitrary RSA key object, 29*4724848cSchristoseven if it is otherwise fit for regular RSA operation. 30*4724848cSchristos 31*4724848cSchristosThe B<cb> parameter is a callback that will be invoked in the same 32*4724848cSchristosmanner as L<BN_is_prime_ex(3)>. 33*4724848cSchristos 34*4724848cSchristosRSA_check_key() is equivalent to RSA_check_key_ex() with a NULL B<cb>. 35*4724848cSchristos 36*4724848cSchristos=head1 RETURN VALUES 37*4724848cSchristos 38*4724848cSchristosRSA_check_key_ex() and RSA_check_key() 39*4724848cSchristosreturn 1 if B<rsa> is a valid RSA key, and 0 otherwise. 40*4724848cSchristosThey return -1 if an error occurs while checking the key. 41*4724848cSchristos 42*4724848cSchristosIf the key is invalid or an error occurred, the reason code can be 43*4724848cSchristosobtained using L<ERR_get_error(3)>. 44*4724848cSchristos 45*4724848cSchristos=head1 NOTES 46*4724848cSchristos 47*4724848cSchristosUnlike most other RSA functions, this function does B<not> work 48*4724848cSchristostransparently with any underlying ENGINE implementation because it uses the 49*4724848cSchristoskey data in the RSA structure directly. An ENGINE implementation can 50*4724848cSchristosoverride the way key data is stored and handled, and can even provide 51*4724848cSchristossupport for HSM keys - in which case the RSA structure may contain B<no> 52*4724848cSchristoskey data at all! If the ENGINE in question is only being used for 53*4724848cSchristosacceleration or analysis purposes, then in all likelihood the RSA key data 54*4724848cSchristosis complete and untouched, but this can't be assumed in the general case. 55*4724848cSchristos 56*4724848cSchristos=head1 BUGS 57*4724848cSchristos 58*4724848cSchristosA method of verifying the RSA key using opaque RSA API functions might need 59*4724848cSchristosto be considered. Right now RSA_check_key() simply uses the RSA structure 60*4724848cSchristoselements directly, bypassing the RSA_METHOD table altogether (and 61*4724848cSchristoscompletely violating encapsulation and object-orientation in the process). 62*4724848cSchristosThe best fix will probably be to introduce a "check_key()" handler to the 63*4724848cSchristosRSA_METHOD function table so that alternative implementations can also 64*4724848cSchristosprovide their own verifiers. 65*4724848cSchristos 66*4724848cSchristos=head1 SEE ALSO 67*4724848cSchristos 68*4724848cSchristosL<BN_is_prime_ex(3)>, 69*4724848cSchristosL<ERR_get_error(3)> 70*4724848cSchristos 71*4724848cSchristos=head1 HISTORY 72*4724848cSchristos 73*4724848cSchristosRSA_check_key_ex() appeared after OpenSSL 1.0.2. 74*4724848cSchristos 75*4724848cSchristos=head1 COPYRIGHT 76*4724848cSchristos 77*4724848cSchristosCopyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. 78*4724848cSchristos 79*4724848cSchristosLicensed under the OpenSSL license (the "License"). You may not use 80*4724848cSchristosthis file except in compliance with the License. You can obtain a copy 81*4724848cSchristosin the file LICENSE in the source distribution or at 82*4724848cSchristosL<https://www.openssl.org/source/license.html>. 83*4724848cSchristos 84*4724848cSchristos=cut 85