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