import libcrypto (LibreSSL 2.5.2)
[unleashed.git] / lib / libcrypto / man / RSA_new.3
blob9e43f03f1d0d22d91ff1c1b088b76c2b917c2646
1 .\"     $OpenBSD: RSA_new.3,v 1.4 2016/12/11 12:52:28 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: December 11 2016 $
53 .Dt RSA_NEW 3
54 .Os
55 .Sh NAME
56 .Nm RSA_new ,
57 .Nm RSA_free
58 .Nd allocate and free RSA objects
59 .Sh SYNOPSIS
60 .In openssl/rsa.h
61 .Ft RSA *
62 .Fn RSA_new void
63 .Ft void
64 .Fo RSA_free
65 .Fa "RSA *rsa"
66 .Fc
67 .Sh DESCRIPTION
68 The RSA functions implement RSA public key encryption and signatures
69 as defined in PKCS #1 v2.0 (RFC 2437).
70 .Pp
71 .Fn RSA_new
72 allocates and initializes an
73 .Vt RSA
74 structure.
75 It is equivalent to calling
76 .Fn RSA_new_method NULL .
77 .Pp
78 .Fn RSA_free
79 frees the
80 .Vt RSA
81 structure and its components.
82 The key is erased before the memory is returned to the system.
84 .Fa rsa
85 is a
86 .Dv NULL
87 pointer, no action occurs.
88 .Pp
89 The
90 .Vt RSA
91 structure consists of several
92 .Vt BIGNUM
93 components.
94 It can contain public as well as private RSA keys:
95 .Bd -literal
96 typdef struct {
97         BIGNUM *n;              // public modulus
98         BIGNUM *e;              // public exponent
99         BIGNUM *d;              // private exponent
100         BIGNUM *p;              // secret prime factor
101         BIGNUM *q;              // secret prime factor
102         BIGNUM *dmp1;           // d mod (p-1)
103         BIGNUM *dmq1;           // d mod (q-1)
104         BIGNUM *iqmp;           // q^-1 mod p
105         // ...
106 } RSA;
109 In public keys, the private exponent
110 .Fa d
111 and the related secret values
112 .Fa p , q , dmp1 , dmp2 ,
114 .Fa iqmp
116 .Dv NULL .
118 .Fa p ,
119 .Fa q ,
120 .Fa dmp1 ,
121 .Fa dmq1 ,
123 .Fa iqmp
124 may be
125 .Dv NULL
126 in private keys, but the RSA operations are much faster when these
127 values are available.
129 Note that RSA keys may use non-standard
130 .Vt RSA_METHOD
131 implementations, either directly or by the use of
132 .Vt ENGINE
133 modules.
134 In some cases (e.g. an
135 .Vt ENGINE
136 providing support for hardware-embedded keys), these
137 .Vt BIGNUM
138 values will not be used by the implementation or may be used for
139 alternative data storage.
140 For this reason, applications should generally avoid using
141 .Vt RSA
142 structure elements directly and instead use API functions to query
143 or modify keys.
144 .Sh RETURN VALUES
145 If the allocation fails,
146 .Fn RSA_new
147 returns
148 .Dv NULL
149 and sets an error code that can be obtained by
150 .Xr ERR_get_error 3 .
151 Otherwise it returns a pointer to the newly allocated structure.
152 .Sh SEE ALSO
153 .Xr BN_new 3 ,
154 .Xr d2i_RSAPublicKey 3 ,
155 .Xr DH_new 3 ,
156 .Xr DSA_new 3 ,
157 .Xr engine 3 ,
158 .Xr ERR_get_error 3 ,
159 .Xr EVP_PKEY_set1_RSA 3 ,
160 .Xr RSA_blinding_on 3 ,
161 .Xr RSA_check_key 3 ,
162 .Xr RSA_generate_key 3 ,
163 .Xr RSA_get_ex_new_index 3 ,
164 .Xr RSA_padding_add_PKCS1_type_1 3 ,
165 .Xr RSA_print 3 ,
166 .Xr RSA_private_encrypt 3 ,
167 .Xr RSA_public_encrypt 3 ,
168 .Xr RSA_set_method 3 ,
169 .Xr RSA_sign 3 ,
170 .Xr RSA_sign_ASN1_OCTET_STRING 3 ,
171 .Xr RSA_size 3
172 .Sh STANDARDS
173 SSL, PKCS #1 v2.0
175 RSA was covered by a US patent which expired in September 2000.
176 .Sh HISTORY
177 .Fn RSA_new
179 .Fn RSA_free
180 are available in all versions of SSLeay and OpenSSL.