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