summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_lib.c
diff options
context:
space:
mode:
authorjsing <>2022-11-24 01:30:01 +0000
committerjsing <>2022-11-24 01:30:01 +0000
commit8a7c8abfd4f8805f2a5101e89356e9411d908a0c (patch)
treefaea38f1c86dae9f6d4b143b2aa9f7752ecd0a34 /src/lib/libcrypto/bn/bn_lib.c
parent095ccaedd0631462c52a1a2d9aa19b35c3e45b12 (diff)
downloadopenbsd-8a7c8abfd4f8805f2a5101e89356e9411d908a0c.tar.gz
openbsd-8a7c8abfd4f8805f2a5101e89356e9411d908a0c.tar.bz2
openbsd-8a7c8abfd4f8805f2a5101e89356e9411d908a0c.zip
Change bn_expand()/bn_wexpand() to indicate failure/success via 0/1.
Currently bn_expand()/bn_wexpand() return a BIGNUM *, however none of the callers use this (and many already treat it as a true/false value). Change these functions to return 0 on failure and 1 on success, revising callers that test against NULL in the process. ok tb@
Diffstat (limited to 'src/lib/libcrypto/bn/bn_lib.c')
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index 1c079b004a..e67abf90b1 100644
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ b/src/lib/libcrypto/bn/bn_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_lib.c,v 1.60 2022/11/23 03:10:10 jsing Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.61 2022/11/24 01:30:01 jsing 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 *
@@ -334,15 +334,15 @@ bn_expand_internal(const BIGNUM *b, int words)
334 * It is mostly used by the various BIGNUM routines. If there is an error, 334 * It is mostly used by the various BIGNUM routines. If there is an error,
335 * NULL is returned. If not, 'b' is returned. */ 335 * NULL is returned. If not, 'b' is returned. */
336 336
337static BIGNUM * 337static int
338bn_expand2(BIGNUM *b, int words) 338bn_expand2(BIGNUM *b, int words)
339{ 339{
340 bn_check_top(b); 340 bn_check_top(b);
341 341
342 if (words > b->dmax) { 342 if (words > b->dmax) {
343 BN_ULONG *a = bn_expand_internal(b, words); 343 BN_ULONG *a = bn_expand_internal(b, words);
344 if (!a) 344 if (a == NULL)
345 return NULL; 345 return 0;
346 if (b->d) 346 if (b->d)
347 freezero(b->d, b->dmax * sizeof(b->d[0])); 347 freezero(b->d, b->dmax * sizeof(b->d[0]));
348 b->d = a; 348 b->d = a;
@@ -371,32 +371,32 @@ bn_expand2(BIGNUM *b, int words)
371 } 371 }
372#endif 372#endif
373 bn_check_top(b); 373 bn_check_top(b);
374 return b; 374 return 1;
375} 375}
376 376
377BIGNUM * 377int
378bn_expand(BIGNUM *a, int bits) 378bn_expand(BIGNUM *a, int bits)
379{ 379{
380 if (bits < 0) 380 if (bits < 0)
381 return (NULL); 381 return 0;
382 382
383 if (bits > (INT_MAX - BN_BITS2 + 1)) 383 if (bits > (INT_MAX - BN_BITS2 + 1))
384 return (NULL); 384 return 0;
385 385
386 if (((bits + BN_BITS2 - 1) / BN_BITS2) <= a->dmax) 386 if (((bits + BN_BITS2 - 1) / BN_BITS2) <= a->dmax)
387 return (a); 387 return 1;
388 388
389 return bn_expand2(a, (bits + BN_BITS2 - 1) / BN_BITS2); 389 return bn_expand2(a, (bits + BN_BITS2 - 1) / BN_BITS2);
390} 390}
391 391
392BIGNUM * 392int
393bn_wexpand(BIGNUM *a, int words) 393bn_wexpand(BIGNUM *a, int words)
394{ 394{
395 if (words < 0) 395 if (words < 0)
396 return NULL; 396 return 0;
397 397
398 if (words <= a->dmax) 398 if (words <= a->dmax)
399 return a; 399 return 1;
400 400
401 return bn_expand2(a, words); 401 return bn_expand2(a, words);
402} 402}
@@ -432,7 +432,7 @@ BN_copy(BIGNUM *a, const BIGNUM *b)
432 432
433 if (a == b) 433 if (a == b)
434 return (a); 434 return (a);
435 if (bn_wexpand(a, b->top) == NULL) 435 if (!bn_wexpand(a, b->top))
436 return (NULL); 436 return (NULL);
437 437
438#if 1 438#if 1
@@ -518,7 +518,7 @@ int
518BN_set_word(BIGNUM *a, BN_ULONG w) 518BN_set_word(BIGNUM *a, BN_ULONG w)
519{ 519{
520 bn_check_top(a); 520 bn_check_top(a);
521 if (bn_wexpand(a, 1) == NULL) 521 if (!bn_wexpand(a, 1))
522 return (0); 522 return (0);
523 a->neg = 0; 523 a->neg = 0;
524 a->d[0] = w; 524 a->d[0] = w;
@@ -550,7 +550,7 @@ BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
550 } 550 }
551 i = ((n - 1) / BN_BYTES) + 1; 551 i = ((n - 1) / BN_BYTES) + 1;
552 m = ((n - 1) % (BN_BYTES)); 552 m = ((n - 1) % (BN_BYTES));
553 if (bn_wexpand(ret, (int)i) == NULL) { 553 if (!bn_wexpand(ret, (int)i)) {
554 BN_free(bn); 554 BN_free(bn);
555 return NULL; 555 return NULL;
556 } 556 }
@@ -673,7 +673,7 @@ BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret)
673 673
674 i = ((n - 1) / BN_BYTES) + 1; 674 i = ((n - 1) / BN_BYTES) + 1;
675 m = (n - 1) % BN_BYTES; 675 m = (n - 1) % BN_BYTES;
676 if (bn_wexpand(ret, (int)i) == NULL) { 676 if (!bn_wexpand(ret, (int)i)) {
677 BN_free(bn); 677 BN_free(bn);
678 return NULL; 678 return NULL;
679 } 679 }
@@ -791,7 +791,7 @@ BN_set_bit(BIGNUM *a, int n)
791 i = n / BN_BITS2; 791 i = n / BN_BITS2;
792 j = n % BN_BITS2; 792 j = n % BN_BITS2;
793 if (a->top <= i) { 793 if (a->top <= i) {
794 if (bn_wexpand(a, i + 1) == NULL) 794 if (!bn_wexpand(a, i + 1))
795 return (0); 795 return (0);
796 for (k = a->top; k < i + 1; k++) 796 for (k = a->top; k < i + 1; k++)
797 a->d[k] = 0; 797 a->d[k] = 0;
@@ -989,7 +989,7 @@ BN_swap_ct(BN_ULONG condition, BIGNUM *a, BIGNUM *b, size_t nwords)
989 if (nwords > INT_MAX) 989 if (nwords > INT_MAX)
990 return 0; 990 return 0;
991 words = (int)nwords; 991 words = (int)nwords;
992 if (bn_wexpand(a, words) == NULL || bn_wexpand(b, words) == NULL) 992 if (!bn_wexpand(a, words) || !bn_wexpand(b, words))
993 return 0; 993 return 0;
994 if (a->top > words || b->top > words) { 994 if (a->top > words || b->top > words) {
995 BNerror(BN_R_INVALID_LENGTH); 995 BNerror(BN_R_INVALID_LENGTH);