int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
                                const char *label, size_t llen,
                                const unsigned char *context,
                                size_t contextlen, int use_context)
{
    unsigned char *val = NULL;
    size_t vallen = 0, currentvalpos;
    int rv;
    vallen = llen + SSL3_RANDOM_SIZE * 2;
    if (use_context) {
        vallen += 2 + contextlen;
    }
    val = OPENSSL_malloc(vallen);
    if (val == NULL)
        goto err2;
    currentvalpos = 0;
    memcpy(val + currentvalpos, (unsigned char *)label, llen);
    currentvalpos += llen;
    memcpy(val + currentvalpos, s->s3.client_random, SSL3_RANDOM_SIZE);
    currentvalpos += SSL3_RANDOM_SIZE;
    memcpy(val + currentvalpos, s->s3.server_random, SSL3_RANDOM_SIZE);
    currentvalpos += SSL3_RANDOM_SIZE;
    if (use_context) {
        val[currentvalpos] = (contextlen >> 8) & 0xff;
        currentvalpos++;
        val[currentvalpos] = contextlen & 0xff;
        currentvalpos++;
        if ((contextlen > 0) || (context != NULL)) {
            memcpy(val + currentvalpos, context, contextlen);
        }
    }
    if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,
               TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0)
        goto err1;
    if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,
               TLS_MD_SERVER_FINISH_CONST_SIZE) == 0)
        goto err1;
    if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,
               TLS_MD_MASTER_SECRET_CONST_SIZE) == 0)
        goto err1;
    if (memcmp(val, TLS_MD_EXTENDED_MASTER_SECRET_CONST,
               TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE) == 0)
        goto err1;
    if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,
               TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0)
        goto err1;
    rv = tls1_PRF(s,
                  val, vallen,
                  NULL, 0,
                  NULL, 0,
                  NULL, 0,
                  NULL, 0,
                  s->session->master_key, s->session->master_key_length,
                  out, olen, 0);
    goto ret;
 err1:
    SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);
    rv = 0;
    goto ret;
 err2:
    SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, ERR_R_MALLOC_FAILURE);
    rv = 0;
 ret:
    OPENSSL_clear_free(val, vallen);
    return rv;
}
['int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,\n                                const char *label, size_t llen,\n                                const unsigned char *context,\n                                size_t contextlen, int use_context)\n{\n    unsigned char *val = NULL;\n    size_t vallen = 0, currentvalpos;\n    int rv;\n    vallen = llen + SSL3_RANDOM_SIZE * 2;\n    if (use_context) {\n        vallen += 2 + contextlen;\n    }\n    val = OPENSSL_malloc(vallen);\n    if (val == NULL)\n        goto err2;\n    currentvalpos = 0;\n    memcpy(val + currentvalpos, (unsigned char *)label, llen);\n    currentvalpos += llen;\n    memcpy(val + currentvalpos, s->s3.client_random, SSL3_RANDOM_SIZE);\n    currentvalpos += SSL3_RANDOM_SIZE;\n    memcpy(val + currentvalpos, s->s3.server_random, SSL3_RANDOM_SIZE);\n    currentvalpos += SSL3_RANDOM_SIZE;\n    if (use_context) {\n        val[currentvalpos] = (contextlen >> 8) & 0xff;\n        currentvalpos++;\n        val[currentvalpos] = contextlen & 0xff;\n        currentvalpos++;\n        if ((contextlen > 0) || (context != NULL)) {\n            memcpy(val + currentvalpos, context, contextlen);\n        }\n    }\n    if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,\n               TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0)\n        goto err1;\n    if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,\n               TLS_MD_SERVER_FINISH_CONST_SIZE) == 0)\n        goto err1;\n    if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,\n               TLS_MD_MASTER_SECRET_CONST_SIZE) == 0)\n        goto err1;\n    if (memcmp(val, TLS_MD_EXTENDED_MASTER_SECRET_CONST,\n               TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE) == 0)\n        goto err1;\n    if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,\n               TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0)\n        goto err1;\n    rv = tls1_PRF(s,\n                  val, vallen,\n                  NULL, 0,\n                  NULL, 0,\n                  NULL, 0,\n                  NULL, 0,\n                  s->session->master_key, s->session->master_key_length,\n                  out, olen, 0);\n    goto ret;\n err1:\n    SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);\n    rv = 0;\n    goto ret;\n err2:\n    SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, ERR_R_MALLOC_FAILURE);\n    rv = 0;\n ret:\n    OPENSSL_clear_free(val, vallen);\n    return rv;\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}']