]>
Commit | Line | Data |
---|---|---|
2039c421 | 1 | /* |
33388b44 | 2 | * Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved. |
e9224c71 | 3 | * |
2a7b6f39 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
2039c421 RS |
5 | * this file except in compliance with the License. You can obtain a copy |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
e9224c71 GT |
8 | */ |
9 | ||
0f113f3e MC |
10 | /* |
11 | * NB: This file contains deprecated functions (compatibility wrappers to the | |
12 | * "new" versions). | |
13 | */ | |
e9224c71 | 14 | |
c5f87134 P |
15 | /* |
16 | * RSA low level APIs are deprecated for public use, but still ok for | |
17 | * internal use. | |
18 | */ | |
19 | #include "internal/deprecated.h" | |
20 | ||
98186eb4 | 21 | #include <openssl/opensslconf.h> |
9d473aa2 | 22 | |
705536e2 RS |
23 | #include <stdio.h> |
24 | #include <time.h> | |
25 | #include "internal/cryptlib.h" | |
26 | #include <openssl/bn.h> | |
27 | #include <openssl/rsa.h> | |
effaf4de | 28 | |
e9224c71 | 29 | RSA *RSA_generate_key(int bits, unsigned long e_value, |
0f113f3e MC |
30 | void (*callback) (int, int, void *), void *cb_arg) |
31 | { | |
32 | int i; | |
33 | BN_GENCB *cb = BN_GENCB_new(); | |
34 | RSA *rsa = RSA_new(); | |
35 | BIGNUM *e = BN_new(); | |
e9224c71 | 36 | |
90945fa3 | 37 | if (cb == NULL || rsa == NULL || e == NULL) |
0f113f3e | 38 | goto err; |
bcfea9fb | 39 | |
0f113f3e MC |
40 | /* |
41 | * The problem is when building with 8, 16, or 32 BN_ULONG, unsigned long | |
42 | * can be larger | |
43 | */ | |
44 | for (i = 0; i < (int)sizeof(unsigned long) * 8; i++) { | |
45 | if (e_value & (1UL << i)) | |
46 | if (BN_set_bit(e, i) == 0) | |
47 | goto err; | |
48 | } | |
e9224c71 | 49 | |
0f113f3e | 50 | BN_GENCB_set_old(cb, callback, cb_arg); |
e9224c71 | 51 | |
0f113f3e MC |
52 | if (RSA_generate_key_ex(rsa, bits, e, cb)) { |
53 | BN_free(e); | |
54 | BN_GENCB_free(cb); | |
55 | return rsa; | |
56 | } | |
57 | err: | |
23a1d5e9 | 58 | BN_free(e); |
d6407083 | 59 | RSA_free(rsa); |
23a1d5e9 | 60 | BN_GENCB_free(cb); |
0f113f3e MC |
61 | return 0; |
62 | } |