int BN_hex2bn(BIGNUM **bn, const char *a)
{
    BIGNUM *ret = NULL;
    BN_ULONG l = 0;
    int neg = 0, h, m, i, j, k, c;
    int num;
    if ((a == NULL) || (*a == '\0'))
        return (0);
    if (*a == '-') {
        neg = 1;
        a++;
    }
    for (i = 0; isxdigit((unsigned char)a[i]); i++) ;
    num = i + neg;
    if (bn == NULL)
        return (num);
    if (*bn == NULL) {
        if ((ret = BN_new()) == NULL)
            return (0);
    } else {
        ret = *bn;
        BN_zero(ret);
    }
    if (bn_expand(ret, i * 4) == NULL)
        goto err;
    j = i;
    m = 0;
    h = 0;
    while (j > 0) {
        m = ((BN_BYTES * 2) <= j) ? (BN_BYTES * 2) : j;
        l = 0;
        for (;;) {
            c = a[j - m];
            if ((c >= '0') && (c <= '9'))
                k = c - '0';
            else if ((c >= 'a') && (c <= 'f'))
                k = c - 'a' + 10;
            else if ((c >= 'A') && (c <= 'F'))
                k = c - 'A' + 10;
            else
                k = 0;
            l = (l << 4) | k;
            if (--m <= 0) {
                ret->d[h++] = l;
                break;
            }
        }
        j -= (BN_BYTES * 2);
    }
    ret->top = h;
    bn_correct_top(ret);
    ret->neg = neg;
    *bn = ret;
    bn_check_top(ret);
    return (num);
 err:
    if (*bn == NULL)
        BN_free(ret);
    return (0);
}
['int test_sqr(BIO *bp, BN_CTX *ctx)\n{\n    BIGNUM *a, *c, *d, *e;\n    int i, ret = 0;\n    a = BN_new();\n    c = BN_new();\n    d = BN_new();\n    e = BN_new();\n    if (a == NULL || c == NULL || d == NULL || e == NULL) {\n        goto err;\n    }\n    for (i = 0; i < num0; i++) {\n        BN_bntest_rand(a, 40 + i * 10, 0, 0);\n        a->neg = rand_neg();\n        BN_sqr(c, a, ctx);\n        if (bp != NULL) {\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " * ");\n                BN_print(bp, a);\n                BIO_puts(bp, " - ");\n            }\n            BN_print(bp, c);\n            BIO_puts(bp, "\\n");\n        }\n        BN_div(d, e, c, a, ctx);\n        BN_sub(d, d, a);\n        if (!BN_is_zero(d) || !BN_is_zero(e)) {\n            fprintf(stderr, "Square test failed!\\n");\n            goto err;\n        }\n    }\n    BN_hex2bn(&a,\n              "80000000000000008000000000000001"\n              "FFFFFFFFFFFFFFFE0000000000000000");\n    BN_sqr(c, a, ctx);\n    if (bp != NULL) {\n        if (!results) {\n            BN_print(bp, a);\n            BIO_puts(bp, " * ");\n            BN_print(bp, a);\n            BIO_puts(bp, " - ");\n        }\n        BN_print(bp, c);\n        BIO_puts(bp, "\\n");\n    }\n    BN_mul(d, a, a, ctx);\n    if (BN_cmp(c, d)) {\n        fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "\n                "different results!\\n");\n        goto err;\n    }\n    BN_hex2bn(&a,\n              "80000000000000000000000080000001"\n              "FFFFFFFE000000000000000000000000");\n    BN_sqr(c, a, ctx);\n    if (bp != NULL) {\n        if (!results) {\n            BN_print(bp, a);\n            BIO_puts(bp, " * ");\n            BN_print(bp, a);\n            BIO_puts(bp, " - ");\n        }\n        BN_print(bp, c);\n        BIO_puts(bp, "\\n");\n    }\n    BN_mul(d, a, a, ctx);\n    if (BN_cmp(c, d)) {\n        fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "\n                "different results!\\n");\n        goto err;\n    }\n    ret = 1;\n err:\n    if (a != NULL)\n        BN_free(a);\n    if (c != NULL)\n        BN_free(c);\n    if (d != NULL)\n        BN_free(d);\n    if (e != NULL)\n        BN_free(e);\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; isxdigit((unsigned char)a[i]); i++) ;\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            if ((c >= '0') && (c <= '9'))\n                k = c - '0';\n            else if ((c >= 'a') && (c <= 'f'))\n                k = c - 'a' + 10;\n            else if ((c >= 'A') && (c <= 'F'))\n                k = c - 'A' + 10;\n            else\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    ret->neg = neg;\n    *bn = ret;\n    bn_check_top(ret);\n    return (num);\n err:\n    if (*bn == NULL)\n        BN_free(ret);\n    return (0);\n}"]