-/* $OpenBSD: bn_gf2m.c,v 1.24 2022/11/20 22:23:43 schwarze Exp $ */
+/* $OpenBSD: bn_gf2m.c,v 1.25 2022/11/20 23:35:00 schwarze Exp $ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p)
{
int ret = 0;
- int arr[6];
+ const int max = BN_num_bits(p) + 1;
+ int *arr = NULL;
bn_check_top(a);
bn_check_top(p);
- ret = BN_GF2m_poly2arr(p, arr, sizeof(arr) / sizeof(arr[0]));
- if (!ret || ret > (int)(sizeof(arr) / sizeof(arr[0]))) {
+ if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL)
+ goto err;
+ ret = BN_GF2m_poly2arr(p, arr, max);
+ if (!ret || ret > max) {
BNerror(BN_R_INVALID_LENGTH);
- return 0;
+ goto err;
}
ret = BN_GF2m_mod_arr(r, a, arr);
bn_check_top(r);
+
+ err:
+ free(arr);
return ret;
}
-.\" $OpenBSD: BN_GF2m_add.3,v 1.3 2022/11/18 07:28:34 tb Exp $
+.\" $OpenBSD: BN_GF2m_add.3,v 1.4 2022/11/20 23:35:00 schwarze Exp $
.\"
.\" Copyright (c) 2022 Ingo Schwarze <schwarze@openbsd.org>
.\"
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: November 18 2022 $
+.Dd $Mdocdate: November 20 2022 $
.Dt BN_GF2M_ADD 3
.Os
.Sh NAME
.Fn *_arr
variant, the
.Fa "BIGNUM *p"
-argument had a value of zero, or in
-.Fn BN_GF2m_mod ,
-it contained more than five non-zero coefficients.
+argument had a value of zero.
.El
.Sh SEE ALSO
.Xr BN_add 3 ,
exponentiation algorithm A.4.1 for square roots, and\
algorithms A.4.7 and A.4.6 for the quadratic equation
.Re
-.Sh BUGS
-.Fn BN_GF2m_mod
-is arbitrarily limited to reducing polynomials containing at most five
-non-zero coefficients and returns failure if
-.Fa p
-contains six or more non-zero coefficients.