int test_kron(BIO *bp, BN_CTX *ctx)
{
    BN_GENCB cb;
    BIGNUM *a, *b, *r, *t;
    int i;
    int legendre, kronecker;
    int ret = 0;
    a = BN_new();
    b = BN_new();
    r = BN_new();
    t = BN_new();
    if (a == NULL || b == NULL || r == NULL || t == NULL)
        goto err;
    BN_GENCB_set(&cb, genprime_cb, NULL);
    if (!BN_generate_prime_ex(b, 512, 0, NULL, NULL, &cb))
        goto err;
    b->neg = rand_neg();
    putc('\n', stderr);
    for (i = 0; i < num0; i++) {
        if (!BN_bntest_rand(a, 512, 0, 0))
            goto err;
        a->neg = rand_neg();
        if (!BN_copy(t, b))
            goto err;
        t->neg = 0;
        if (!BN_sub_word(t, 1))
            goto err;
        if (!BN_rshift1(t, t))
            goto err;
        b->neg = 0;
        if (!BN_mod_exp_recp(r, a, t, b, ctx))
            goto err;
        b->neg = 1;
        if (BN_is_word(r, 1))
            legendre = 1;
        else if (BN_is_zero(r))
            legendre = 0;
        else {
            if (!BN_add_word(r, 1))
                goto err;
            if (0 != BN_ucmp(r, b)) {
                fprintf(stderr, "Legendre symbol computation failed\n");
                goto err;
            }
            legendre = -1;
        }
        kronecker = BN_kronecker(a, b, ctx);
        if (kronecker < -1)
            goto err;
        if (a->neg && b->neg)
            kronecker = -kronecker;
        if (legendre != kronecker) {
            fprintf(stderr, "legendre != kronecker; a = ");
            BN_print_fp(stderr, a);
            fprintf(stderr, ", b = ");
            BN_print_fp(stderr, b);
            fprintf(stderr, "\n");
            goto err;
        }
        putc('.', stderr);
        fflush(stderr);
    }
    putc('\n', stderr);
    fflush(stderr);
    ret = 1;
 err:
    BN_free(a);
    BN_free(b);
    BN_free(r);
    BN_free(t);
    return ret;
}
['int test_kron(BIO *bp, BN_CTX *ctx)\n{\n    BN_GENCB cb;\n    BIGNUM *a, *b, *r, *t;\n    int i;\n    int legendre, kronecker;\n    int ret = 0;\n    a = BN_new();\n    b = BN_new();\n    r = BN_new();\n    t = BN_new();\n    if (a == NULL || b == NULL || r == NULL || t == NULL)\n        goto err;\n    BN_GENCB_set(&cb, genprime_cb, NULL);\n    if (!BN_generate_prime_ex(b, 512, 0, NULL, NULL, &cb))\n        goto err;\n    b->neg = rand_neg();\n    putc(\'\\n\', stderr);\n    for (i = 0; i < num0; i++) {\n        if (!BN_bntest_rand(a, 512, 0, 0))\n            goto err;\n        a->neg = rand_neg();\n        if (!BN_copy(t, b))\n            goto err;\n        t->neg = 0;\n        if (!BN_sub_word(t, 1))\n            goto err;\n        if (!BN_rshift1(t, t))\n            goto err;\n        b->neg = 0;\n        if (!BN_mod_exp_recp(r, a, t, b, ctx))\n            goto err;\n        b->neg = 1;\n        if (BN_is_word(r, 1))\n            legendre = 1;\n        else if (BN_is_zero(r))\n            legendre = 0;\n        else {\n            if (!BN_add_word(r, 1))\n                goto err;\n            if (0 != BN_ucmp(r, b)) {\n                fprintf(stderr, "Legendre symbol computation failed\\n");\n                goto err;\n            }\n            legendre = -1;\n        }\n        kronecker = BN_kronecker(a, b, ctx);\n        if (kronecker < -1)\n            goto err;\n        if (a->neg && b->neg)\n            kronecker = -kronecker;\n        if (legendre != kronecker) {\n            fprintf(stderr, "legendre != kronecker; a = ");\n            BN_print_fp(stderr, a);\n            fprintf(stderr, ", b = ");\n            BN_print_fp(stderr, b);\n            fprintf(stderr, "\\n");\n            goto err;\n        }\n        putc(\'.\', stderr);\n        fflush(stderr);\n    }\n    putc(\'\\n\', stderr);\n    fflush(stderr);\n    ret = 1;\n err:\n    BN_free(a);\n    BN_free(b);\n    BN_free(r);\n    BN_free(t);\n    return ret;\n}', 'BIGNUM *BN_new(void)\n{\n    BIGNUM *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n        BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    ret->flags = BN_FLG_MALLOCED;\n    bn_check_top(ret);\n    return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\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    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\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;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}', 'void BN_GENCB_set(BN_GENCB *gencb, int (*callback) (int, int, BN_GENCB *),\n                  void *cb_arg)\n{\n    BN_GENCB *tmp_gencb = gencb;\n    tmp_gencb->ver = 2;\n    tmp_gencb->arg = cb_arg;\n    tmp_gencb->cb.cb_2 = callback;\n}', 'void BN_free(BIGNUM *a)\n{\n    if (a == NULL)\n        return;\n    bn_check_top(a);\n    if (!BN_get_flags(a, BN_FLG_STATIC_DATA))\n        bn_free_d(a);\n    if (a->flags & BN_FLG_MALLOCED)\n        OPENSSL_free(a);\n    else {\n#if OPENSSL_API_COMPAT < 0x00908000L\n        a->flags |= BN_FLG_FREE;\n#endif\n        a->d = NULL;\n    }\n}', 'int BN_get_flags(const BIGNUM *b, int n)\n{\n    return b->flags & n;\n}']