summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-04-13 14:59:13 +0000
committertb <>2023-04-13 14:59:13 +0000
commit15b6ca969589a3b9b2069bb0b796c42e2f146fc4 (patch)
tree4f989651344b778b6d4b5b824baf6c4cb56290d1 /src/lib
parent444a1e2335883999b57e5f9b1f505b5915c2da3d (diff)
downloadopenbsd-15b6ca969589a3b9b2069bb0b796c42e2f146fc4.tar.gz
openbsd-15b6ca969589a3b9b2069bb0b796c42e2f146fc4.tar.bz2
openbsd-15b6ca969589a3b9b2069bb0b796c42e2f146fc4.zip
Move RSA_generate_key() from rsa_depr.c to rsa_gen.c
Discussed with jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/rsa/rsa_depr.c34
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c35
2 files changed, 35 insertions, 34 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_depr.c b/src/lib/libcrypto/rsa/rsa_depr.c
index 2d8d55a693..0c3aa67874 100644
--- a/src/lib/libcrypto/rsa/rsa_depr.c
+++ b/src/lib/libcrypto/rsa/rsa_depr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_depr.c,v 1.11 2023/04/09 19:10:23 tb Exp $ */ 1/* $OpenBSD: rsa_depr.c,v 1.12 2023/04/13 14:59:13 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -66,35 +66,3 @@
66 66
67#include "bn_local.h" 67#include "bn_local.h"
68 68
69RSA *
70RSA_generate_key(int bits, unsigned long e_value,
71 void (*callback)(int, int, void *), void *cb_arg)
72{
73 BN_GENCB cb;
74 int i;
75 RSA *rsa = RSA_new();
76 BIGNUM *e = BN_new();
77
78 if (!rsa || !e)
79 goto err;
80
81 /* The problem is when building with 8, 16, or 32 BN_ULONG,
82 * unsigned long can be larger */
83 for (i = 0; i < (int)sizeof(unsigned long) * 8; i++) {
84 if (e_value & (1UL << i))
85 if (BN_set_bit(e, i) == 0)
86 goto err;
87 }
88
89 BN_GENCB_set_old(&cb, callback, cb_arg);
90
91 if (RSA_generate_key_ex(rsa, bits, e, &cb)) {
92 BN_free(e);
93 return rsa;
94 }
95err:
96 BN_free(e);
97 RSA_free(rsa);
98
99 return 0;
100}
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c
index d4a4d60a86..64b70aa7b7 100644
--- a/src/lib/libcrypto/rsa/rsa_gen.c
+++ b/src/lib/libcrypto/rsa/rsa_gen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_gen.c,v 1.27 2023/03/27 10:22:47 tb Exp $ */ 1/* $OpenBSD: rsa_gen.c,v 1.28 2023/04/13 14:59:13 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -233,3 +233,36 @@ err:
233 233
234 return ok; 234 return ok;
235} 235}
236
237RSA *
238RSA_generate_key(int bits, unsigned long e_value,
239 void (*callback)(int, int, void *), void *cb_arg)
240{
241 BN_GENCB cb;
242 int i;
243 RSA *rsa = RSA_new();
244 BIGNUM *e = BN_new();
245
246 if (!rsa || !e)
247 goto err;
248
249 /* The problem is when building with 8, 16, or 32 BN_ULONG,
250 * unsigned long can be larger */
251 for (i = 0; i < (int)sizeof(unsigned long) * 8; i++) {
252 if (e_value & (1UL << i))
253 if (BN_set_bit(e, i) == 0)
254 goto err;
255 }
256
257 BN_GENCB_set_old(&cb, callback, cb_arg);
258
259 if (RSA_generate_key_ex(rsa, bits, e, &cb)) {
260 BN_free(e);
261 return rsa;
262 }
263err:
264 BN_free(e);
265 RSA_free(rsa);
266
267 return 0;
268}