int	BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], BN_CTX *ctx)
	{
	int ret = 0;
	BIGNUM *u;
	if (!p[0])
		return BN_zero(r);
	BN_CTX_start(ctx);
	if ((u = BN_CTX_get(ctx)) == NULL) goto err;
	if (!BN_zero(u)) goto err;
	if (!BN_set_bit(u, p[0] - 1)) goto err;
	ret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx);
	bn_check_top(r);
  err:
	BN_CTX_end(ctx);
	return ret;
	}
['int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n\t{\n\tconst int max = BN_num_bits(p);\n\tunsigned int *arr=NULL, ret = 0;\n\tif ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;\n\tret = BN_GF2m_poly2arr(p, arr, max);\n\tif (!ret || ret > max)\n\t\t{\n\t\tBNerr(BN_F_BN_GF2M_MOD_EXP,BN_R_INVALID_LENGTH);\n\t\tgoto err;\n\t\t}\n\tret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx);\n\tbn_check_top(r);\n  err:\n\tif (arr) OPENSSL_free(arr);\n\treturn ret;\n\t}', 'int BN_GF2m_poly2arr(const BIGNUM *a, unsigned int p[], int max)\n\t{\n\tint i, j, k = 0;\n\tBN_ULONG mask;\n\tif (BN_is_zero(a) || !BN_is_bit_set(a, 0))\n\t\treturn 0;\n\tfor (i = a->top - 1; i >= 0; i--)\n\t\t{\n\t\tif (!a->d[i])\n\t\t\tcontinue;\n\t\tmask = BN_TBIT;\n\t\tfor (j = BN_BITS2 - 1; j >= 0; j--)\n\t\t\t{\n\t\t\tif (a->d[i] & mask)\n\t\t\t\t{\n\t\t\t\tif (k < max) p[k] = BN_BITS2 * i + j;\n\t\t\t\tk++;\n\t\t\t\t}\n\t\t\tmask >>= 1;\n\t\t\t}\n\t\t}\n\treturn k;\n\t}', 'int\tBN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *u;\n\tif (!p[0])\n\t\treturn BN_zero(r);\n\tBN_CTX_start(ctx);\n\tif ((u = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (!BN_zero(u)) goto err;\n\tif (!BN_set_bit(u, p[0] - 1)) goto err;\n\tret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx);\n\tbn_check_top(r);\n  err:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}']