ssl/record/ssl3_record.c:1376: error: BUFFER_OVERRUN_L2
  Offset added: [71-min(70, `ssl->s3->read_mac_secret_size`), `ssl->s3->read_mac_secret_size` + 123] (⇐ [64, 128] + [7-min(70, `ssl->s3->read_mac_secret_size`), `ssl->s3->read_mac_secret_size` - 5]) Size: 104 by call to `ssl3_cbc_digest_record`.
Showing all 8 steps of the trace


ssl/record/ssl3_record.c:1313:1: Array declaration
1311.   }
1312.   
1313. > int tls1_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int sending)
1314.   {
1315.       unsigned char *seq;

ssl/record/ssl3_record.c:1376:13: Call
1374.            */
1375.           /* Final param == not SSLv3 */
1376.           if (ssl3_cbc_digest_record(mac_ctx,
                    ^
1377.                                      md, &md_size,
1378.                                      header, rec->input,

ssl/s3_cbc.c:144:5: <Offset trace>
142.       void (*md_final_raw) (void *ctx, unsigned char *md_out);
143.       void (*md_transform) (void *ctx, const unsigned char *block);
144.       size_t md_size, md_block_size = 64;
           ^
145.       size_t sslv3_pad_length = 40, header_length, variance_blocks,
146.           len, max_mac_bytes, num_blocks,

ssl/s3_cbc.c:144:5: Assignment
  142.       void (*md_final_raw) (void *ctx, unsigned char *md_out);
  143.       void (*md_transform) (void *ctx, const unsigned char *block);
  144.       size_t md_size, md_block_size = 64;
             ^
  145.       size_t sslv3_pad_length = 40, header_length, variance_blocks,
  146.           len, max_mac_bytes, num_blocks,

ssl/s3_cbc.c:377:13: Assignment
  375.                   return 0;
  376.               }
  377.               overhang = header_length - md_block_size;
                     ^
  378.               md_transform(md_state.c, header);
  379.               memcpy(first_block, header + md_block_size, overhang);

ssl/s3_cbc.c:128:1: <Length trace>
126.    * Returns 1 on success or 0 on error
127.    */
128. > int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx,
129.                              unsigned char *md_out,
130.                              size_t *md_out_size,

ssl/s3_cbc.c:128:1: Parameter `*header`
  126.    * Returns 1 on success or 0 on error
  127.    */
  128. > int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx,
  129.                              unsigned char *md_out,
  130.                              size_t *md_out_size,

ssl/s3_cbc.c:379:13: Array access: Offset added: [71-min(70, ssl->s3->read_mac_secret_size), ssl->s3->read_mac_secret_size + 123] (⇐ [64, 128] + [7-min(70, ssl->s3->read_mac_secret_size), ssl->s3->read_mac_secret_size - 5]) Size: 104 by call to `ssl3_cbc_digest_record` 
  377.               overhang = header_length - md_block_size;
  378.               md_transform(md_state.c, header);
  379.               memcpy(first_block, header + md_block_size, overhang);
                     ^
  380.               memcpy(first_block + overhang, data, md_block_size - overhang);
  381.               md_transform(md_state.c, first_block);

int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx,
                           unsigned char *md_out,
                           size_t *md_out_size,
                           const unsigned char header[13],
                           const unsigned char *data,
                           size_t data_plus_mac_size,
                           size_t data_plus_mac_plus_padding_size,
                           const unsigned char *mac_secret,
                           size_t mac_secret_length, char is_sslv3)
{
    union {
        double align;
        unsigned char c[sizeof(LARGEST_DIGEST_CTX)];
    } md_state;
    void (*md_final_raw) (void *ctx, unsigned char *md_out);
    void (*md_transform) (void *ctx, const unsigned char *block);
    size_t md_size, md_block_size = 64;
    size_t sslv3_pad_length = 40, header_length, variance_blocks,
        len, max_mac_bytes, num_blocks,
        num_starting_blocks, k, mac_end_offset, c, index_a, index_b;
    size_t bits;
    unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];
    unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];
    unsigned char first_block[MAX_HASH_BLOCK_SIZE];
    unsigned char mac_out[EVP_MAX_MD_SIZE];
    size_t i, j;
    unsigned md_out_size_u;
    EVP_MD_CTX *md_ctx = NULL;
    size_t md_length_size = 8;
    char length_is_big_endian = 1;
    int ret;
    if (!ossl_assert(data_plus_mac_plus_padding_size < 1024 * 1024))
        return 0;
    switch (EVP_MD_CTX_type(ctx)) {
    case NID_md5:
        if (MD5_Init((MD5_CTX *)md_state.c) <= 0)
            return 0;
        md_final_raw = tls1_md5_final_raw;
        md_transform =
            (void (*)(void *ctx, const unsigned char *block))MD5_Transform;
        md_size = 16;
        sslv3_pad_length = 48;
        length_is_big_endian = 0;
        break;
    case NID_sha1:
        if (SHA1_Init((SHA_CTX *)md_state.c) <= 0)
            return 0;
        md_final_raw = tls1_sha1_final_raw;
        md_transform =
            (void (*)(void *ctx, const unsigned char *block))SHA1_Transform;
        md_size = 20;
        break;
    case NID_sha224:
        if (SHA224_Init((SHA256_CTX *)md_state.c) <= 0)
            return 0;
        md_final_raw = tls1_sha256_final_raw;
        md_transform =
            (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;
        md_size = 224 / 8;
        break;
    case NID_sha256:
        if (SHA256_Init((SHA256_CTX *)md_state.c) <= 0)
            return 0;
        md_final_raw = tls1_sha256_final_raw;
        md_transform =
            (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;
        md_size = 32;
        break;
    case NID_sha384:
        if (SHA384_Init((SHA512_CTX *)md_state.c) <= 0)
            return 0;
        md_final_raw = tls1_sha512_final_raw;
        md_transform =
            (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;
        md_size = 384 / 8;
        md_block_size = 128;
        md_length_size = 16;
        break;
    case NID_sha512:
        if (SHA512_Init((SHA512_CTX *)md_state.c) <= 0)
            return 0;
        md_final_raw = tls1_sha512_final_raw;
        md_transform =
            (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;
        md_size = 64;
        md_block_size = 128;
        md_length_size = 16;
        break;
    default:
        if (md_out_size != NULL)
            *md_out_size = 0;
        return ossl_assert(0);
    }
    if (!ossl_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES)
            || !ossl_assert(md_block_size <= MAX_HASH_BLOCK_SIZE)
            || !ossl_assert(md_size <= EVP_MAX_MD_SIZE))
        return 0;
    header_length = 13;
    if (is_sslv3) {
        header_length = mac_secret_length + sslv3_pad_length + 8    +
            1    +
            2   ;
    }
    variance_blocks = is_sslv3 ? 2 : ( ((255 + 1 + md_size + md_block_size - 1) / md_block_size) + 1);
    len = data_plus_mac_plus_padding_size + header_length;
    max_mac_bytes = len - md_size - 1;
    num_blocks =
        (max_mac_bytes + 1 + md_length_size + md_block_size -
         1) / md_block_size;
    num_starting_blocks = 0;
    k = 0;
    mac_end_offset = data_plus_mac_size + header_length - md_size;
    c = mac_end_offset % md_block_size;
    index_a = mac_end_offset / md_block_size;
    index_b = (mac_end_offset + md_length_size) / md_block_size;
    if (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0)) {
        num_starting_blocks = num_blocks - variance_blocks;
        k = md_block_size * num_starting_blocks;
    }
    bits = 8 * mac_end_offset;
    if (!is_sslv3) {
        bits += 8 * md_block_size;
        memset(hmac_pad, 0, md_block_size);
        if (!ossl_assert(mac_secret_length <= sizeof(hmac_pad)))
            return 0;
        memcpy(hmac_pad, mac_secret, mac_secret_length);
        for (i = 0; i < md_block_size; i++)
            hmac_pad[i] ^= 0x36;
        md_transform(md_state.c, hmac_pad);
    }
    if (length_is_big_endian) {
        memset(length_bytes, 0, md_length_size - 4);
        length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24);
        length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16);
        length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8);
        length_bytes[md_length_size - 1] = (unsigned char)bits;
    } else {
        memset(length_bytes, 0, md_length_size);
        length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24);
        length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16);
        length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8);
        length_bytes[md_length_size - 8] = (unsigned char)bits;
    }
    if (k > 0) {
        if (is_sslv3) {
            size_t overhang;
            if (header_length <= md_block_size) {
                return 0;
            }
            overhang = header_length - md_block_size;
            md_transform(md_state.c, header);
            memcpy(first_block, header + md_block_size, overhang);
            memcpy(first_block + overhang, data, md_block_size - overhang);
            md_transform(md_state.c, first_block);
            for (i = 1; i < k / md_block_size - 1; i++)
                md_transform(md_state.c, data + md_block_size * i - overhang);
        } else {
            memcpy(first_block, header, 13);
            memcpy(first_block + 13, data, md_block_size - 13);
            md_transform(md_state.c, first_block);
            for (i = 1; i < k / md_block_size; i++)
                md_transform(md_state.c, data + md_block_size * i - 13);
        }
    }
    memset(mac_out, 0, sizeof(mac_out));
    for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks;
         i++) {
        unsigned char block[MAX_HASH_BLOCK_SIZE];
        unsigned char is_block_a = constant_time_eq_8_s(i, index_a);
        unsigned char is_block_b = constant_time_eq_8_s(i, index_b);
        for (j = 0; j < md_block_size; j++) {
            unsigned char b = 0, is_past_c, is_past_cp1;
            if (k < header_length)
                b = header[k];
            else if (k < data_plus_mac_plus_padding_size + header_length)
                b = data[k - header_length];
            k++;
            is_past_c = is_block_a & constant_time_ge_8_s(j, c);
            is_past_cp1 = is_block_a & constant_time_ge_8_s(j, c + 1);
            b = constant_time_select_8(is_past_c, 0x80, b);
            b = b & ~is_past_cp1;
            b &= ~is_block_b | is_block_a;
            if (j >= md_block_size - md_length_size) {
                b = constant_time_select_8(is_block_b,
                                           length_bytes[j -
                                                        (md_block_size -
                                                         md_length_size)], b);
            }
            block[j] = b;
        }
        md_transform(md_state.c, block);
        md_final_raw(md_state.c, block);
        for (j = 0; j < md_size; j++)
            mac_out[j] |= block[j] & is_block_b;
    }
    md_ctx = EVP_MD_CTX_new();
    if (md_ctx == NULL)
        goto err;
    if (EVP_DigestInit_ex(md_ctx, EVP_MD_CTX_md(ctx), NULL   ) <= 0)
        goto err;
    if (is_sslv3) {
        memset(hmac_pad, 0x5c, sslv3_pad_length);
        if (EVP_DigestUpdate(md_ctx, mac_secret, mac_secret_length) <= 0
            || EVP_DigestUpdate(md_ctx, hmac_pad, sslv3_pad_length) <= 0
            || EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0)
            goto err;
    } else {
        for (i = 0; i < md_block_size; i++)
            hmac_pad[i] ^= 0x6a;
        if (EVP_DigestUpdate(md_ctx, hmac_pad, md_block_size) <= 0
            || EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0)
            goto err;
    }
    ret = EVP_DigestFinal(md_ctx, md_out, &md_out_size_u);
    if (ret && md_out_size)
        *md_out_size = md_out_size_u;
    EVP_MD_CTX_free(md_ctx);
    return 1;
 err:
    EVP_MD_CTX_free(md_ctx);
    return 0;
}
['int tls1_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int sending)\n{\n    unsigned char *seq;\n    EVP_MD_CTX *hash;\n    size_t md_size;\n    int i;\n    EVP_MD_CTX *hmac = NULL, *mac_ctx;\n    unsigned char header[13];\n    int stream_mac = (sending ? (ssl->mac_flags & SSL_MAC_FLAG_WRITE_MAC_STREAM)\n                      : (ssl->mac_flags & SSL_MAC_FLAG_READ_MAC_STREAM));\n    int t;\n    if (sending) {\n        seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);\n        hash = ssl->write_hash;\n    } else {\n        seq = RECORD_LAYER_get_read_sequence(&ssl->rlayer);\n        hash = ssl->read_hash;\n    }\n    t = EVP_MD_CTX_size(hash);\n    if (!ossl_assert(t >= 0))\n        return 0;\n    md_size = t;\n    if (stream_mac) {\n        mac_ctx = hash;\n    } else {\n        hmac = EVP_MD_CTX_new();\n        if (hmac == NULL || !EVP_MD_CTX_copy(hmac, hash)) {\n            EVP_MD_CTX_free(hmac);\n            return 0;\n        }\n        mac_ctx = hmac;\n    }\n    if (SSL_IS_DTLS(ssl)) {\n        unsigned char dtlsseq[8], *p = dtlsseq;\n        s2n(sending ? DTLS_RECORD_LAYER_get_w_epoch(&ssl->rlayer) :\n            DTLS_RECORD_LAYER_get_r_epoch(&ssl->rlayer), p);\n        memcpy(p, &seq[2], 6);\n        memcpy(header, dtlsseq, 8);\n    } else\n        memcpy(header, seq, 8);\n    header[8] = rec->type;\n    header[9] = (unsigned char)(ssl->version >> 8);\n    header[10] = (unsigned char)(ssl->version);\n    header[11] = (unsigned char)(rec->length >> 8);\n    header[12] = (unsigned char)(rec->length & 0xff);\n    if (!sending && !SSL_READ_ETM(ssl) &&\n        EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n        ssl3_cbc_record_digest_supported(mac_ctx)) {\n        if (ssl3_cbc_digest_record(mac_ctx,\n                                   md, &md_size,\n                                   header, rec->input,\n                                   rec->length + md_size, rec->orig_len,\n                                   ssl->s3->read_mac_secret,\n                                   ssl->s3->read_mac_secret_size, 0) <= 0) {\n            EVP_MD_CTX_free(hmac);\n            return 0;\n        }\n    } else {\n        if (EVP_DigestSignUpdate(mac_ctx, header, sizeof(header)) <= 0\n            || EVP_DigestSignUpdate(mac_ctx, rec->input, rec->length) <= 0\n            || EVP_DigestSignFinal(mac_ctx, md, &md_size) <= 0) {\n            EVP_MD_CTX_free(hmac);\n            return 0;\n        }\n    }\n    EVP_MD_CTX_free(hmac);\n    OSSL_TRACE_BEGIN(TLS) {\n        BIO_printf(trc_out, "seq:\\n");\n        BIO_dump_indent(trc_out, seq, 8, 4);\n        BIO_printf(trc_out, "rec:\\n");\n        BIO_dump_indent(trc_out, rec->data, rec->length, 4);\n    } OSSL_TRACE_END(TLS);\n    if (!SSL_IS_DTLS(ssl)) {\n        for (i = 7; i >= 0; i--) {\n            ++seq[i];\n            if (seq[i] != 0)\n                break;\n        }\n    }\n    OSSL_TRACE_BEGIN(TLS) {\n        BIO_printf(trc_out, "md:\\n");\n        BIO_dump_indent(trc_out, md, md_size, 4);\n    } OSSL_TRACE_END(TLS);\n    return 1;\n}', 'int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx,\n                           unsigned char *md_out,\n                           size_t *md_out_size,\n                           const unsigned char header[13],\n                           const unsigned char *data,\n                           size_t data_plus_mac_size,\n                           size_t data_plus_mac_plus_padding_size,\n                           const unsigned char *mac_secret,\n                           size_t mac_secret_length, char is_sslv3)\n{\n    union {\n        double align;\n        unsigned char c[sizeof(LARGEST_DIGEST_CTX)];\n    } md_state;\n    void (*md_final_raw) (void *ctx, unsigned char *md_out);\n    void (*md_transform) (void *ctx, const unsigned char *block);\n    size_t md_size, md_block_size = 64;\n    size_t sslv3_pad_length = 40, header_length, variance_blocks,\n        len, max_mac_bytes, num_blocks,\n        num_starting_blocks, k, mac_end_offset, c, index_a, index_b;\n    size_t bits;\n    unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];\n    unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];\n    unsigned char first_block[MAX_HASH_BLOCK_SIZE];\n    unsigned char mac_out[EVP_MAX_MD_SIZE];\n    size_t i, j;\n    unsigned md_out_size_u;\n    EVP_MD_CTX *md_ctx = NULL;\n    size_t md_length_size = 8;\n    char length_is_big_endian = 1;\n    int ret;\n    if (!ossl_assert(data_plus_mac_plus_padding_size < 1024 * 1024))\n        return 0;\n    switch (EVP_MD_CTX_type(ctx)) {\n    case NID_md5:\n        if (MD5_Init((MD5_CTX *)md_state.c) <= 0)\n            return 0;\n        md_final_raw = tls1_md5_final_raw;\n        md_transform =\n            (void (*)(void *ctx, const unsigned char *block))MD5_Transform;\n        md_size = 16;\n        sslv3_pad_length = 48;\n        length_is_big_endian = 0;\n        break;\n    case NID_sha1:\n        if (SHA1_Init((SHA_CTX *)md_state.c) <= 0)\n            return 0;\n        md_final_raw = tls1_sha1_final_raw;\n        md_transform =\n            (void (*)(void *ctx, const unsigned char *block))SHA1_Transform;\n        md_size = 20;\n        break;\n    case NID_sha224:\n        if (SHA224_Init((SHA256_CTX *)md_state.c) <= 0)\n            return 0;\n        md_final_raw = tls1_sha256_final_raw;\n        md_transform =\n            (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;\n        md_size = 224 / 8;\n        break;\n    case NID_sha256:\n        if (SHA256_Init((SHA256_CTX *)md_state.c) <= 0)\n            return 0;\n        md_final_raw = tls1_sha256_final_raw;\n        md_transform =\n            (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;\n        md_size = 32;\n        break;\n    case NID_sha384:\n        if (SHA384_Init((SHA512_CTX *)md_state.c) <= 0)\n            return 0;\n        md_final_raw = tls1_sha512_final_raw;\n        md_transform =\n            (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;\n        md_size = 384 / 8;\n        md_block_size = 128;\n        md_length_size = 16;\n        break;\n    case NID_sha512:\n        if (SHA512_Init((SHA512_CTX *)md_state.c) <= 0)\n            return 0;\n        md_final_raw = tls1_sha512_final_raw;\n        md_transform =\n            (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;\n        md_size = 64;\n        md_block_size = 128;\n        md_length_size = 16;\n        break;\n    default:\n        if (md_out_size != NULL)\n            *md_out_size = 0;\n        return ossl_assert(0);\n    }\n    if (!ossl_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES)\n            || !ossl_assert(md_block_size <= MAX_HASH_BLOCK_SIZE)\n            || !ossl_assert(md_size <= EVP_MAX_MD_SIZE))\n        return 0;\n    header_length = 13;\n    if (is_sslv3) {\n        header_length = mac_secret_length + sslv3_pad_length + 8    +\n            1    +\n            2   ;\n    }\n    variance_blocks = is_sslv3 ? 2 : ( ((255 + 1 + md_size + md_block_size - 1) / md_block_size) + 1);\n    len = data_plus_mac_plus_padding_size + header_length;\n    max_mac_bytes = len - md_size - 1;\n    num_blocks =\n        (max_mac_bytes + 1 + md_length_size + md_block_size -\n         1) / md_block_size;\n    num_starting_blocks = 0;\n    k = 0;\n    mac_end_offset = data_plus_mac_size + header_length - md_size;\n    c = mac_end_offset % md_block_size;\n    index_a = mac_end_offset / md_block_size;\n    index_b = (mac_end_offset + md_length_size) / md_block_size;\n    if (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0)) {\n        num_starting_blocks = num_blocks - variance_blocks;\n        k = md_block_size * num_starting_blocks;\n    }\n    bits = 8 * mac_end_offset;\n    if (!is_sslv3) {\n        bits += 8 * md_block_size;\n        memset(hmac_pad, 0, md_block_size);\n        if (!ossl_assert(mac_secret_length <= sizeof(hmac_pad)))\n            return 0;\n        memcpy(hmac_pad, mac_secret, mac_secret_length);\n        for (i = 0; i < md_block_size; i++)\n            hmac_pad[i] ^= 0x36;\n        md_transform(md_state.c, hmac_pad);\n    }\n    if (length_is_big_endian) {\n        memset(length_bytes, 0, md_length_size - 4);\n        length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24);\n        length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16);\n        length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8);\n        length_bytes[md_length_size - 1] = (unsigned char)bits;\n    } else {\n        memset(length_bytes, 0, md_length_size);\n        length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24);\n        length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16);\n        length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8);\n        length_bytes[md_length_size - 8] = (unsigned char)bits;\n    }\n    if (k > 0) {\n        if (is_sslv3) {\n            size_t overhang;\n            if (header_length <= md_block_size) {\n                return 0;\n            }\n            overhang = header_length - md_block_size;\n            md_transform(md_state.c, header);\n            memcpy(first_block, header + md_block_size, overhang);\n            memcpy(first_block + overhang, data, md_block_size - overhang);\n            md_transform(md_state.c, first_block);\n            for (i = 1; i < k / md_block_size - 1; i++)\n                md_transform(md_state.c, data + md_block_size * i - overhang);\n        } else {\n            memcpy(first_block, header, 13);\n            memcpy(first_block + 13, data, md_block_size - 13);\n            md_transform(md_state.c, first_block);\n            for (i = 1; i < k / md_block_size; i++)\n                md_transform(md_state.c, data + md_block_size * i - 13);\n        }\n    }\n    memset(mac_out, 0, sizeof(mac_out));\n    for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks;\n         i++) {\n        unsigned char block[MAX_HASH_BLOCK_SIZE];\n        unsigned char is_block_a = constant_time_eq_8_s(i, index_a);\n        unsigned char is_block_b = constant_time_eq_8_s(i, index_b);\n        for (j = 0; j < md_block_size; j++) {\n            unsigned char b = 0, is_past_c, is_past_cp1;\n            if (k < header_length)\n                b = header[k];\n            else if (k < data_plus_mac_plus_padding_size + header_length)\n                b = data[k - header_length];\n            k++;\n            is_past_c = is_block_a & constant_time_ge_8_s(j, c);\n            is_past_cp1 = is_block_a & constant_time_ge_8_s(j, c + 1);\n            b = constant_time_select_8(is_past_c, 0x80, b);\n            b = b & ~is_past_cp1;\n            b &= ~is_block_b | is_block_a;\n            if (j >= md_block_size - md_length_size) {\n                b = constant_time_select_8(is_block_b,\n                                           length_bytes[j -\n                                                        (md_block_size -\n                                                         md_length_size)], b);\n            }\n            block[j] = b;\n        }\n        md_transform(md_state.c, block);\n        md_final_raw(md_state.c, block);\n        for (j = 0; j < md_size; j++)\n            mac_out[j] |= block[j] & is_block_b;\n    }\n    md_ctx = EVP_MD_CTX_new();\n    if (md_ctx == NULL)\n        goto err;\n    if (EVP_DigestInit_ex(md_ctx, EVP_MD_CTX_md(ctx), NULL   ) <= 0)\n        goto err;\n    if (is_sslv3) {\n        memset(hmac_pad, 0x5c, sslv3_pad_length);\n        if (EVP_DigestUpdate(md_ctx, mac_secret, mac_secret_length) <= 0\n            || EVP_DigestUpdate(md_ctx, hmac_pad, sslv3_pad_length) <= 0\n            || EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0)\n            goto err;\n    } else {\n        for (i = 0; i < md_block_size; i++)\n            hmac_pad[i] ^= 0x6a;\n        if (EVP_DigestUpdate(md_ctx, hmac_pad, md_block_size) <= 0\n            || EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0)\n            goto err;\n    }\n    ret = EVP_DigestFinal(md_ctx, md_out, &md_out_size_u);\n    if (ret && md_out_size)\n        *md_out_size = md_out_size_u;\n    EVP_MD_CTX_free(md_ctx);\n    return 1;\n err:\n    EVP_MD_CTX_free(md_ctx);\n    return 0;\n}']