]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/rsa/rsa_depr.c
Refactor the computation of API version limits
[thirdparty/openssl.git] / crypto / rsa / rsa_depr.c
CommitLineData
2039c421
RS
1/*
2 * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
e9224c71 3 *
2039c421
RS
4 * Licensed under the OpenSSL license (the "License"). You may not use
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
98186eb4 15#include <openssl/opensslconf.h>
fcd2d5a6 16#if OPENSSL_API_0_9_8
effaf4de 17NON_EMPTY_TRANSLATION_UNIT
9d473aa2 18
bcfea9fb
GT
19#else
20
effaf4de
RS
21# include <stdio.h>
22# include <time.h>
23# include "internal/cryptlib.h"
24# include <openssl/bn.h>
25# include <openssl/rsa.h>
26
e9224c71 27RSA *RSA_generate_key(int bits, unsigned long e_value,
0f113f3e
MC
28 void (*callback) (int, int, void *), void *cb_arg)
29{
30 int i;
31 BN_GENCB *cb = BN_GENCB_new();
32 RSA *rsa = RSA_new();
33 BIGNUM *e = BN_new();
e9224c71 34
90945fa3 35 if (cb == NULL || rsa == NULL || e == NULL)
0f113f3e 36 goto err;
bcfea9fb 37
0f113f3e
MC
38 /*
39 * The problem is when building with 8, 16, or 32 BN_ULONG, unsigned long
40 * can be larger
41 */
42 for (i = 0; i < (int)sizeof(unsigned long) * 8; i++) {
43 if (e_value & (1UL << i))
44 if (BN_set_bit(e, i) == 0)
45 goto err;
46 }
e9224c71 47
0f113f3e 48 BN_GENCB_set_old(cb, callback, cb_arg);
e9224c71 49
0f113f3e
MC
50 if (RSA_generate_key_ex(rsa, bits, e, cb)) {
51 BN_free(e);
52 BN_GENCB_free(cb);
53 return rsa;
54 }
55 err:
23a1d5e9 56 BN_free(e);
d6407083 57 RSA_free(rsa);
23a1d5e9 58 BN_GENCB_free(cb);
0f113f3e
MC
59 return 0;
60}
9d473aa2 61#endif