static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts,
                           unsigned char *val, int len)
{
    unsigned char *tmpval;
    ASN1_OCTET_STRING os;
    int ret = 0;
    if (len <= 0)
        len = OCSP_DEFAULT_NONCE_LENGTH;
    os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING);
    os.data = OPENSSL_malloc(os.length);
    if (os.data == NULL)
        goto err;
    tmpval = os.data;
    ASN1_put_object(&tmpval, 0, len, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL);
    if (val)
        memcpy(tmpval, val, len);
    else if (RAND_bytes(tmpval, len) <= 0)
        goto err;
    if (!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce,
                         &os, 0, X509V3_ADD_REPLACE))
        goto err;
    ret = 1;
 err:
    OPENSSL_free(os.data);
    return ret;
}
['static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts,\n                           unsigned char *val, int len)\n{\n    unsigned char *tmpval;\n    ASN1_OCTET_STRING os;\n    int ret = 0;\n    if (len <= 0)\n        len = OCSP_DEFAULT_NONCE_LENGTH;\n    os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING);\n    os.data = OPENSSL_malloc(os.length);\n    if (os.data == NULL)\n        goto err;\n    tmpval = os.data;\n    ASN1_put_object(&tmpval, 0, len, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL);\n    if (val)\n        memcpy(tmpval, val, len);\n    else if (RAND_bytes(tmpval, len) <= 0)\n        goto err;\n    if (!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce,\n                         &os, 0, X509V3_ADD_REPLACE))\n        goto err;\n    ret = 1;\n err:\n    OPENSSL_free(os.data);\n    return ret;\n}', 'int ASN1_object_size(int constructed, int length, int tag)\n{\n    int ret;\n    ret = length;\n    ret++;\n    if (tag >= 31) {\n        while (tag > 0) {\n            tag >>= 7;\n            ret++;\n        }\n    }\n    if (constructed == 2)\n        return ret + 3;\n    ret++;\n    if (length > 127) {\n        while (length > 0) {\n            length >>= 8;\n            ret++;\n        }\n    }\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}', 'int RAND_bytes(unsigned char *buf, int num)\n{\n    const RAND_METHOD *meth = RAND_get_rand_method();\n    if (meth && meth->bytes)\n        return meth->bytes(buf, num);\n    return (-1);\n}', 'const RAND_METHOD *RAND_get_rand_method(void)\n{\n    if (!default_RAND_meth) {\n#ifndef OPENSSL_NO_ENGINE\n        ENGINE *e = ENGINE_get_default_RAND();\n        if (e) {\n            default_RAND_meth = ENGINE_get_RAND(e);\n            if (!default_RAND_meth) {\n                ENGINE_finish(e);\n                e = NULL;\n            }\n        }\n        if (e)\n            funct_ref = e;\n        else\n#endif\n            default_RAND_meth = RAND_OpenSSL();\n    }\n    return default_RAND_meth;\n}']