summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_gf2m.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_gf2m.c')
-rw-r--r--src/lib/libcrypto/bn/bn_gf2m.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/lib/libcrypto/bn/bn_gf2m.c b/src/lib/libcrypto/bn/bn_gf2m.c
index 1fd7105a31..b9e3ba8566 100644
--- a/src/lib/libcrypto/bn/bn_gf2m.c
+++ b/src/lib/libcrypto/bn/bn_gf2m.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_gf2m.c,v 1.24 2022/11/20 22:23:43 schwarze Exp $ */ 1/* $OpenBSD: bn_gf2m.c,v 1.25 2022/11/20 23:35:00 schwarze Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -464,17 +464,23 @@ int
464BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p) 464BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p)
465{ 465{
466 int ret = 0; 466 int ret = 0;
467 int arr[6]; 467 const int max = BN_num_bits(p) + 1;
468 int *arr = NULL;
468 469
469 bn_check_top(a); 470 bn_check_top(a);
470 bn_check_top(p); 471 bn_check_top(p);
471 ret = BN_GF2m_poly2arr(p, arr, sizeof(arr) / sizeof(arr[0])); 472 if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL)
472 if (!ret || ret > (int)(sizeof(arr) / sizeof(arr[0]))) { 473 goto err;
474 ret = BN_GF2m_poly2arr(p, arr, max);
475 if (!ret || ret > max) {
473 BNerror(BN_R_INVALID_LENGTH); 476 BNerror(BN_R_INVALID_LENGTH);
474 return 0; 477 goto err;
475 } 478 }
476 ret = BN_GF2m_mod_arr(r, a, arr); 479 ret = BN_GF2m_mod_arr(r, a, arr);
477 bn_check_top(r); 480 bn_check_top(r);
481
482 err:
483 free(arr);
478 return ret; 484 return ret;
479} 485}
480 486