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