diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_depr.c | 34 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_gen.c | 35 |
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 | ||
69 | RSA * | ||
70 | RSA_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 | } | ||
95 | err: | ||
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 | |||
237 | RSA * | ||
238 | RSA_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 | } | ||
263 | err: | ||
264 | BN_free(e); | ||
265 | RSA_free(rsa); | ||
266 | |||
267 | return 0; | ||
268 | } | ||