2 * Copyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
14 #include "internal/cryptlib.h"
17 #ifndef OPENSSL_NO_EC2M
20 * Maximum number of iterations before BN_GF2m_mod_solve_quad_arr should
23 # define MAX_ITERATIONS 50
25 # define SQR_nibble(w) ((((w) & 8) << 3) \
31 /* Platform-specific macros to accelerate squaring. */
32 # if defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
34 SQR_nibble((w) >> 60) << 56 | SQR_nibble((w) >> 56) << 48 | \
35 SQR_nibble((w) >> 52) << 40 | SQR_nibble((w) >> 48) << 32 | \
36 SQR_nibble((w) >> 44) << 24 | SQR_nibble((w) >> 40) << 16 | \
37 SQR_nibble((w) >> 36) << 8 | SQR_nibble((w) >> 32)
39 SQR_nibble((w) >> 28) << 56 | SQR_nibble((w) >> 24) << 48 | \
40 SQR_nibble((w) >> 20) << 40 | SQR_nibble((w) >> 16) << 32 | \
41 SQR_nibble((w) >> 12) << 24 | SQR_nibble((w) >> 8) << 16 | \
42 SQR_nibble((w) >> 4) << 8 | SQR_nibble((w) )
44 # ifdef THIRTY_TWO_BIT
46 SQR_nibble((w) >> 28) << 24 | SQR_nibble((w) >> 24) << 16 | \
47 SQR_nibble((w) >> 20) << 8 | SQR_nibble((w) >> 16)
49 SQR_nibble((w) >> 12) << 24 | SQR_nibble((w) >> 8) << 16 | \
50 SQR_nibble((w) >> 4) << 8 | SQR_nibble((w) )
53 # if !defined(OPENSSL_BN_ASM_GF2m)
55 * Product of two polynomials a, b each with degree < BN_BITS2 - 1, result is
56 * a polynomial r with degree < 2 * BN_BITS - 1 The caller MUST ensure that
57 * the variables have the right amount of space allocated.
59 # ifdef THIRTY_TWO_BIT
60 static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a,
63 register BN_ULONG h, l, s;
64 BN_ULONG tab[8], top2b = a >> 30;
65 register BN_ULONG a1, a2, a4;
67 a1 = a & (0x3FFFFFFF);
78 tab[7] = a1 ^ a2 ^ a4;
82 s = tab[b >> 3 & 0x7];
85 s = tab[b >> 6 & 0x7];
88 s = tab[b >> 9 & 0x7];
91 s = tab[b >> 12 & 0x7];
94 s = tab[b >> 15 & 0x7];
97 s = tab[b >> 18 & 0x7];
100 s = tab[b >> 21 & 0x7];
103 s = tab[b >> 24 & 0x7];
106 s = tab[b >> 27 & 0x7];
113 /* compensate for the top two bits of a */
128 # if defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
129 static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a,
132 register BN_ULONG h, l, s;
133 BN_ULONG tab[16], top3b = a >> 61;
134 register BN_ULONG a1, a2, a4, a8;
136 a1 = a & (0x1FFFFFFFFFFFFFFFULL);
148 tab[7] = a1 ^ a2 ^ a4;
152 tab[11] = a1 ^ a2 ^ a8;
154 tab[13] = a1 ^ a4 ^ a8;
155 tab[14] = a2 ^ a4 ^ a8;
156 tab[15] = a1 ^ a2 ^ a4 ^ a8;
160 s = tab[b >> 4 & 0xF];
163 s = tab[b >> 8 & 0xF];
166 s = tab[b >> 12 & 0xF];
169 s = tab[b >> 16 & 0xF];
172 s = tab[b >> 20 & 0xF];
175 s = tab[b >> 24 & 0xF];
178 s = tab[b >> 28 & 0xF];
181 s = tab[b >> 32 & 0xF];
184 s = tab[b >> 36 & 0xF];
187 s = tab[b >> 40 & 0xF];
190 s = tab[b >> 44 & 0xF];
193 s = tab[b >> 48 & 0xF];
196 s = tab[b >> 52 & 0xF];
199 s = tab[b >> 56 & 0xF];
206 /* compensate for the top three bits of a */
227 * Product of two polynomials a, b each with degree < 2 * BN_BITS2 - 1,
228 * result is a polynomial r with degree < 4 * BN_BITS2 - 1 The caller MUST
229 * ensure that the variables have the right amount of space allocated.
231 static void bn_GF2m_mul_2x2(BN_ULONG *r, const BN_ULONG a1, const BN_ULONG a0,
232 const BN_ULONG b1, const BN_ULONG b0)
235 /* r[3] = h1, r[2] = h0; r[1] = l1; r[0] = l0 */
236 bn_GF2m_mul_1x1(r + 3, r + 2, a1, b1);
237 bn_GF2m_mul_1x1(r + 1, r, a0, b0);
238 bn_GF2m_mul_1x1(&m1, &m0, a0 ^ a1, b0 ^ b1);
239 /* Correction on m1 ^= l1 ^ h1; m0 ^= l0 ^ h0; */
240 r[2] ^= m1 ^ r[1] ^ r[3]; /* h0 ^= m1 ^ l1 ^ h1; */
241 r[1] = r[3] ^ r[2] ^ r[0] ^ m1 ^ m0; /* l1 ^= l0 ^ h0 ^ m0; */
244 void bn_GF2m_mul_2x2(BN_ULONG *r, BN_ULONG a1, BN_ULONG a0, BN_ULONG b1,
249 * Add polynomials a and b and store result in r; r could be a or b, a and b
250 * could be equal; r is the bitwise XOR of a and b.
252 int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
255 const BIGNUM *at, *bt;
260 if (a->top < b->top) {
268 if (bn_wexpand(r, at->top) == NULL)
271 for (i = 0; i < bt->top; i++) {
272 r->d[i] = at->d[i] ^ bt->d[i];
274 for (; i < at->top; i++) {
285 * Some functions allow for representation of the irreducible polynomials
286 * as an int[], say p. The irreducible f(t) is then of the form:
287 * t^p[0] + t^p[1] + ... + t^p[k]
288 * where m = p[0] > p[1] > ... > p[k] = 0.
291 /* Performs modular reduction of a and store result in r. r could be a. */
292 int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[])
301 /* reduction mod 1 => return 0 */
307 * Since the algorithm does reduction in the r value, if a != r, copy the
308 * contents of a into r so we can do reduction in r.
311 if (!bn_wexpand(r, a->top))
313 for (j = 0; j < a->top; j++) {
320 /* start reduction */
321 dN = p[0] / BN_BITS2;
322 for (j = r->top - 1; j > dN;) {
330 for (k = 1; p[k] != 0; k++) {
331 /* reducing component t^p[k] */
336 z[j - n] ^= (zz >> d0);
338 z[j - n - 1] ^= (zz << d1);
341 /* reducing component t^0 */
343 d0 = p[0] % BN_BITS2;
345 z[j - n] ^= (zz >> d0);
347 z[j - n - 1] ^= (zz << d1);
350 /* final round of reduction */
353 d0 = p[0] % BN_BITS2;
359 /* clear up the top d1 bits */
361 z[dN] = (z[dN] << d1) >> d1;
364 z[0] ^= zz; /* reduction t^0 component */
366 for (k = 1; p[k] != 0; k++) {
369 /* reducing component t^p[k] */
371 d0 = p[k] % BN_BITS2;
374 if (d0 && (tmp_ulong = zz >> d1))
375 z[n + 1] ^= tmp_ulong;
385 * Performs modular reduction of a by p and store result in r. r could be a.
386 * This function calls down to the BN_GF2m_mod_arr implementation; this wrapper
387 * function is only provided for convenience; for best performance, use the
388 * BN_GF2m_mod_arr function.
390 int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p)
396 ret = BN_GF2m_poly2arr(p, arr, OSSL_NELEM(arr));
397 if (!ret || ret > (int)OSSL_NELEM(arr)) {
398 ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH);
401 ret = BN_GF2m_mod_arr(r, a, arr);
407 * Compute the product of two polynomials a and b, reduce modulo p, and store
408 * the result in r. r could be a or b; a could be b.
410 int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
411 const int p[], BN_CTX *ctx)
413 int zlen, i, j, k, ret = 0;
415 BN_ULONG x1, x0, y1, y0, zz[4];
421 return BN_GF2m_mod_sqr_arr(r, a, p, ctx);
425 if ((s = BN_CTX_get(ctx)) == NULL)
428 zlen = a->top + b->top + 4;
429 if (!bn_wexpand(s, zlen))
433 for (i = 0; i < zlen; i++)
436 for (j = 0; j < b->top; j += 2) {
438 y1 = ((j + 1) == b->top) ? 0 : b->d[j + 1];
439 for (i = 0; i < a->top; i += 2) {
441 x1 = ((i + 1) == a->top) ? 0 : a->d[i + 1];
442 bn_GF2m_mul_2x2(zz, x1, x0, y1, y0);
443 for (k = 0; k < 4; k++)
444 s->d[i + j + k] ^= zz[k];
449 if (BN_GF2m_mod_arr(r, s, p))
459 * Compute the product of two polynomials a and b, reduce modulo p, and store
460 * the result in r. r could be a or b; a could equal b. This function calls
461 * down to the BN_GF2m_mod_mul_arr implementation; this wrapper function is
462 * only provided for convenience; for best performance, use the
463 * BN_GF2m_mod_mul_arr function.
465 int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
466 const BIGNUM *p, BN_CTX *ctx)
469 const int max = BN_num_bits(p) + 1;
476 arr = OPENSSL_malloc(sizeof(*arr) * max);
479 ret = BN_GF2m_poly2arr(p, arr, max);
480 if (!ret || ret > max) {
481 ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH);
484 ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);
491 /* Square a, reduce the result mod p, and store it in a. r could be a. */
492 int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],
500 if ((s = BN_CTX_get(ctx)) == NULL)
502 if (!bn_wexpand(s, 2 * a->top))
505 for (i = a->top - 1; i >= 0; i--) {
506 s->d[2 * i + 1] = SQR1(a->d[i]);
507 s->d[2 * i] = SQR0(a->d[i]);
512 if (!BN_GF2m_mod_arr(r, s, p))
522 * Square a, reduce the result mod p, and store it in a. r could be a. This
523 * function calls down to the BN_GF2m_mod_sqr_arr implementation; this
524 * wrapper function is only provided for convenience; for best performance,
525 * use the BN_GF2m_mod_sqr_arr function.
527 int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
530 const int max = BN_num_bits(p) + 1;
536 arr = OPENSSL_malloc(sizeof(*arr) * max);
539 ret = BN_GF2m_poly2arr(p, arr, max);
540 if (!ret || ret > max) {
541 ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH);
544 ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx);
552 * Invert a, reduce modulo p, and store the result in r. r could be a. Uses
553 * Modified Almost Inverse Algorithm (Algorithm 10) from Hankerson, D.,
554 * Hernandez, J.L., and Menezes, A. "Software Implementation of Elliptic
555 * Curve Cryptography Over Binary Fields".
557 static int BN_GF2m_mod_inv_vartime(BIGNUM *r, const BIGNUM *a,
558 const BIGNUM *p, BN_CTX *ctx)
560 BIGNUM *b, *c = NULL, *u = NULL, *v = NULL, *tmp;
575 if (!BN_GF2m_mod(u, a, p))
587 while (!BN_is_odd(u)) {
590 if (!BN_rshift1(u, u))
593 if (!BN_GF2m_add(b, b, p))
596 if (!BN_rshift1(b, b))
600 if (BN_abs_is_word(u, 1))
603 if (BN_num_bits(u) < BN_num_bits(v)) {
612 if (!BN_GF2m_add(u, u, v))
614 if (!BN_GF2m_add(b, b, c))
620 int ubits = BN_num_bits(u);
621 int vbits = BN_num_bits(v); /* v is copy of p */
623 BN_ULONG *udp, *bdp, *vdp, *cdp;
625 if (!bn_wexpand(u, top))
628 for (i = u->top; i < top; i++)
631 if (!bn_wexpand(b, top))
635 for (i = 1; i < top; i++)
638 if (!bn_wexpand(c, top))
641 for (i = 0; i < top; i++)
644 vdp = v->d; /* It pays off to "cache" *->d pointers,
645 * because it allows optimizer to be more
646 * aggressive. But we don't have to "cache"
647 * p->d, because *p is declared 'const'... */
649 while (ubits && !(udp[0] & 1)) {
650 BN_ULONG u0, u1, b0, b1, mask;
654 mask = (BN_ULONG)0 - (b0 & 1);
655 b0 ^= p->d[0] & mask;
656 for (i = 0; i < top - 1; i++) {
658 udp[i] = ((u0 >> 1) | (u1 << (BN_BITS2 - 1))) & BN_MASK2;
660 b1 = bdp[i + 1] ^ (p->d[i + 1] & mask);
661 bdp[i] = ((b0 >> 1) | (b1 << (BN_BITS2 - 1))) & BN_MASK2;
669 if (ubits <= BN_BITS2) {
670 if (udp[0] == 0) /* poly was reducible */
691 for (i = 0; i < top; i++) {
695 if (ubits == vbits) {
697 int utop = (ubits - 1) / BN_BITS2;
699 while ((ul = udp[utop]) == 0 && utop)
701 ubits = utop * BN_BITS2 + BN_num_bits_word(ul);
715 /* BN_CTX_end would complain about the expanded form */
725 * Wrapper for BN_GF2m_mod_inv_vartime that blinds the input before calling.
726 * This is not constant time.
727 * But it does eliminate first order deduction on the input.
729 int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
735 if ((b = BN_CTX_get(ctx)) == NULL)
738 /* generate blinding value */
740 if (!BN_priv_rand_ex(b, BN_num_bits(p) - 1,
741 BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY, 0, ctx))
743 } while (BN_is_zero(b));
746 if (!BN_GF2m_mod_mul(r, a, b, p, ctx))
750 if (!BN_GF2m_mod_inv_vartime(r, r, p, ctx))
753 /* r := b/(a * b) = 1/a */
754 if (!BN_GF2m_mod_mul(r, r, b, p, ctx))
765 * Invert xx, reduce modulo p, and store the result in r. r could be xx.
766 * This function calls down to the BN_GF2m_mod_inv implementation; this
767 * wrapper function is only provided for convenience; for best performance,
768 * use the BN_GF2m_mod_inv function.
770 int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const int p[],
778 if ((field = BN_CTX_get(ctx)) == NULL)
780 if (!BN_GF2m_arr2poly(p, field))
783 ret = BN_GF2m_mod_inv(r, xx, field, ctx);
792 * Divide y by x, reduce modulo p, and store the result in r. r could be x
793 * or y, x could equal y.
795 int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x,
796 const BIGNUM *p, BN_CTX *ctx)
806 xinv = BN_CTX_get(ctx);
810 if (!BN_GF2m_mod_inv(xinv, x, p, ctx))
812 if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx))
823 * Divide yy by xx, reduce modulo p, and store the result in r. r could be xx
824 * * or yy, xx could equal yy. This function calls down to the
825 * BN_GF2m_mod_div implementation; this wrapper function is only provided for
826 * convenience; for best performance, use the BN_GF2m_mod_div function.
828 int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx,
829 const int p[], BN_CTX *ctx)
838 if ((field = BN_CTX_get(ctx)) == NULL)
840 if (!BN_GF2m_arr2poly(p, field))
843 ret = BN_GF2m_mod_div(r, yy, xx, field, ctx);
852 * Compute the bth power of a, reduce modulo p, and store the result in r. r
853 * could be a. Uses simple square-and-multiply algorithm A.5.1 from IEEE
856 int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
857 const int p[], BN_CTX *ctx)
868 if (BN_abs_is_word(b, 1))
869 return (BN_copy(r, a) != NULL);
872 if ((u = BN_CTX_get(ctx)) == NULL)
875 if (!BN_GF2m_mod_arr(u, a, p))
878 n = BN_num_bits(b) - 1;
879 for (i = n - 1; i >= 0; i--) {
880 if (!BN_GF2m_mod_sqr_arr(u, u, p, ctx))
882 if (BN_is_bit_set(b, i)) {
883 if (!BN_GF2m_mod_mul_arr(u, u, a, p, ctx))
897 * Compute the bth power of a, reduce modulo p, and store the result in r. r
898 * could be a. This function calls down to the BN_GF2m_mod_exp_arr
899 * implementation; this wrapper function is only provided for convenience;
900 * for best performance, use the BN_GF2m_mod_exp_arr function.
902 int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
903 const BIGNUM *p, BN_CTX *ctx)
906 const int max = BN_num_bits(p) + 1;
913 arr = OPENSSL_malloc(sizeof(*arr) * max);
916 ret = BN_GF2m_poly2arr(p, arr, max);
917 if (!ret || ret > max) {
918 ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH);
921 ret = BN_GF2m_mod_exp_arr(r, a, b, arr, ctx);
929 * Compute the square root of a, reduce modulo p, and store the result in r.
930 * r could be a. Uses exponentiation as in algorithm A.4.1 from IEEE P1363.
932 int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const int p[],
941 /* reduction mod 1 => return 0 */
947 if ((u = BN_CTX_get(ctx)) == NULL)
950 if (!BN_set_bit(u, p[0] - 1))
952 ret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx);
961 * Compute the square root of a, reduce modulo p, and store the result in r.
962 * r could be a. This function calls down to the BN_GF2m_mod_sqrt_arr
963 * implementation; this wrapper function is only provided for convenience;
964 * for best performance, use the BN_GF2m_mod_sqrt_arr function.
966 int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
969 const int max = BN_num_bits(p) + 1;
975 arr = OPENSSL_malloc(sizeof(*arr) * max);
978 ret = BN_GF2m_poly2arr(p, arr, max);
979 if (!ret || ret > max) {
980 ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH);
983 ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx);
991 * Find r such that r^2 + r = a mod p. r could be a. If no r exists returns
992 * 0. Uses algorithms A.4.7 and A.4.6 from IEEE P1363.
994 int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const int p[],
997 int ret = 0, count = 0, j;
998 BIGNUM *a, *z, *rho, *w, *w2, *tmp;
1003 /* reduction mod 1 => return 0 */
1009 a = BN_CTX_get(ctx);
1010 z = BN_CTX_get(ctx);
1011 w = BN_CTX_get(ctx);
1015 if (!BN_GF2m_mod_arr(a, a_, p))
1018 if (BN_is_zero(a)) {
1024 if (p[0] & 0x1) { /* m is odd */
1025 /* compute half-trace of a */
1028 for (j = 1; j <= (p[0] - 1) / 2; j++) {
1029 if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx))
1031 if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx))
1033 if (!BN_GF2m_add(z, z, a))
1037 } else { /* m is even */
1039 rho = BN_CTX_get(ctx);
1040 w2 = BN_CTX_get(ctx);
1041 tmp = BN_CTX_get(ctx);
1045 if (!BN_priv_rand_ex(rho, p[0], BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY,
1048 if (!BN_GF2m_mod_arr(rho, rho, p))
1051 if (!BN_copy(w, rho))
1053 for (j = 1; j <= p[0] - 1; j++) {
1054 if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx))
1056 if (!BN_GF2m_mod_sqr_arr(w2, w, p, ctx))
1058 if (!BN_GF2m_mod_mul_arr(tmp, w2, a, p, ctx))
1060 if (!BN_GF2m_add(z, z, tmp))
1062 if (!BN_GF2m_add(w, w2, rho))
1066 } while (BN_is_zero(w) && (count < MAX_ITERATIONS));
1067 if (BN_is_zero(w)) {
1068 ERR_raise(ERR_LIB_BN, BN_R_TOO_MANY_ITERATIONS);
1073 if (!BN_GF2m_mod_sqr_arr(w, z, p, ctx))
1075 if (!BN_GF2m_add(w, z, w))
1077 if (BN_GF2m_cmp(w, a)) {
1078 ERR_raise(ERR_LIB_BN, BN_R_NO_SOLUTION);
1094 * Find r such that r^2 + r = a mod p. r could be a. If no r exists returns
1095 * 0. This function calls down to the BN_GF2m_mod_solve_quad_arr
1096 * implementation; this wrapper function is only provided for convenience;
1097 * for best performance, use the BN_GF2m_mod_solve_quad_arr function.
1099 int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
1103 const int max = BN_num_bits(p) + 1;
1109 arr = OPENSSL_malloc(sizeof(*arr) * max);
1112 ret = BN_GF2m_poly2arr(p, arr, max);
1113 if (!ret || ret > max) {
1114 ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH);
1117 ret = BN_GF2m_mod_solve_quad_arr(r, a, arr, ctx);
1125 * Convert the bit-string representation of a polynomial ( \sum_{i=0}^n a_i *
1126 * x^i) into an array of integers corresponding to the bits with non-zero
1127 * coefficient. Array is terminated with -1. Up to max elements of the array
1128 * will be filled. Return value is total number of array elements that would
1129 * be filled if array was large enough.
1131 int BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max)
1139 for (i = a->top - 1; i >= 0; i--) {
1141 /* skip word if a->d[i] == 0 */
1144 for (j = BN_BITS2 - 1; j >= 0; j--) {
1145 if (a->d[i] & mask) {
1147 p[k] = BN_BITS2 * i + j;
1163 * Convert the coefficient array representation of a polynomial to a
1164 * bit-string. The array must be terminated by -1.
1166 int BN_GF2m_arr2poly(const int p[], BIGNUM *a)
1172 for (i = 0; p[i] != -1; i++) {
1173 if (BN_set_bit(a, p[i]) == 0)