diff options
| author | tb <> | 2026-08-27 07:18:40 +0000 |
|---|---|---|
| committer | tb <> | 2026-08-27 07:18:40 +0000 |
| commit | c6ecafe6589675f83ca98bd5a3be89cf59281d1c (patch) | |
| tree | e55568a9525dbbe4f246296e3eda355835ab7d1c /src/lib | |
| parent | 448d7a6a510aab5c772d736a43fb5dcec9dfbd73 (diff) | |
| download | openbsd-c6ecafe6589675f83ca98bd5a3be89cf59281d1c.tar.gz openbsd-c6ecafe6589675f83ca98bd5a3be89cf59281d1c.tar.bz2 openbsd-c6ecafe6589675f83ca98bd5a3be89cf59281d1c.zip | |
rsa_eay: Replace handrolled BN_bn2binpad with the real thing
Just a tiny little bit of lipstick on this entelodont. This is simpler
and does not change behavior as BN_bn2binpad() returns -1 on failure and
num on success.
jsing points out that BN_bn2binpad() is constant time.
ok jsing kenjiro
PS: henning, you owe me a significant amount of quality beverages for
making me look at this particular tire fire (and corresponding XS files).
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_eay.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c index 65ccfc35e1..0a88c812be 100644 --- a/src/lib/libcrypto/rsa/rsa_eay.c +++ b/src/lib/libcrypto/rsa/rsa_eay.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: rsa_eay.c,v 1.66 2025/05/10 05:54:38 tb Exp $ */ | 1 | /* $OpenBSD: rsa_eay.c,v 1.67 2026/08/27 07:18:40 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 | * |
| @@ -126,7 +126,7 @@ rsa_public_encrypt(int flen, const unsigned char *from, unsigned char *to, | |||
| 126 | RSA *rsa, int padding) | 126 | RSA *rsa, int padding) |
| 127 | { | 127 | { |
| 128 | BIGNUM *f, *ret; | 128 | BIGNUM *f, *ret; |
| 129 | int i, j, k, num = 0, r = -1; | 129 | int i, num = 0, r = -1; |
| 130 | unsigned char *buf = NULL; | 130 | unsigned char *buf = NULL; |
| 131 | BN_CTX *ctx = NULL; | 131 | BN_CTX *ctx = NULL; |
| 132 | 132 | ||
| @@ -200,15 +200,9 @@ rsa_public_encrypt(int flen, const unsigned char *from, unsigned char *to, | |||
| 200 | rsa->_method_mod_n)) | 200 | rsa->_method_mod_n)) |
| 201 | goto err; | 201 | goto err; |
| 202 | 202 | ||
| 203 | /* put in leading 0 bytes if the number is less than the | 203 | r = BN_bn2binpad(ret, to, num); |
| 204 | * length of the modulus */ | ||
| 205 | j = BN_num_bytes(ret); | ||
| 206 | i = BN_bn2bin(ret, &(to[num - j])); | ||
| 207 | for (k = 0; k < num - i; k++) | ||
| 208 | to[k] = 0; | ||
| 209 | 204 | ||
| 210 | r = num; | 205 | err: |
| 211 | err: | ||
| 212 | if (ctx != NULL) { | 206 | if (ctx != NULL) { |
| 213 | BN_CTX_end(ctx); | 207 | BN_CTX_end(ctx); |
| 214 | BN_CTX_free(ctx); | 208 | BN_CTX_free(ctx); |
| @@ -306,7 +300,7 @@ rsa_private_encrypt(int flen, const unsigned char *from, unsigned char *to, | |||
| 306 | RSA *rsa, int padding) | 300 | RSA *rsa, int padding) |
| 307 | { | 301 | { |
| 308 | BIGNUM *f, *ret, *res; | 302 | BIGNUM *f, *ret, *res; |
| 309 | int i, j, k, num = 0, r = -1; | 303 | int i, num = 0, r = -1; |
| 310 | unsigned char *buf = NULL; | 304 | unsigned char *buf = NULL; |
| 311 | BN_CTX *ctx = NULL; | 305 | BN_CTX *ctx = NULL; |
| 312 | int local_blinding = 0; | 306 | int local_blinding = 0; |
| @@ -412,15 +406,9 @@ rsa_private_encrypt(int flen, const unsigned char *from, unsigned char *to, | |||
| 412 | } else | 406 | } else |
| 413 | res = ret; | 407 | res = ret; |
| 414 | 408 | ||
| 415 | /* put in leading 0 bytes if the number is less than the | 409 | r = BN_bn2binpad(res, to, num); |
| 416 | * length of the modulus */ | ||
| 417 | j = BN_num_bytes(res); | ||
| 418 | i = BN_bn2bin(res, &(to[num - j])); | ||
| 419 | for (k = 0; k < num - i; k++) | ||
| 420 | to[k] = 0; | ||
| 421 | 410 | ||
| 422 | r = num; | 411 | err: |
| 423 | err: | ||
| 424 | if (ctx != NULL) { | 412 | if (ctx != NULL) { |
| 425 | BN_CTX_end(ctx); | 413 | BN_CTX_end(ctx); |
| 426 | BN_CTX_free(ctx); | 414 | BN_CTX_free(ctx); |
