1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
.\" $OpenBSD: RSA_check_key.3,v 1.7 2019/06/10 14:58:48 schwarze Exp $
.\" OpenSSL 6859cf74 Sep 25 13:33:28 2002 +0000
.\"
.\" This file was written by Ulf Moeller <ulf@openssl.org> and
.\" Geoff Thorpe <geoff@openssl.org>.
.\" Copyright (c) 2000, 2002 The OpenSSL Project. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in
.\" the documentation and/or other materials provided with the
.\" distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\" software must display the following acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\" endorse or promote products derived from this software without
.\" prior written permission. For written permission, please contact
.\" openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\" nor may "OpenSSL" appear in their names without prior written
.\" permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\" acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: June 10 2019 $
.Dt RSA_CHECK_KEY 3
.Os
.Sh NAME
.Nm RSA_check_key
.Nd validate private RSA keys
.Sh SYNOPSIS
.In openssl/rsa.h
.Ft int
.Fo RSA_check_key
.Fa "RSA *rsa"
.Fc
.Sh DESCRIPTION
This function validates RSA keys.
It checks that
.Fa rsa->p
and
.Fa rsa->q
are in fact prime, and that
.Fa rsa->n
satifies n = p*q.
.Pp
It also checks that
.Fa rsa->d
and
.Fa rsa->e
satisfy d*e = 1 mod ((p-1)*(q-1)),
and that
.Fa rsa->dmp1 ,
.Fa rsa->dmq1 ,
and
.Fa resa->iqmp
are set correctly or are
.Dv NULL .
.Pp
This function does not work on RSA public keys that have only the
modulus and public exponent elements populated.
It performs integrity checks on all the RSA key material, so the
.Vt RSA
key structure must contain all the private key data too.
Therefore, it cannot be used with any arbitrary
.Vt RSA
key object, even if it is otherwise fit for regular RSA operation.
.Pp
Unlike most other RSA functions, this function does
.Sy not
work transparently with any underlying
.Vt ENGINE
implementation because it uses the key data in the
.Vt RSA
structure directly.
An
.Vt ENGINE
implementation can override the way key data is stored and handled,
and can even provide support for HSM keys - in which case the
.Vt RSA
structure may contain
.Sy no
key data at all!
If the
.Vt ENGINE
in question is only being used for acceleration or analysis purposes,
then in all likelihood the RSA key data is complete and untouched,
but this can't be assumed in the general case.
.Sh RETURN VALUES
.Fn RSA_check_key
returns 1 if
.Fa rsa
is a valid RSA key, and 0 otherwise.
-1 is returned if an error occurs while checking the key.
.Pp
If the key is invalid or an error occurred, the reason code can be
obtained using
.Xr ERR_get_error 3 .
.Sh SEE ALSO
.Xr BN_is_prime_ex 3 ,
.Xr RSA_get0_key 3 ,
.Xr RSA_new 3
.Sh HISTORY
.Fn RSA_check_key
first appeared in OpenSSL 0.9.4 and has been available since
.Ox 2.6 .
.Sh BUGS
A method of verifying the RSA key using opaque RSA API functions might
need to be considered.
Right now
.Fn RSA_check_key
simply uses the
.Vt RSA
structure elements directly, bypassing the
.Vt RSA_METHOD
table altogether (and completely violating encapsulation and
object-orientation in the process).
The best fix will probably be to introduce a check_key() handler
to the
.Vt RSA_METHOD
function table so that alternative implementations can also provide
their own verifiers.
|