2016-05-17 18:51:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2002-12-08 05:24:31 +00:00
|
|
|
*
|
2018-12-06 12:54:02 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 18:51:34 +00:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2002-12-08 05:24:31 +00:00
|
|
|
*/
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* NB: This file contains deprecated functions (compatibility wrappers to the
|
|
|
|
* "new" versions).
|
|
|
|
*/
|
2002-12-08 05:24:31 +00:00
|
|
|
|
2016-01-05 04:00:33 +00:00
|
|
|
#include <openssl/opensslconf.h>
|
2018-11-29 23:05:03 +00:00
|
|
|
#if OPENSSL_API_0_9_8
|
2016-01-31 18:08:23 +00:00
|
|
|
NON_EMPTY_TRANSLATION_UNIT
|
2003-10-29 04:06:50 +00:00
|
|
|
|
2004-04-26 15:31:35 +00:00
|
|
|
#else
|
|
|
|
|
2016-01-31 18:08:23 +00:00
|
|
|
# include <stdio.h>
|
|
|
|
# include <time.h>
|
|
|
|
# include "internal/cryptlib.h"
|
|
|
|
# include <openssl/bn.h>
|
|
|
|
# include <openssl/rsa.h>
|
|
|
|
|
2002-12-08 05:24:31 +00:00
|
|
|
RSA *RSA_generate_key(int bits, unsigned long e_value,
|
2015-01-22 03:40:55 +00:00
|
|
|
void (*callback) (int, int, void *), void *cb_arg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BN_GENCB *cb = BN_GENCB_new();
|
|
|
|
RSA *rsa = RSA_new();
|
|
|
|
BIGNUM *e = BN_new();
|
2002-12-08 05:24:31 +00:00
|
|
|
|
2015-10-30 11:12:26 +00:00
|
|
|
if (cb == NULL || rsa == NULL || e == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
2004-04-26 15:31:35 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* The problem is when building with 8, 16, or 32 BN_ULONG, unsigned long
|
|
|
|
* can be larger
|
|
|
|
*/
|
|
|
|
for (i = 0; i < (int)sizeof(unsigned long) * 8; i++) {
|
|
|
|
if (e_value & (1UL << i))
|
|
|
|
if (BN_set_bit(e, i) == 0)
|
|
|
|
goto err;
|
|
|
|
}
|
2002-12-08 05:24:31 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
BN_GENCB_set_old(cb, callback, cb_arg);
|
2002-12-08 05:24:31 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (RSA_generate_key_ex(rsa, bits, e, cb)) {
|
|
|
|
BN_free(e);
|
|
|
|
BN_GENCB_free(cb);
|
|
|
|
return rsa;
|
|
|
|
}
|
|
|
|
err:
|
2015-05-01 01:37:06 +00:00
|
|
|
BN_free(e);
|
2015-03-24 14:17:37 +00:00
|
|
|
RSA_free(rsa);
|
2015-05-01 01:37:06 +00:00
|
|
|
BN_GENCB_free(cb);
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-10-29 04:06:50 +00:00
|
|
|
#endif
|