|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit Service |
084de1 |
*
|
|
Packit Service |
084de1 |
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit Service |
084de1 |
* this file except in compliance with the License. You can obtain a copy
|
|
Packit Service |
084de1 |
* in the file LICENSE in the source distribution or at
|
|
Packit Service |
084de1 |
* https://www.openssl.org/source/license.html
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* NB: This file contains deprecated functions (compatibility wrappers to the
|
|
Packit Service |
084de1 |
* "new" versions).
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include <openssl/opensslconf.h>
|
|
Packit Service |
084de1 |
#if OPENSSL_API_COMPAT >= 0x00908000L
|
|
Packit Service |
084de1 |
NON_EMPTY_TRANSLATION_UNIT
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#else
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
# include <stdio.h>
|
|
Packit Service |
084de1 |
# include <time.h>
|
|
Packit Service |
084de1 |
# include "internal/cryptlib.h"
|
|
Packit Service |
084de1 |
# include <openssl/bn.h>
|
|
Packit Service |
084de1 |
# include <openssl/rsa.h>
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
RSA *RSA_generate_key(int bits, unsigned long e_value,
|
|
Packit Service |
084de1 |
void (*callback) (int, int, void *), void *cb_arg)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
int i;
|
|
Packit Service |
084de1 |
BN_GENCB *cb = BN_GENCB_new();
|
|
Packit Service |
084de1 |
RSA *rsa = RSA_new();
|
|
Packit Service |
084de1 |
BIGNUM *e = BN_new();
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (cb == NULL || rsa == NULL || e == NULL)
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* The problem is when building with 8, 16, or 32 BN_ULONG, unsigned long
|
|
Packit Service |
084de1 |
* can be larger
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
for (i = 0; i < (int)sizeof(unsigned long) * 8; i++) {
|
|
Packit Service |
084de1 |
if (e_value & (1UL << i))
|
|
Packit Service |
084de1 |
if (BN_set_bit(e, i) == 0)
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
BN_GENCB_set_old(cb, callback, cb_arg);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (RSA_generate_key_ex(rsa, bits, e, cb)) {
|
|
Packit Service |
084de1 |
BN_free(e);
|
|
Packit Service |
084de1 |
BN_GENCB_free(cb);
|
|
Packit Service |
084de1 |
return rsa;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
err:
|
|
Packit Service |
084de1 |
BN_free(e);
|
|
Packit Service |
084de1 |
RSA_free(rsa);
|
|
Packit Service |
084de1 |
BN_GENCB_free(cb);
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
#endif
|