From c6877f45ec7586838425b73dc08a6537c7510481 Mon Sep 17 00:00:00 2001 From: tb Date: Thu, 13 Apr 2023 14:59:13 +0000 Subject: [PATCH] Move RSA_generate_key() from rsa_depr.c to rsa_gen.c Discussed with jsing --- lib/libcrypto/rsa/rsa_depr.c | 34 +--------------------------------- lib/libcrypto/rsa/rsa_gen.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/lib/libcrypto/rsa/rsa_depr.c b/lib/libcrypto/rsa/rsa_depr.c index 2d8d55a693a..0c3aa678746 100644 --- a/lib/libcrypto/rsa/rsa_depr.c +++ b/lib/libcrypto/rsa/rsa_depr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsa_depr.c,v 1.11 2023/04/09 19:10:23 tb Exp $ */ +/* $OpenBSD: rsa_depr.c,v 1.12 2023/04/13 14:59:13 tb Exp $ */ /* ==================================================================== * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. * @@ -66,35 +66,3 @@ #include "bn_local.h" -RSA * -RSA_generate_key(int bits, unsigned long e_value, - void (*callback)(int, int, void *), void *cb_arg) -{ - BN_GENCB cb; - int i; - RSA *rsa = RSA_new(); - BIGNUM *e = BN_new(); - - if (!rsa || !e) - goto err; - - /* 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; - } - - BN_GENCB_set_old(&cb, callback, cb_arg); - - if (RSA_generate_key_ex(rsa, bits, e, &cb)) { - BN_free(e); - return rsa; - } -err: - BN_free(e); - RSA_free(rsa); - - return 0; -} diff --git a/lib/libcrypto/rsa/rsa_gen.c b/lib/libcrypto/rsa/rsa_gen.c index d4a4d60a86e..64b70aa7b7d 100644 --- a/lib/libcrypto/rsa/rsa_gen.c +++ b/lib/libcrypto/rsa/rsa_gen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsa_gen.c,v 1.27 2023/03/27 10:22:47 tb Exp $ */ +/* $OpenBSD: rsa_gen.c,v 1.28 2023/04/13 14:59:13 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -233,3 +233,36 @@ err: return ok; } + +RSA * +RSA_generate_key(int bits, unsigned long e_value, + void (*callback)(int, int, void *), void *cb_arg) +{ + BN_GENCB cb; + int i; + RSA *rsa = RSA_new(); + BIGNUM *e = BN_new(); + + if (!rsa || !e) + goto err; + + /* 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; + } + + BN_GENCB_set_old(&cb, callback, cb_arg); + + if (RSA_generate_key_ex(rsa, bits, e, &cb)) { + BN_free(e); + return rsa; + } +err: + BN_free(e); + RSA_free(rsa); + + return 0; +} -- 2.20.1