update libressl to 2.8.2
[unleashed.git] / lib / libcrypto / man / RSA_new.3
blob0b6bcf9740743b1f673c5b012ea6c2b546cc93c8
1 .\"     $OpenBSD: RSA_new.3,v 1.10 2018/04/18 01:11:45 schwarze Exp $
2 .\"     OpenSSL doc/man3/RSA_new.pod 99d63d46 Oct 26 13:56:48 2016 -0400
3 .\"     OpenSSL doc/crypto/rsa.pod 35d2e327 Jun 3 16:19:49 2016 -0400
4 .\"
5 .\" This file was written by Ulf Moeller <ulf@openssl.org>.
6 .\" Copyright (c) 2000, 2002, 2016 The OpenSSL Project.  All rights reserved.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\"
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\"    notice, this list of conditions and the following disclaimer.
14 .\"
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\"    notice, this list of conditions and the following disclaimer in
17 .\"    the documentation and/or other materials provided with the
18 .\"    distribution.
19 .\"
20 .\" 3. All advertising materials mentioning features or use of this
21 .\"    software must display the following acknowledgment:
22 .\"    "This product includes software developed by the OpenSSL Project
23 .\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 .\"
25 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 .\"    endorse or promote products derived from this software without
27 .\"    prior written permission. For written permission, please contact
28 .\"    openssl-core@openssl.org.
29 .\"
30 .\" 5. Products derived from this software may not be called "OpenSSL"
31 .\"    nor may "OpenSSL" appear in their names without prior written
32 .\"    permission of the OpenSSL Project.
33 .\"
34 .\" 6. Redistributions of any form whatsoever must retain the following
35 .\"    acknowledgment:
36 .\"    "This product includes software developed by the OpenSSL Project
37 .\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 .\"
39 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
51 .\"
52 .Dd $Mdocdate: April 18 2018 $
53 .Dt RSA_NEW 3
54 .Os
55 .Sh NAME
56 .Nm RSA_new ,
57 .Nm RSA_up_ref ,
58 .Nm RSA_free
59 .Nd allocate and free RSA objects
60 .Sh SYNOPSIS
61 .In openssl/rsa.h
62 .Ft RSA *
63 .Fn RSA_new void
64 .Ft int
65 .Fo RSA_up_ref
66 .Fa "RSA *rsa"
67 .Fc
68 .Ft void
69 .Fo RSA_free
70 .Fa "RSA *rsa"
71 .Fc
72 .Sh DESCRIPTION
73 The RSA functions implement RSA public key encryption and signatures
74 as defined in PKCS #1 v2.0 (RFC 2437).
75 .Pp
76 .Fn RSA_new
77 allocates and initializes an
78 .Vt RSA
79 structure, setting the reference count to 1.
80 It is equivalent to calling
81 .Xr RSA_new_method 3
82 with a
83 .Dv NULL
84 argument.
85 .Pp
86 .Fn RSA_up_ref
87 increments the reference count by 1.
88 .Pp
89 .Fn RSA_free
90 decrements the reference count by 1.
91 If it reaches 0, it frees the
92 .Vt RSA
93 structure and its components.
94 The key is erased before the memory is returned to the system.
96 .Fa rsa
97 is a
98 .Dv NULL
99 pointer, no action occurs.
102 .Vt RSA
103 structure consists of several
104 .Vt BIGNUM
105 components.
106 It can contain public as well as private RSA keys:
107 .Bd -literal
108 typedef struct {
109         BIGNUM *n;              // public modulus
110         BIGNUM *e;              // public exponent
111         BIGNUM *d;              // private exponent
112         BIGNUM *p;              // secret prime factor
113         BIGNUM *q;              // secret prime factor
114         BIGNUM *dmp1;           // d mod (p-1)
115         BIGNUM *dmq1;           // d mod (q-1)
116         BIGNUM *iqmp;           // q^-1 mod p
117         // ...
118 } RSA;
121 In public keys, the private exponent
122 .Fa d
123 and the related secret values
124 .Fa p , q , dmp1 , dmp2 ,
126 .Fa iqmp
128 .Dv NULL .
130 .Fa p ,
131 .Fa q ,
132 .Fa dmp1 ,
133 .Fa dmq1 ,
135 .Fa iqmp
136 may be
137 .Dv NULL
138 in private keys, but the RSA operations are much faster when these
139 values are available.
141 Note that RSA keys may use non-standard
142 .Vt RSA_METHOD
143 implementations, either directly or by the use of
144 .Vt ENGINE
145 modules.
146 In some cases (e.g. an
147 .Vt ENGINE
148 providing support for hardware-embedded keys), these
149 .Vt BIGNUM
150 values will not be used by the implementation or may be used for
151 alternative data storage.
152 For this reason, applications should generally avoid using
153 .Vt RSA
154 structure elements directly and instead use API functions to query
155 or modify keys.
156 .Sh RETURN VALUES
157 If the allocation fails,
158 .Fn RSA_new
159 returns
160 .Dv NULL
161 and sets an error code that can be obtained by
162 .Xr ERR_get_error 3 .
163 Otherwise it returns a pointer to the newly allocated structure.
165 .Fn RSA_up_ref
166 returns 1 for success or 0 for failure.
167 .Sh SEE ALSO
168 .Xr BN_new 3 ,
169 .Xr d2i_RSAPublicKey 3 ,
170 .Xr DH_new 3 ,
171 .Xr DSA_new 3 ,
172 .Xr ERR_get_error 3 ,
173 .Xr EVP_PKEY_set1_RSA 3 ,
174 .Xr RSA_blinding_on 3 ,
175 .Xr RSA_check_key 3 ,
176 .Xr RSA_generate_key 3 ,
177 .Xr RSA_get0_key 3 ,
178 .Xr RSA_get_ex_new_index 3 ,
179 .Xr RSA_meth_new 3 ,
180 .Xr RSA_padding_add_PKCS1_type_1 3 ,
181 .Xr RSA_print 3 ,
182 .Xr RSA_private_encrypt 3 ,
183 .Xr RSA_public_encrypt 3 ,
184 .Xr RSA_set_method 3 ,
185 .Xr RSA_sign 3 ,
186 .Xr RSA_sign_ASN1_OCTET_STRING 3 ,
187 .Xr RSA_size 3
188 .Sh STANDARDS
189 SSL, PKCS #1 v2.0
191 RSA was covered by a US patent which expired in September 2000.
192 .Sh HISTORY
193 .Fn RSA_new
195 .Fn RSA_free
196 appeared in SSLeay 0.4 or earlier and have been available since
197 .Ox 2.4 .
199 .Fn RSA_up_ref
200 first appeared in OpenSSL 0.9.7 and has been available since
201 .Ox 3.2 .