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