1 | =pod
|
---|
2 |
|
---|
3 | =head1 NAME
|
---|
4 |
|
---|
5 | RSA_check_key_ex, RSA_check_key - validate private RSA keys
|
---|
6 |
|
---|
7 | =head1 SYNOPSIS
|
---|
8 |
|
---|
9 | #include <openssl/rsa.h>
|
---|
10 |
|
---|
11 | int RSA_check_key_ex(RSA *rsa, BN_GENCB *cb);
|
---|
12 |
|
---|
13 | int RSA_check_key(RSA *rsa);
|
---|
14 |
|
---|
15 | =head1 DESCRIPTION
|
---|
16 |
|
---|
17 | RSA_check_key_ex() function validates RSA keys.
|
---|
18 | It checks that B<p> and B<q> are
|
---|
19 | in fact prime, and that B<n = p*q>.
|
---|
20 |
|
---|
21 | It does not work on RSA public keys that have only the modulus
|
---|
22 | and public exponent elements populated.
|
---|
23 | It also checks that B<d*e = 1 mod (p-1*q-1)>,
|
---|
24 | and that B<dmp1>, B<dmq1> and B<iqmp> are set correctly or are B<NULL>.
|
---|
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
|
---|
32 | manner as L<BN_is_prime_ex(3)>.
|
---|
33 |
|
---|
34 | RSA_check_key() is equivalent to RSA_check_key_ex() with a NULL B<cb>.
|
---|
35 |
|
---|
36 | =head1 RETURN VALUES
|
---|
37 |
|
---|
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.
|
---|
41 |
|
---|
42 | If the key is invalid or an error occurred, the reason code can be
|
---|
43 | obtained using L<ERR_get_error(3)>.
|
---|
44 |
|
---|
45 | =head1 NOTES
|
---|
46 |
|
---|
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.
|
---|
65 |
|
---|
66 | =head1 SEE ALSO
|
---|
67 |
|
---|
68 | L<BN_is_prime_ex(3)>,
|
---|
69 | L<ERR_get_error(3)>
|
---|
70 |
|
---|
71 | =head1 HISTORY
|
---|
72 |
|
---|
73 | RSA_check_key_ex() appeared after OpenSSL 1.0.2.
|
---|
74 |
|
---|
75 | =head1 COPYRIGHT
|
---|
76 |
|
---|
77 | Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
|
---|
78 |
|
---|
79 | Licensed under the OpenSSL license (the "License"). You may not use
|
---|
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
|
---|