static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    bn_check_top(b);
    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 ASN1_INTEGER *x509_load_serial(const char *CAfile, const char *serialfile,\n                                      int create)\n{\n    char *buf = NULL, *p;\n    ASN1_INTEGER *bs = NULL;\n    BIGNUM *serial = NULL;\n    size_t len;\n    len = ((serialfile == NULL)\n           ? (strlen(CAfile) + strlen(POSTFIX) + 1)\n           : (strlen(serialfile))) + 1;\n    buf = app_malloc(len, "serial# buffer");\n    if (serialfile == NULL) {\n        OPENSSL_strlcpy(buf, CAfile, len);\n        for (p = buf; *p; p++)\n            if (*p == \'.\') {\n                *p = \'\\0\';\n                break;\n            }\n        OPENSSL_strlcat(buf, POSTFIX, len);\n    } else {\n        OPENSSL_strlcpy(buf, serialfile, len);\n    }\n    serial = load_serial(buf, create, NULL);\n    if (serial == NULL)\n        goto end;\n    if (!BN_add_word(serial, 1)) {\n        BIO_printf(bio_err, "add_word failure\\n");\n        goto end;\n    }\n    if (!save_serial(buf, NULL, serial, &bs))\n        goto end;\n end:\n    OPENSSL_free(buf);\n    BN_free(serial);\n    return bs;\n}', 'BIGNUM *load_serial(const char *serialfile, int create, ASN1_INTEGER **retai)\n{\n    BIO *in = NULL;\n    BIGNUM *ret = NULL;\n    char buf[1024];\n    ASN1_INTEGER *ai = NULL;\n    ai = ASN1_INTEGER_new();\n    if (ai == NULL)\n        goto err;\n    in = BIO_new_file(serialfile, "r");\n    if (in == NULL) {\n        if (!create) {\n            perror(serialfile);\n            goto err;\n        }\n        ERR_clear_error();\n        ret = BN_new();\n        if (ret == NULL || !rand_serial(ret, ai))\n            BIO_printf(bio_err, "Out of memory\\n");\n    } else {\n        if (!a2i_ASN1_INTEGER(in, ai, buf, 1024)) {\n            BIO_printf(bio_err, "unable to load number from %s\\n",\n                       serialfile);\n            goto err;\n        }\n        ret = ASN1_INTEGER_to_BN(ai, NULL);\n        if (ret == NULL) {\n            BIO_printf(bio_err,\n                       "error converting number from bin to BIGNUM\\n");\n            goto err;\n        }\n    }\n    if (ret && retai) {\n        *retai = ai;\n        ai = NULL;\n    }\n err:\n    BIO_free(in);\n    ASN1_INTEGER_free(ai);\n    return (ret);\n}', 'int rand_serial(BIGNUM *b, ASN1_INTEGER *ai)\n{\n    BIGNUM *btmp;\n    int ret = 0;\n    if (b)\n        btmp = b;\n    else\n        btmp = BN_new();\n    if (btmp == NULL)\n        return 0;\n    if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0))\n        goto error;\n    if (ai && !BN_to_ASN1_INTEGER(btmp, ai))\n        goto error;\n    ret = 1;\n error:\n    if (btmp != b)\n        BN_free(btmp);\n    return ret;\n}', 'int BN_add_word(BIGNUM *a, BN_ULONG w)\n{\n    BN_ULONG l;\n    int i;\n    bn_check_top(a);\n    w &= BN_MASK2;\n    if (!w)\n        return 1;\n    if (BN_is_zero(a))\n        return BN_set_word(a, w);\n    if (a->neg) {\n        a->neg = 0;\n        i = BN_sub_word(a, w);\n        if (!BN_is_zero(a))\n            a->neg = !(a->neg);\n        return (i);\n    }\n    for (i = 0; w != 0 && i < a->top; i++) {\n        a->d[i] = l = (a->d[i] + w) & BN_MASK2;\n        w = (w > l) ? 1 : 0;\n    }\n    if (w && i == a->top) {\n        if (bn_wexpand(a, a->top + 1) == NULL)\n            return 0;\n        a->top++;\n        a->d[i] = w;\n    }\n    bn_check_top(a);\n    return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    bn_check_top(b);\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    bn_check_top(b);\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    bn_check_top(b);\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    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    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    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']