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
|
.\" $OpenBSD: RSA_check_key.3,v 1.2 2016/11/06 15:52:50 jmc Exp $
.\"
.Dd $Mdocdate: November 6 2016 $
.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
As such, this function cannot be used with any arbitrary
.Vt RSA
key object, even if it is otherwise fit for regular RSA operation.
.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.
.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 ERR_get_error 3 ,
.Xr rsa 3
.Sh HISTORY
.Fn RSA_check_key
appeared in OpenSSL 0.9.4.
.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.
|