1.Dd $Mdocdate: November 4 2016 $
2.Dt RSA_GENERATE_KEY 3
3.Os
4.Sh NAME
5.Nm RSA_generate_key_ex ,
6.Nm RSA_generate_key
7.Nd generate RSA key pair
8.Sh SYNOPSIS
9.In openssl/rsa.h
10.Ft int
11.Fo RSA_generate_key_ex
12.Fa "RSA *rsa"
13.Fa "int bits"
14.Fa "BIGNUM *e"
15.Fa "BN_GENCB *cb"
16.Fc
17.Pp
18Deprecated:
19.Pp
20.Ft RSA *
21.Fo RSA_generate_key
22.Fa "int num"
23.Fa "unsigned long e"
24.Fa "void (*callback)(int, int, void *)"
25.Fa "void *cb_arg"
26.Fc
27.Sh DESCRIPTION
28.Fn RSA_generate_key_ex
29generates a key pair and stores it in
30.Fa rsa .
31.Pp
32The modulus size will be of length
33.Fa bits ,
34and the public exponent will be
35.Fa e .
36Key sizes with
37.Fa num
38< 1024 should be considered insecure.
39The exponent is an odd number, typically 3, 17 or 65537.
40.Pp
41A callback function may be used to provide feedback about the progress
42of the key generation.
43If
44.Fa cb
45is not
46.Dv NULL ,
47it will be called as follows using the
48.Xr BN_GENCB_call 3
49function:
50.Bl -bullet
51.It
52While a random prime number is generated, it is called as described in
53.Xr BN_generate_prime 3 .
54.It
55When the
56.Fa n Ns -th
57randomly generated prime is rejected as not suitable for
58the key,
59.Fn BN_GENCB_call cb 2 n
60is called.
61.It
62When a random p has been found with p-1 relatively prime to
63.Fa e ,
64it is called as
65.Fn BN_GENCB_call cb 3 0 .
66.El
67.Pp
68The process is then repeated for prime q with
69.Fn BN_GENCB_call cb 3 1 .
70.Pp
71.Fn RSA_generate_key
72is deprecated.
73New applications should use
74.Fn RSA_generate_key_ex
75instead.
76.Fn RSA_generate_key
77works in the same was as
78.Fn RSA_generate_key_ex
79except it uses "old style" call backs.
80See
81.Xr BN_generate_prime 3
82for further details.
83.Sh RETURN VALUE
84If key generation fails,
85.Fn RSA_generate_key
86returns
87.Dv NULL .
88.Pp
89The error codes can be obtained by
90.Xr ERR_get_error 3 .
91.Sh SEE ALSO
92.Xr BN_generate_prime 3 ,
93.Xr ERR_get_error 3 ,
94.Xr rsa 3 ,
95.Xr RSA_free 3
96.Sh HISTORY
97The
98.Fa cb_arg
99argument was added in SSLeay 0.9.0.
100.Sh BUGS
101.Fn BN_GENCB_call cb 2 x
102is used with two different meanings.
103.Pp
104.Fn RSA_generate_key
105goes into an infinite loop for illegal input values.
106