int n_ssl3_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int sending)
{
    unsigned char *mac_sec, *seq;
    const EVP_MD_CTX *hash;
    unsigned char *p, rec_char;
    size_t md_size;
    size_t npad;
    int t;
    if (sending) {
        mac_sec = &(ssl->s3->write_mac_secret[0]);
        seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);
        hash = ssl->write_hash;
    } else {
        mac_sec = &(ssl->s3->read_mac_secret[0]);
        seq = RECORD_LAYER_get_read_sequence(&ssl->rlayer);
        hash = ssl->read_hash;
    }
    t = EVP_MD_CTX_size(hash);
    if (t < 0)
        return 0;
    md_size = t;
    npad = (48 / md_size) * md_size;
    if (!sending &&
        EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&
        ssl3_cbc_record_digest_supported(hash)) {
        unsigned char header[75];
        size_t j = 0;
        memcpy(header + j, mac_sec, md_size);
        j += md_size;
        memcpy(header + j, ssl3_pad_1, npad);
        j += npad;
        memcpy(header + j, seq, 8);
        j += 8;
        header[j++] = rec->type;
        header[j++] = (unsigned char)(rec->length >> 8);
        header[j++] = (unsigned char)(rec->length & 0xff);
        if (ssl3_cbc_digest_record(hash,
                                   md, &md_size,
                                   header, rec->input,
                                   rec->length + md_size, rec->orig_len,
                                   mac_sec, md_size, 1) <= 0)
            return 0;
    } else {
        unsigned int md_size_u;
        EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
        if (md_ctx == NULL)
            return 0;
        rec_char = rec->type;
        p = md;
        s2n(rec->length, p);
        if (EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0
            || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0
            || EVP_DigestUpdate(md_ctx, ssl3_pad_1, npad) <= 0
            || EVP_DigestUpdate(md_ctx, seq, 8) <= 0
            || EVP_DigestUpdate(md_ctx, &rec_char, 1) <= 0
            || EVP_DigestUpdate(md_ctx, md, 2) <= 0
            || EVP_DigestUpdate(md_ctx, rec->input, rec->length) <= 0
            || EVP_DigestFinal_ex(md_ctx, md, NULL) <= 0
            || EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0
            || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0
            || EVP_DigestUpdate(md_ctx, ssl3_pad_2, npad) <= 0
            || EVP_DigestUpdate(md_ctx, md, md_size) <= 0
            || EVP_DigestFinal_ex(md_ctx, md, &md_size_u) <= 0) {
            EVP_MD_CTX_reset(md_ctx);
            return 0;
        }
        EVP_MD_CTX_free(md_ctx);
    }
    ssl3_record_sequence_update(seq);
    return 1;
}
['int n_ssl3_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int sending)\n{\n    unsigned char *mac_sec, *seq;\n    const EVP_MD_CTX *hash;\n    unsigned char *p, rec_char;\n    size_t md_size;\n    size_t npad;\n    int t;\n    if (sending) {\n        mac_sec = &(ssl->s3->write_mac_secret[0]);\n        seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);\n        hash = ssl->write_hash;\n    } else {\n        mac_sec = &(ssl->s3->read_mac_secret[0]);\n        seq = RECORD_LAYER_get_read_sequence(&ssl->rlayer);\n        hash = ssl->read_hash;\n    }\n    t = EVP_MD_CTX_size(hash);\n    if (t < 0)\n        return 0;\n    md_size = t;\n    npad = (48 / md_size) * md_size;\n    if (!sending &&\n        EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n        ssl3_cbc_record_digest_supported(hash)) {\n        unsigned char header[75];\n        size_t j = 0;\n        memcpy(header + j, mac_sec, md_size);\n        j += md_size;\n        memcpy(header + j, ssl3_pad_1, npad);\n        j += npad;\n        memcpy(header + j, seq, 8);\n        j += 8;\n        header[j++] = rec->type;\n        header[j++] = (unsigned char)(rec->length >> 8);\n        header[j++] = (unsigned char)(rec->length & 0xff);\n        if (ssl3_cbc_digest_record(hash,\n                                   md, &md_size,\n                                   header, rec->input,\n                                   rec->length + md_size, rec->orig_len,\n                                   mac_sec, md_size, 1) <= 0)\n            return 0;\n    } else {\n        unsigned int md_size_u;\n        EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();\n        if (md_ctx == NULL)\n            return 0;\n        rec_char = rec->type;\n        p = md;\n        s2n(rec->length, p);\n        if (EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0\n            || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0\n            || EVP_DigestUpdate(md_ctx, ssl3_pad_1, npad) <= 0\n            || EVP_DigestUpdate(md_ctx, seq, 8) <= 0\n            || EVP_DigestUpdate(md_ctx, &rec_char, 1) <= 0\n            || EVP_DigestUpdate(md_ctx, md, 2) <= 0\n            || EVP_DigestUpdate(md_ctx, rec->input, rec->length) <= 0\n            || EVP_DigestFinal_ex(md_ctx, md, NULL) <= 0\n            || EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0\n            || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0\n            || EVP_DigestUpdate(md_ctx, ssl3_pad_2, npad) <= 0\n            || EVP_DigestUpdate(md_ctx, md, md_size) <= 0\n            || EVP_DigestFinal_ex(md_ctx, md, &md_size_u) <= 0) {\n            EVP_MD_CTX_reset(md_ctx);\n            return 0;\n        }\n        EVP_MD_CTX_free(md_ctx);\n    }\n    ssl3_record_sequence_update(seq);\n    return 1;\n}', 'const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx)\n{\n    if (!ctx)\n        return NULL;\n    return ctx->digest;\n}', 'int EVP_MD_size(const EVP_MD *md)\n{\n    if (!md) {\n        EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);\n        return -1;\n    }\n    return md->md_size;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n    return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\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    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    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); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)\n{\n    unsigned char *tmp_buf;\n    if ((in == NULL) || (in->digest == NULL)) {\n        EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);\n        return 0;\n    }\n#ifndef OPENSSL_NO_ENGINE\n    if (in->engine && !ENGINE_init(in->engine)) {\n        EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);\n        return 0;\n    }\n#endif\n    if (out->digest == in->digest) {\n        tmp_buf = out->md_data;\n        EVP_MD_CTX_set_flags(out, EVP_MD_CTX_FLAG_REUSE);\n    } else\n        tmp_buf = NULL;\n    EVP_MD_CTX_reset(out);\n    memcpy(out, in, sizeof(*out));\n    out->md_data = NULL;\n    out->pctx = NULL;\n    if (in->md_data && out->digest->ctx_size) {\n        if (tmp_buf)\n            out->md_data = tmp_buf;\n        else {\n            out->md_data = OPENSSL_malloc(out->digest->ctx_size);\n            if (out->md_data == NULL) {\n                EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_MALLOC_FAILURE);\n                return 0;\n            }\n        }\n        memcpy(out->md_data, in->md_data, out->digest->ctx_size);\n    }\n    out->update = in->update;\n    if (in->pctx) {\n        out->pctx = EVP_PKEY_CTX_dup(in->pctx);\n        if (!out->pctx) {\n            EVP_MD_CTX_reset(out);\n            return 0;\n        }\n    }\n    if (out->digest->copy)\n        return out->digest->copy(out, in);\n    return 1;\n}', 'int ENGINE_init(ENGINE *e)\n{\n    int ret;\n    if (e == NULL) {\n        ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER);\n        return 0;\n    }\n    if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {\n        ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_MALLOC_FAILURE);\n        return 0;\n    }\n    CRYPTO_THREAD_write_lock(global_engine_lock);\n    ret = engine_unlocked_init(e);\n    CRYPTO_THREAD_unlock(global_engine_lock);\n    return ret;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n    if (pthread_once(once, init) != 0)\n        return 0;\n    return 1;\n}']