rsa_depr.c revision 296465
159243Sobrien/* crypto/rsa/rsa_depr.c */ 259243Sobrien/* ==================================================================== 359243Sobrien * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 459243Sobrien * 559243Sobrien * Redistribution and use in source and binary forms, with or without 659243Sobrien * modification, are permitted provided that the following conditions 759243Sobrien * are met: 859243Sobrien * 959243Sobrien * 1. Redistributions of source code must retain the above copyright 1059243Sobrien * notice, this list of conditions and the following disclaimer. 1159243Sobrien * 1259243Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1359243Sobrien * notice, this list of conditions and the following disclaimer in 1459243Sobrien * the documentation and/or other materials provided with the 1559243Sobrien * distribution. 16100616Smp * 1759243Sobrien * 3. All advertising materials mentioning features or use of this 1859243Sobrien * software must display the following acknowledgment: 1959243Sobrien * "This product includes software developed by the OpenSSL Project 2059243Sobrien * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 2159243Sobrien * 2259243Sobrien * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 2359243Sobrien * endorse or promote products derived from this software without 2459243Sobrien * prior written permission. For written permission, please contact 2559243Sobrien * openssl-core@openssl.org. 2659243Sobrien * 2759243Sobrien * 5. Products derived from this software may not be called "OpenSSL" 2859243Sobrien * nor may "OpenSSL" appear in their names without prior written 2959243Sobrien * permission of the OpenSSL Project. 3059243Sobrien * 3159243Sobrien * 6. Redistributions of any form whatsoever must retain the following 3259243Sobrien * acknowledgment: 3359243Sobrien * "This product includes software developed by the OpenSSL Project 3459243Sobrien * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 3559243Sobrien * 3659243Sobrien * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 3769408Sache * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3859243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39167465Smp * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 40167465Smp * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4169408Sache * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 4259243Sobrien * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 4359243Sobrien * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4459243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4559243Sobrien * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 4659243Sobrien * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 4759243Sobrien * OF THE POSSIBILITY OF SUCH DAMAGE. 4859243Sobrien * ==================================================================== 4959243Sobrien * 5059243Sobrien * This product includes cryptographic software written by Eric Young 5159243Sobrien * (eay@cryptsoft.com). This product includes software written by Tim 5259243Sobrien * Hudson (tjh@cryptsoft.com). 5359243Sobrien * 54145479Smp */ 55145479Smp 56354195Sbrooks/* 57145479Smp * NB: This file contains deprecated functions (compatibility wrappers to the 58145479Smp * "new" versions). 59145479Smp */ 60167465Smp 6159243Sobrien#include <stdio.h> 62167465Smp#include <time.h> 63167465Smp#include "cryptlib.h" 64167465Smp#include <openssl/bn.h> 6559243Sobrien#include <openssl/rsa.h> 66167465Smp 67167465Smp#ifdef OPENSSL_NO_DEPRECATED 68167465Smp 6959243Sobrienstatic void *dummy = &dummy; 70167465Smp 71167465Smp#else 7259243Sobrien 73167465SmpRSA *RSA_generate_key(int bits, unsigned long e_value, 74167465Smp void (*callback) (int, int, void *), void *cb_arg) 7559243Sobrien{ 7659243Sobrien BN_GENCB cb; 7759243Sobrien int i; 7859243Sobrien RSA *rsa = RSA_new(); 7959243Sobrien BIGNUM *e = BN_new(); 8059243Sobrien 8159243Sobrien if (!rsa || !e) 82167465Smp goto err; 83167465Smp 84167465Smp /* 8561524Sobrien * The problem is when building with 8, 16, or 32 BN_ULONG, unsigned long 8661524Sobrien * can be larger 8761524Sobrien */ 8861524Sobrien for (i = 0; i < (int)sizeof(unsigned long) * 8; i++) { 8961524Sobrien if (e_value & (1UL << i)) 9059243Sobrien if (BN_set_bit(e, i) == 0) 9159243Sobrien goto err; 9259243Sobrien } 9359243Sobrien 9459243Sobrien BN_GENCB_set_old(&cb, callback, cb_arg); 95167465Smp 9659243Sobrien if (RSA_generate_key_ex(rsa, bits, e, &cb)) { 97167465Smp BN_free(e); 98167465Smp return rsa; 99167465Smp } 100145479Smp err: 101145479Smp if (e) 10259243Sobrien BN_free(e); 10359243Sobrien if (rsa) 10459243Sobrien RSA_free(rsa); 105167465Smp return 0; 106167465Smp} 10759243Sobrien#endif 108167465Smp