xref: /openbsd-src/lib/libcrypto/man/RSA_generate_key.3 (revision ab3cf6dbbb0d6598bc02e80a6c2cb70eb6ee5956)
1*ab3cf6dbSschwarze.\"	$OpenBSD: RSA_generate_key.3,v 1.13 2019/06/10 14:58:48 schwarze Exp $
27bb0f920Sschwarze.\"	OpenSSL RSA_generate_key.pod bb6c5e7f Feb 5 10:29:22 2017 -0500
38974101aSjmc.\"
4860a60ecSschwarze.\" This file was written by Ulf Moeller <ulf@openssl.org>.
5860a60ecSschwarze.\" Copyright (c) 2000, 2002, 2013 The OpenSSL Project.  All rights reserved.
6860a60ecSschwarze.\"
7860a60ecSschwarze.\" Redistribution and use in source and binary forms, with or without
8860a60ecSschwarze.\" modification, are permitted provided that the following conditions
9860a60ecSschwarze.\" are met:
10860a60ecSschwarze.\"
11860a60ecSschwarze.\" 1. Redistributions of source code must retain the above copyright
12860a60ecSschwarze.\"    notice, this list of conditions and the following disclaimer.
13860a60ecSschwarze.\"
14860a60ecSschwarze.\" 2. Redistributions in binary form must reproduce the above copyright
15860a60ecSschwarze.\"    notice, this list of conditions and the following disclaimer in
16860a60ecSschwarze.\"    the documentation and/or other materials provided with the
17860a60ecSschwarze.\"    distribution.
18860a60ecSschwarze.\"
19860a60ecSschwarze.\" 3. All advertising materials mentioning features or use of this
20860a60ecSschwarze.\"    software must display the following acknowledgment:
21860a60ecSschwarze.\"    "This product includes software developed by the OpenSSL Project
22860a60ecSschwarze.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23860a60ecSschwarze.\"
24860a60ecSschwarze.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25860a60ecSschwarze.\"    endorse or promote products derived from this software without
26860a60ecSschwarze.\"    prior written permission. For written permission, please contact
27860a60ecSschwarze.\"    openssl-core@openssl.org.
28860a60ecSschwarze.\"
29860a60ecSschwarze.\" 5. Products derived from this software may not be called "OpenSSL"
30860a60ecSschwarze.\"    nor may "OpenSSL" appear in their names without prior written
31860a60ecSschwarze.\"    permission of the OpenSSL Project.
32860a60ecSschwarze.\"
33860a60ecSschwarze.\" 6. Redistributions of any form whatsoever must retain the following
34860a60ecSschwarze.\"    acknowledgment:
35860a60ecSschwarze.\"    "This product includes software developed by the OpenSSL Project
36860a60ecSschwarze.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37860a60ecSschwarze.\"
38860a60ecSschwarze.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39860a60ecSschwarze.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40860a60ecSschwarze.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41860a60ecSschwarze.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42860a60ecSschwarze.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43860a60ecSschwarze.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44860a60ecSschwarze.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45860a60ecSschwarze.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46860a60ecSschwarze.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47860a60ecSschwarze.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48860a60ecSschwarze.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49860a60ecSschwarze.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50860a60ecSschwarze.\"
51*ab3cf6dbSschwarze.Dd $Mdocdate: June 10 2019 $
5229ab75b0Sschwarze.Dt RSA_GENERATE_KEY 3
5329ab75b0Sschwarze.Os
5429ab75b0Sschwarze.Sh NAME
5529ab75b0Sschwarze.Nm RSA_generate_key_ex ,
5629ab75b0Sschwarze.Nm RSA_generate_key
5729ab75b0Sschwarze.Nd generate RSA key pair
5829ab75b0Sschwarze.Sh SYNOPSIS
5929ab75b0Sschwarze.In openssl/rsa.h
6029ab75b0Sschwarze.Ft int
6129ab75b0Sschwarze.Fo RSA_generate_key_ex
6229ab75b0Sschwarze.Fa "RSA *rsa"
6329ab75b0Sschwarze.Fa "int bits"
6429ab75b0Sschwarze.Fa "BIGNUM *e"
6529ab75b0Sschwarze.Fa "BN_GENCB *cb"
6629ab75b0Sschwarze.Fc
6729ab75b0Sschwarze.Pp
6829ab75b0SschwarzeDeprecated:
6929ab75b0Sschwarze.Pp
7029ab75b0Sschwarze.Ft RSA *
7129ab75b0Sschwarze.Fo RSA_generate_key
7229ab75b0Sschwarze.Fa "int num"
7329ab75b0Sschwarze.Fa "unsigned long e"
7429ab75b0Sschwarze.Fa "void (*callback)(int, int, void *)"
7529ab75b0Sschwarze.Fa "void *cb_arg"
7629ab75b0Sschwarze.Fc
7729ab75b0Sschwarze.Sh DESCRIPTION
7829ab75b0Sschwarze.Fn RSA_generate_key_ex
7929ab75b0Sschwarzegenerates a key pair and stores it in
8029ab75b0Sschwarze.Fa rsa .
8129ab75b0Sschwarze.Pp
8229ab75b0SschwarzeThe modulus size will be of length
8329ab75b0Sschwarze.Fa bits ,
8429ab75b0Sschwarzeand the public exponent will be
8529ab75b0Sschwarze.Fa e .
8629ab75b0SschwarzeKey sizes with
8729ab75b0Sschwarze.Fa num
8829ab75b0Sschwarze< 1024 should be considered insecure.
8929ab75b0SschwarzeThe exponent is an odd number, typically 3, 17 or 65537.
9029ab75b0Sschwarze.Pp
9129ab75b0SschwarzeA callback function may be used to provide feedback about the progress
9229ab75b0Sschwarzeof the key generation.
9329ab75b0SschwarzeIf
9429ab75b0Sschwarze.Fa cb
9529ab75b0Sschwarzeis not
9629ab75b0Sschwarze.Dv NULL ,
9729ab75b0Sschwarzeit will be called as follows using the
9829ab75b0Sschwarze.Xr BN_GENCB_call 3
9929ab75b0Sschwarzefunction:
10029ab75b0Sschwarze.Bl -bullet
10129ab75b0Sschwarze.It
10229ab75b0SschwarzeWhile a random prime number is generated, it is called as described in
10329ab75b0Sschwarze.Xr BN_generate_prime 3 .
10429ab75b0Sschwarze.It
10529ab75b0SschwarzeWhen the
10629ab75b0Sschwarze.Fa n Ns -th
10729ab75b0Sschwarzerandomly generated prime is rejected as not suitable for
10829ab75b0Sschwarzethe key,
10929ab75b0Sschwarze.Fn BN_GENCB_call cb 2 n
11029ab75b0Sschwarzeis called.
11129ab75b0Sschwarze.It
11229ab75b0SschwarzeWhen a random p has been found with p-1 relatively prime to
11329ab75b0Sschwarze.Fa e ,
11429ab75b0Sschwarzeit is called as
11529ab75b0Sschwarze.Fn BN_GENCB_call cb 3 0 .
11629ab75b0Sschwarze.El
11729ab75b0Sschwarze.Pp
11829ab75b0SschwarzeThe process is then repeated for prime q with
11929ab75b0Sschwarze.Fn BN_GENCB_call cb 3 1 .
12029ab75b0Sschwarze.Pp
12129ab75b0Sschwarze.Fn RSA_generate_key
12229ab75b0Sschwarzeis deprecated.
12329ab75b0SschwarzeNew applications should use
12429ab75b0Sschwarze.Fn RSA_generate_key_ex
12529ab75b0Sschwarzeinstead.
12629ab75b0Sschwarze.Fn RSA_generate_key
127d9480f44Sschwarzeworks in the same way as
12829ab75b0Sschwarze.Fn RSA_generate_key_ex
12929ab75b0Sschwarzeexcept it uses "old style" call backs.
13029ab75b0SschwarzeSee
13129ab75b0Sschwarze.Xr BN_generate_prime 3
13229ab75b0Sschwarzefor further details.
1338974101aSjmc.Sh RETURN VALUES
1347bb0f920Sschwarze.Fn RSA_generate_key_ex
1357bb0f920Sschwarzereturns 1 on success or 0 on error.
13629ab75b0Sschwarze.Fn RSA_generate_key
1377bb0f920Sschwarzereturns the key on success or
1387bb0f920Sschwarze.Dv NULL
1397bb0f920Sschwarzeon error.
14029ab75b0Sschwarze.Pp
14129ab75b0SschwarzeThe error codes can be obtained by
14229ab75b0Sschwarze.Xr ERR_get_error 3 .
14329ab75b0Sschwarze.Sh SEE ALSO
14429ab75b0Sschwarze.Xr BN_generate_prime 3 ,
1456f64bd5eSschwarze.Xr RSA_get0_key 3 ,
14699647b63Sschwarze.Xr RSA_meth_set_keygen 3 ,
14778bb7a80Sschwarze.Xr RSA_new 3
14829ab75b0Sschwarze.Sh HISTORY
14947ef50e0Sschwarze.Fn RSA_generate_key
15010e00d17Sschwarzeappeared in SSLeay 0.4 or earlier and had its
15129ab75b0Sschwarze.Fa cb_arg
1526b430279Sschwarzeargument added in SSLeay 0.9.0.
1536b430279SschwarzeIt has been available since
1546b430279Sschwarze.Ox 2.4 .
1552c07bb3bSschwarze.Pp
1562c07bb3bSschwarze.Fn RSA_generate_key_ex
1572c07bb3bSschwarzefirst appeared in OpenSSL 0.9.8 and has been available since
1582c07bb3bSschwarze.Ox 4.5 .
15929ab75b0Sschwarze.Sh BUGS
16029ab75b0Sschwarze.Fn BN_GENCB_call cb 2 x
16129ab75b0Sschwarzeis used with two different meanings.
16229ab75b0Sschwarze.Pp
16329ab75b0Sschwarze.Fn RSA_generate_key
16429ab75b0Sschwarzegoes into an infinite loop for illegal input values.
165