static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    if (words > (INT_MAX / (4 * BN_BITS2))) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_SECURE))
        a = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = OPENSSL_zalloc(words * sizeof(*a));
    if (a == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    assert(b->top <= words);
    if (b->top > 0)
        memcpy(a, b->d, sizeof(*a) * b->top);
    return a;
}
['static int x9_62_tests(int n)\n{\n    int nid, md_nid, ret = 0;\n    const char *r_in = NULL, *s_in = NULL, *tbs = NULL;\n    unsigned char *pbuf = NULL, *qbuf = NULL, *message = NULL;\n    unsigned char digest[EVP_MAX_MD_SIZE];\n    unsigned int dgst_len = 0;\n    long q_len, msg_len = 0;\n    size_t p_len;\n    EVP_MD_CTX *mctx = NULL;\n    EC_KEY *key = NULL;\n    ECDSA_SIG *signature = NULL;\n    BIGNUM *r = NULL, *s = NULL;\n    BIGNUM *kinv = NULL, *rp = NULL;\n    const BIGNUM *sig_r = NULL, *sig_s = NULL;\n    nid = ecdsa_cavs_kats[n].nid;\n    md_nid = ecdsa_cavs_kats[n].md_nid;\n    r_in = ecdsa_cavs_kats[n].r;\n    s_in = ecdsa_cavs_kats[n].s;\n    tbs = ecdsa_cavs_kats[n].msg;\n    numbers[0] = ecdsa_cavs_kats[n].d;\n    numbers[1] = ecdsa_cavs_kats[n].k;\n    TEST_info("ECDSA KATs for curve %s", OBJ_nid2sn(nid));\n    if (!TEST_ptr(mctx = EVP_MD_CTX_new())\n        || !TEST_ptr(message = OPENSSL_hexstr2buf(tbs, &msg_len))\n        || !TEST_true(EVP_DigestInit_ex(mctx, EVP_get_digestbynid(md_nid), NULL))\n        || !TEST_true(EVP_DigestUpdate(mctx, message, msg_len))\n        || !TEST_true(EVP_DigestFinal_ex(mctx, digest, &dgst_len))\n        || !TEST_ptr(key = EC_KEY_new_by_curve_name(nid))\n        || !TEST_ptr(r = BN_new())\n        || !TEST_ptr(s = BN_new())\n        || !TEST_true(BN_hex2bn(&r, r_in))\n        || !TEST_true(BN_hex2bn(&s, s_in))\n        || !TEST_true(change_rand()))\n        goto err;\n    use_fake = 1;\n    if (!TEST_true(EC_KEY_generate_key(key))\n        || !TEST_true(p_len = EC_KEY_key2buf(key, POINT_CONVERSION_UNCOMPRESSED,\n                                             &pbuf, NULL))\n        || !TEST_ptr(qbuf = OPENSSL_hexstr2buf(ecdsa_cavs_kats[n].Q, &q_len))\n        || !TEST_int_eq(q_len, p_len)\n        || !TEST_mem_eq(qbuf, q_len, pbuf, p_len))\n        goto err;\n    use_fake = 1;\n    if (!TEST_true(ECDSA_sign_setup(key, NULL, &kinv, &rp))\n        || !TEST_ptr(signature = ECDSA_do_sign_ex(digest, dgst_len,\n                                                  kinv, rp, key))\n        || !TEST_int_eq(ECDSA_do_verify(digest, dgst_len, signature, key), 1))\n        goto err;\n    ECDSA_SIG_get0(signature, &sig_r, &sig_s);\n    if (!TEST_BN_eq(sig_r, r)\n        || !TEST_BN_eq(sig_s, s))\n        goto err;\n    ret = 1;\n err:\n    if (!TEST_true(restore_rand()))\n        ret = 0;\n    OPENSSL_free(message);\n    OPENSSL_free(pbuf);\n    OPENSSL_free(qbuf);\n    EC_KEY_free(key);\n    ECDSA_SIG_free(signature);\n    BN_free(r);\n    BN_free(s);\n    EVP_MD_CTX_free(mctx);\n    BN_clear_free(kinv);\n    BN_clear_free(rp);\n    return ret;\n}', "int BN_hex2bn(BIGNUM **bn, const char *a)\n{\n    BIGNUM *ret = NULL;\n    BN_ULONG l = 0;\n    int neg = 0, h, m, i, j, k, c;\n    int num;\n    if (a == NULL || *a == '\\0')\n        return 0;\n    if (*a == '-') {\n        neg = 1;\n        a++;\n    }\n    for (i = 0; i <= INT_MAX / 4 && ossl_isxdigit(a[i]); i++)\n        continue;\n    if (i == 0 || i > INT_MAX / 4)\n        goto err;\n    num = i + neg;\n    if (bn == NULL)\n        return num;\n    if (*bn == NULL) {\n        if ((ret = BN_new()) == NULL)\n            return 0;\n    } else {\n        ret = *bn;\n        BN_zero(ret);\n    }\n    if (bn_expand(ret, i * 4) == NULL)\n        goto err;\n    j = i;\n    m = 0;\n    h = 0;\n    while (j > 0) {\n        m = (BN_BYTES * 2 <= j) ? BN_BYTES * 2 : j;\n        l = 0;\n        for (;;) {\n            c = a[j - m];\n            k = OPENSSL_hexchar2int(c);\n            if (k < 0)\n                k = 0;\n            l = (l << 4) | k;\n            if (--m <= 0) {\n                ret->d[h++] = l;\n                break;\n            }\n        }\n        j -= BN_BYTES * 2;\n    }\n    ret->top = h;\n    bn_correct_top(ret);\n    *bn = ret;\n    bn_check_top(ret);\n    if (ret->top != 0)\n        ret->neg = neg;\n    return num;\n err:\n    if (*bn == NULL)\n        BN_free(ret);\n    return 0;\n}", 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return 0;\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    a->flags &= ~BN_FLG_FIXED_TOP;\n    bn_check_top(a);\n    return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n    if (bits > (INT_MAX - BN_BITS2 + 1))\n        return NULL;\n    if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n        return a;\n    return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    if (words > b->dmax) {\n        BN_ULONG *a = bn_expand_internal(b, words);\n        if (!a)\n            return NULL;\n        if (b->d) {\n            OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n            bn_free_d(b);\n        }\n        b->d = a;\n        b->dmax = words;\n    }\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    if (words > (INT_MAX / (4 * BN_BITS2))) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_SECURE))\n        a = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = OPENSSL_zalloc(words * sizeof(*a));\n    if (a == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    assert(b->top <= words);\n    if (b->top > 0)\n        memcpy(a, b->d, sizeof(*a) * b->top);\n    return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    INCREMENT(malloc_count);\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\n    if (allow_customize) {\n        allow_customize = 0;\n    }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']