summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/rsa.3
blob: 7c34f3595baff602a9520238ca14cbcef530030c (plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
.Dd $Mdocdate: November 4 2016 $
.Dt RSA 3
.Os
.Sh NAME
.Nm rsa
.Nd RSA public key cryptosystem
.Sh SYNOPSIS
.In openssl/rsa.h
.In openssl/engine.h
.Ft RSA *
.Fn RSA_new void
.Ft void
.Fo RSA_free
.Fa "RSA *rsa"
.Fc
.Ft int
.Fo RSA_public_encrypt
.Fa "int flen"
.Fa "unsigned char *from"
.Fa "unsigned char *to"
.Fa "RSA *rsa"
.Fa "int padding"
.Fc
.Ft int
.Fo RSA_private_decrypt
.Fa "int flen"
.Fa "unsigned char *from"
.Fa "unsigned char *to"
.Fa "RSA *rsa"
.Fa "int padding"
.Fc
.Ft int
.Fo RSA_private_encrypt
.Fa "int flen"
.Fa "unsigned char *from"
.Fa "unsigned char *to"
.Fa "RSA *rsa"
.Fa "int padding"
.Fc
.Ft int
.Fo RSA_public_decrypt
.Fa "int flen"
.Fa "unsigned char *from"
.Fa "unsigned char *to"
.Fa "RSA *rsa"
.Fa "int padding"
.Fc
.Ft int
.Fo RSA_sign
.Fa "int type"
.Fa "unsigned char *m"
.Fa "unsigned int m_len"
.Fa "unsigned char *sigret"
.Fa "unsigned int *siglen"
.Fa "RSA *rsa"
.Fc
.Ft int
.Fo RSA_verify
.Fa "int type"
.Fa "unsigned char *m"
.Fa "unsigned int m_len"
.Fa "unsigned char *sigbuf"
.Fa "unsigned int siglen"
.Fa "RSA *rsa"
.Fc
.Ft int
.Fo RSA_size
.Fa "const RSA *rsa"
.Fc
.Ft RSA *
.Fo RSA_generate_key
.Fa "int num"
.Fa "unsigned long e"
.Fa "void (*callback)(int, int, void *)"
.Fa "void *cb_arg"
.Fc
.Ft int
.Fo RSA_check_key
.Fa "RSA *rsa"
.Fc
.Ft int
.Fo RSA_blinding_on
.Fa "RSA *rsa"
.Fa "BN_CTX *ctx"
.Fc
.Ft void
.Fo RSA_blinding_off
.Fa "RSA *rsa"
.Fc
.Ft void
.Fo RSA_set_default_method
.Fa "const RSA_METHOD *meth"
.Fc
.Ft const RSA_METHOD *
.Fn RSA_get_default_method void
.Ft int
.Fo RSA_set_method
.Fa "RSA *rsa"
.Fa "const RSA_METHOD *meth"
.Fc
.Ft const RSA_METHOD *
.Fo RSA_get_method
.Fa "const RSA *rsa"
.Fc
.Ft RSA_METHOD *
.Fn RSA_PKCS1_SSLeay void
.Ft RSA_METHOD *
.Fn RSA_null_method void
.Ft int
.Fo RSA_flags
.Fa "const RSA *rsa"
.Fc
.Ft RSA *
.Fo RSA_new_method
.Fa "ENGINE *engine"
.Fc
.Ft int
.Fo RSA_print
.Fa "BIO *bp"
.Fa "RSA *x"
.Fa "int offset"
.Fc
.Ft int
.Fo RSA_print_fp
.Fa "FILE *fp"
.Fa "RSA *x"
.Fa "int offset"
.Fc
.Ft int
.Fo RSA_get_ex_new_index
.Fa "long argl"
.Fa "char *argp"
.Fa "int (*new_func)()"
.Fa "int (*dup_func)()"
.Fa "void (*free_func)()"
.Fc
.Ft int
.Fo RSA_set_ex_data
.Fa "RSA *r"
.Fa "int idx"
.Fa "char *arg"
.Fc
.Ft char *
.Fo RSA_get_ex_data
.Fa "RSA *r"
.Fa "int idx"
.Fc
.Ft int
.Fo RSA_sign_ASN1_OCTET_STRING
.Fa "int dummy"
.Fa "unsigned char *m"
.Fa "unsigned int m_len"
.Fa "unsigned char *sigret"
.Fa "unsigned int *siglen"
.Fa "RSA *rsa"
.Fc
.Ft int
.Fo RSA_verify_ASN1_OCTET_STRING
.Fa "int dummy"
.Fa "unsigned char *m"
.Fa "unsigned int m_len"
.Fa "unsigned char *sigbuf"
.Fa "unsigned int siglen"
.Fa "RSA *rsa"
.Fc
.Sh DESCRIPTION
These functions implement RSA public key encryption and signatures as
defined in PKCS #1 v2.0 [RFC 2437].
.Pp
The
.Vt RSA
structure consists of several BIGNUM components.
It can contain public as well as private RSA keys:
.Bd -literal
typdef struct {
        BIGNUM *n;		// public modulus
        BIGNUM *e;		// public exponent
        BIGNUM *d;		// private exponent
        BIGNUM *p;		// secret prime factor
        BIGNUM *q;		// secret prime factor
        BIGNUM *dmp1;		// d mod (p-1)
        BIGNUM *dmq1;		// d mod (q-1)
        BIGNUM *iqmp;		// q^-1 mod p
	// ...
} RSA;
.Ed
.Pp
In public keys, the private exponent and the related secret values are
.Dv NULL .
.Pp
.Fa p ,
.Fa q ,
.Fa dmp1 ,
.Fa dmq1 ,
and
.Fa iqmp
may be
.Dv NULL
in private keys, but the RSA operations are much faster when these
values are available.
.Pp
Note that RSA keys may use non-standard
.Vt RSA_METHOD
implementations, either directly or by the use of
.Vt ENGINE
modules.
In some cases (eg. an
.Vt ENGINE
providing support for hardware-embedded keys), these
.Vt BIGNUM
values will not be used by the implementation or may be used for
alternative data storage.
For this reason, applications should generally avoid using
.Vt RSA
structure elements directly and instead use API functions to query
or modify keys.
.Sh SEE ALSO
.Xr bn 3 ,
.Xr dh 3 ,
.Xr dsa 3 ,
.Xr engine 3 ,
.Xr RSA_blinding_on 3 ,
.Xr RSA_check_key 3 ,
.Xr RSA_generate_key 3 ,
.Xr RSA_get_ex_new_index 3 ,
.Xr RSA_new 3 ,
.Xr RSA_padding_add_PKCS1_type_1 3 ,
.Xr RSA_print 3 ,
.Xr RSA_private_encrypt 3 ,
.Xr RSA_public_encrypt 3 ,
.Xr RSA_set_method 3 ,
.Xr RSA_sign 3 ,
.Xr RSA_sign_ASN1_OCTET_STRING 3 ,
.Xr RSA_size 3
.Sh STANDARDS
SSL, PKCS #1 v2.0
.Pp
RSA was covered by a US patent which expired in September 2000.