1 1.1 christos =pod 2 1.1 christos 3 1.1 christos =head1 NAME 4 1.1 christos 5 1.1 christos RSA_check_key_ex, RSA_check_key - validate private RSA keys 6 1.1 christos 7 1.1 christos =head1 SYNOPSIS 8 1.1 christos 9 1.1 christos #include <openssl/rsa.h> 10 1.1 christos 11 1.1.1.2 christos The following functions have been deprecated since OpenSSL 3.0, and can be 12 1.1.1.2 christos hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value, 13 1.1.1.2 christos see L<openssl_user_macros(7)>: 14 1.1 christos 15 1.1.1.2 christos int RSA_check_key_ex(const RSA *rsa, BN_GENCB *cb); 16 1.1.1.2 christos 17 1.1.1.2 christos int RSA_check_key(const RSA *rsa); 18 1.1 christos 19 1.1 christos =head1 DESCRIPTION 20 1.1 christos 21 1.1.1.2 christos Both of the functions described on this page are deprecated. 22 1.1.1.2 christos Applications should instead use L<EVP_PKEY_public_check(3)>, 23 1.1.1.2 christos L<EVP_PKEY_private_check(3)> and L<EVP_PKEY_pairwise_check(3)>. 24 1.1.1.2 christos 25 1.1 christos RSA_check_key_ex() function validates RSA keys. 26 1.1 christos It checks that B<p> and B<q> are 27 1.1 christos in fact prime, and that B<n = p*q>. 28 1.1 christos 29 1.1 christos It does not work on RSA public keys that have only the modulus 30 1.1 christos and public exponent elements populated. 31 1.1 christos It also checks that B<d*e = 1 mod (p-1*q-1)>, 32 1.1 christos and that B<dmp1>, B<dmq1> and B<iqmp> are set correctly or are B<NULL>. 33 1.1 christos It performs integrity checks on all 34 1.1 christos the RSA key material, so the RSA key structure must contain all the private 35 1.1 christos key data too. 36 1.1 christos Therefore, it cannot be used with any arbitrary RSA key object, 37 1.1 christos even if it is otherwise fit for regular RSA operation. 38 1.1 christos 39 1.1 christos The B<cb> parameter is a callback that will be invoked in the same 40 1.1 christos manner as L<BN_is_prime_ex(3)>. 41 1.1 christos 42 1.1 christos RSA_check_key() is equivalent to RSA_check_key_ex() with a NULL B<cb>. 43 1.1 christos 44 1.1 christos =head1 RETURN VALUES 45 1.1 christos 46 1.1 christos RSA_check_key_ex() and RSA_check_key() 47 1.1 christos return 1 if B<rsa> is a valid RSA key, and 0 otherwise. 48 1.1 christos They return -1 if an error occurs while checking the key. 49 1.1 christos 50 1.1 christos If the key is invalid or an error occurred, the reason code can be 51 1.1 christos obtained using L<ERR_get_error(3)>. 52 1.1 christos 53 1.1 christos =head1 NOTES 54 1.1 christos 55 1.1 christos Unlike most other RSA functions, this function does B<not> work 56 1.1 christos transparently with any underlying ENGINE implementation because it uses the 57 1.1 christos key data in the RSA structure directly. An ENGINE implementation can 58 1.1 christos override the way key data is stored and handled, and can even provide 59 1.1 christos support for HSM keys - in which case the RSA structure may contain B<no> 60 1.1 christos key data at all! If the ENGINE in question is only being used for 61 1.1 christos acceleration or analysis purposes, then in all likelihood the RSA key data 62 1.1 christos is complete and untouched, but this can't be assumed in the general case. 63 1.1 christos 64 1.1 christos =head1 BUGS 65 1.1 christos 66 1.1 christos A method of verifying the RSA key using opaque RSA API functions might need 67 1.1 christos to be considered. Right now RSA_check_key() simply uses the RSA structure 68 1.1 christos elements directly, bypassing the RSA_METHOD table altogether (and 69 1.1 christos completely violating encapsulation and object-orientation in the process). 70 1.1 christos The best fix will probably be to introduce a "check_key()" handler to the 71 1.1 christos RSA_METHOD function table so that alternative implementations can also 72 1.1 christos provide their own verifiers. 73 1.1 christos 74 1.1 christos =head1 SEE ALSO 75 1.1 christos 76 1.1 christos L<BN_is_prime_ex(3)>, 77 1.1 christos L<ERR_get_error(3)> 78 1.1 christos 79 1.1 christos =head1 HISTORY 80 1.1 christos 81 1.1.1.2 christos All of these functions were deprecated in OpenSSL 3.0. 82 1.1.1.2 christos 83 1.1 christos RSA_check_key_ex() appeared after OpenSSL 1.0.2. 84 1.1 christos 85 1.1 christos =head1 COPYRIGHT 86 1.1 christos 87 1.1.1.2 christos Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. 88 1.1 christos 89 1.1.1.2 christos Licensed under the Apache License 2.0 (the "License"). You may not use 90 1.1 christos this file except in compliance with the License. You can obtain a copy 91 1.1 christos in the file LICENSE in the source distribution or at 92 1.1 christos L<https://www.openssl.org/source/license.html>. 93 1.1 christos 94 1.1 christos =cut 95