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