ssl/record/ssl3_record.c:863: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 842, column 30 is not reachable after line 863, column 13.
Showing all 81 steps of the trace


ssl/record/ssl3_record.c:775:1: start of procedure n_ssl3_mac()
773.   }
774.   
775. > int n_ssl3_mac(SSL *ssl, unsigned char *md, int send)
776.   {
777.       SSL3_RECORD *rec;

ssl/record/ssl3_record.c:785:9: Taking true branch
783.       int t;
784.   
785.       if (send) {
               ^
786.           rec = RECORD_LAYER_get_wrec(&ssl->rlayer);
787.           mac_sec = &(ssl->s3->write_mac_secret[0]);

ssl/record/ssl3_record.c:786:9: 
784.   
785.       if (send) {
786. >         rec = RECORD_LAYER_get_wrec(&ssl->rlayer);
787.           mac_sec = &(ssl->s3->write_mac_secret[0]);
788.           seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);

ssl/record/ssl3_record.c:787:9: 
785.       if (send) {
786.           rec = RECORD_LAYER_get_wrec(&ssl->rlayer);
787. >         mac_sec = &(ssl->s3->write_mac_secret[0]);
788.           seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);
789.           hash = ssl->write_hash;

ssl/record/ssl3_record.c:788:9: 
786.           rec = RECORD_LAYER_get_wrec(&ssl->rlayer);
787.           mac_sec = &(ssl->s3->write_mac_secret[0]);
788. >         seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);
789.           hash = ssl->write_hash;
790.       } else {

ssl/record/ssl3_record.c:789:9: 
787.           mac_sec = &(ssl->s3->write_mac_secret[0]);
788.           seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);
789. >         hash = ssl->write_hash;
790.       } else {
791.           rec = RECORD_LAYER_get_rrec(&ssl->rlayer);

ssl/record/ssl3_record.c:797:5: 
795.       }
796.   
797. >     t = EVP_MD_CTX_size(hash);
798.       if (t < 0)
799.           return -1;

crypto/evp/evp_lib.c:477:1: start of procedure EVP_MD_CTX_md()
  475.   }
  476.   
  477. > const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
  478.   {
  479.       if (!ctx)

crypto/evp/evp_lib.c:479:10: Taking false branch
  477.   const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
  478.   {
  479.       if (!ctx)
                  ^
  480.           return NULL;
  481.       return ctx->digest;

crypto/evp/evp_lib.c:481:5: 
  479.       if (!ctx)
  480.           return NULL;
  481. >     return ctx->digest;
  482.   }
  483.   

crypto/evp/evp_lib.c:482:1: return from a call to EVP_MD_CTX_md
  480.           return NULL;
  481.       return ctx->digest;
  482. > }
  483.   
  484.   EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)

crypto/evp/evp_lib.c:339:1: start of procedure EVP_MD_size()
  337.   }
  338.   
  339. > int EVP_MD_size(const EVP_MD *md)
  340.   {
  341.       if (!md) {

crypto/evp/evp_lib.c:341:10: Taking false branch
  339.   int EVP_MD_size(const EVP_MD *md)
  340.   {
  341.       if (!md) {
                  ^
  342.           EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);
  343.           return -1;

crypto/evp/evp_lib.c:345:5: 
  343.           return -1;
  344.       }
  345. >     return md->md_size;
  346.   }
  347.   

crypto/evp/evp_lib.c:346:1: return from a call to EVP_MD_size
  344.       }
  345.       return md->md_size;
  346. > }
  347.   
  348.   unsigned long EVP_MD_flags(const EVP_MD *md)

ssl/record/ssl3_record.c:798:9: Taking false branch
796.   
797.       t = EVP_MD_CTX_size(hash);
798.       if (t < 0)
               ^
799.           return -1;
800.       md_size = t;

ssl/record/ssl3_record.c:800:5: 
798.       if (t < 0)
799.           return -1;
800. >     md_size = t;
801.       npad = (48 / md_size) * md_size;
802.   

ssl/record/ssl3_record.c:801:5: 
799.           return -1;
800.       md_size = t;
801. >     npad = (48 / md_size) * md_size;
802.   
803.       if (!send &&

ssl/record/ssl3_record.c:803:10: Taking false branch
801.       npad = (48 / md_size) * md_size;
802.   
803.       if (!send &&
                ^
804.           EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&
805.           ssl3_cbc_record_digest_supported(hash)) {

ssl/record/ssl3_record.c:842:9: 
840.           unsigned int md_size_u;
841.           /* Chop the digest off the end :-) */
842. >         EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
843.   
844.           if (md_ctx == NULL)

crypto/evp/digest.c:152:1: start of procedure EVP_MD_CTX_new()
  150.   }
  151.   
  152. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  153.   {
  154.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:154:5: 
  152.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  153.   {
  154. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  155.   }
  156.   

crypto/mem.c:156:1: start of procedure CRYPTO_zalloc()
    154.   }
    155.   
    156. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:158:5: 
    156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158. >     void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       if (ret != NULL)

crypto/mem.c:119:1: start of procedure CRYPTO_malloc()
      117.   }
      118.   
      119. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121.       void *ret = NULL;

crypto/mem.c:121:5: 
      119.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121. >     void *ret = NULL;
      122.   
      123.       if (num <= 0)

crypto/mem.c:123:9: Taking false branch
      121.       void *ret = NULL;
      122.   
      123.       if (num <= 0)
                     ^
      124.           return NULL;
      125.   

crypto/mem.c:126:5: 
      124.           return NULL;
      125.   
      126. >     allow_customize = 0;
      127.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      128.       if (call_malloc_debug) {

crypto/mem.c:136:5: 
      134.       }
      135.   #else
      136. >     (void)file;
      137.       (void)line;
      138.       ret = malloc(num);

crypto/mem.c:137:5: 
      135.   #else
      136.       (void)file;
      137. >     (void)line;
      138.       ret = malloc(num);
      139.   #endif

crypto/mem.c:138:5: 
      136.       (void)file;
      137.       (void)line;
      138. >     ret = malloc(num);
      139.   #endif
      140.   

crypto/mem.c:153:5: 
      151.   #endif
      152.   
      153. >     return ret;
      154.   }
      155.   

crypto/mem.c:154:1: return from a call to CRYPTO_malloc
      152.   
      153.       return ret;
      154. > }
      155.   
      156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:160:9: Taking true branch
    158.       void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       if (ret != NULL)
                   ^
    161.           memset(ret, 0, num);
    162.       return ret;

crypto/mem.c:161:9: 
    159.   
    160.       if (ret != NULL)
    161. >         memset(ret, 0, num);
    162.       return ret;
    163.   }

crypto/mem.c:162:5: 
    160.       if (ret != NULL)
    161.           memset(ret, 0, num);
    162. >     return ret;
    163.   }
    164.   

crypto/mem.c:163:1: return from a call to CRYPTO_zalloc
    161.           memset(ret, 0, num);
    162.       return ret;
    163. > }
    164.   
    165.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:155:1: return from a call to EVP_MD_CTX_new
  153.   {
  154.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  155. > }
  156.   
  157.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

ssl/record/ssl3_record.c:844:13: Taking false branch
842.           EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
843.   
844.           if (md_ctx == NULL)
                   ^
845.               return -1;
846.   

ssl/record/ssl3_record.c:847:9: 
845.               return -1;
846.   
847. >         rec_char = rec->type;
848.           p = md;
849.           s2n(rec->length, p);

ssl/record/ssl3_record.c:848:9: 
846.   
847.           rec_char = rec->type;
848. >         p = md;
849.           s2n(rec->length, p);
850.           if (EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0

ssl/record/ssl3_record.c:849:9: 
847.           rec_char = rec->type;
848.           p = md;
849. >         s2n(rec->length, p);
850.           if (EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0
851.                   || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0

ssl/record/ssl3_record.c:850:13: 
848.           p = md;
849.           s2n(rec->length, p);
850. >         if (EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0
851.                   || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0
852.                   || EVP_DigestUpdate(md_ctx, ssl3_pad_1, npad) <= 0

crypto/evp/digest.c:291:1: start of procedure EVP_MD_CTX_copy_ex()
  289.   }
  290.   
  291. > int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
  292.   {
  293.       unsigned char *tmp_buf;

crypto/evp/digest.c:294:10: Taking false branch
  292.   {
  293.       unsigned char *tmp_buf;
  294.       if ((in == NULL) || (in->digest == NULL)) {
                  ^
  295.           EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);
  296.           return 0;

crypto/evp/digest.c:294:26: Taking false branch
  292.   {
  293.       unsigned char *tmp_buf;
  294.       if ((in == NULL) || (in->digest == NULL)) {
                                  ^
  295.           EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);
  296.           return 0;

crypto/evp/digest.c:300:9: Taking true branch
  298.   #ifndef OPENSSL_NO_ENGINE
  299.       /* Make sure it's safe to copy a digest context using an ENGINE */
  300.       if (in->engine && !ENGINE_init(in->engine)) {
                 ^
  301.           EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);
  302.           return 0;

crypto/evp/digest.c:300:24: 
  298.   #ifndef OPENSSL_NO_ENGINE
  299.       /* Make sure it's safe to copy a digest context using an ENGINE */
  300. >     if (in->engine && !ENGINE_init(in->engine)) {
  301.           EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);
  302.           return 0;

crypto/engine/eng_init.c:126:1: start of procedure ENGINE_init()
    124.   
    125.   /* The API (locked) version of "init" */
    126. > int ENGINE_init(ENGINE *e)
    127.   {
    128.       int ret;

crypto/engine/eng_init.c:129:9: Taking false branch
    127.   {
    128.       int ret;
    129.       if (e == NULL) {
                   ^
    130.           ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER);
    131.           return 0;

crypto/engine/eng_init.c:133:5: 
    131.           return 0;
    132.       }
    133. >     CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
    134.       ret = engine_unlocked_init(e);
    135.       CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);

crypto/lock.c:414:1: start of procedure CRYPTO_lock()
      412.   }
      413.   
      414. > void CRYPTO_lock(int mode, int type, const char *file, int line)
      415.   {
      416.   #ifdef LOCK_DEBUG

crypto/lock.c:441:9: Taking false branch
      439.       }
      440.   #endif
      441.       if (type < 0) {
                     ^
      442.           if (dynlock_lock_callback != NULL) {
      443.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:452:16: Taking true branch
      450.               CRYPTO_destroy_dynlockid(type);
      451.           }
      452.       } else if (locking_callback != NULL)
                            ^
      453.           locking_callback(mode, type, file, line);
      454.   }

crypto/lock.c:453:9: Skipping __function_pointer__(): unresolved function pointer
      451.           }
      452.       } else if (locking_callback != NULL)
      453.           locking_callback(mode, type, file, line);
                     ^
      454.   }
      455.   

crypto/lock.c:441:5: 
      439.       }
      440.   #endif
      441. >     if (type < 0) {
      442.           if (dynlock_lock_callback != NULL) {
      443.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:454:1: return from a call to CRYPTO_lock
      452.       } else if (locking_callback != NULL)
      453.           locking_callback(mode, type, file, line);
      454. > }
      455.   
      456.   int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

crypto/engine/eng_init.c:134:5: 
    132.       }
    133.       CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
    134. >     ret = engine_unlocked_init(e);
    135.       CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
    136.       return ret;

crypto/engine/eng_init.c:61:1: start of procedure engine_unlocked_init()
      59.    * it's already in use). This version is only used internally.
      60.    */
      61. > int engine_unlocked_init(ENGINE *e)
      62.   {
      63.       int to_return = 1;

crypto/engine/eng_init.c:63:5: 
      61.   int engine_unlocked_init(ENGINE *e)
      62.   {
      63. >     int to_return = 1;
      64.   
      65.       if ((e->funct_ref == 0) && e->init)

crypto/engine/eng_init.c:65:10: Taking true branch
      63.       int to_return = 1;
      64.   
      65.       if ((e->funct_ref == 0) && e->init)
                     ^
      66.           /*
      67.            * This is the first functional reference and the engine requires

crypto/engine/eng_init.c:65:32: Taking true branch
      63.       int to_return = 1;
      64.   
      65.       if ((e->funct_ref == 0) && e->init)
                                           ^
      66.           /*
      67.            * This is the first functional reference and the engine requires

crypto/engine/eng_init.c:70:9: Skipping __function_pointer__(): unresolved function pointer
      68.            * initialisation so we do it now.
      69.            */
      70.           to_return = e->init(e);
                    ^
      71.       if (to_return) {
      72.           /*

crypto/engine/eng_init.c:71:9: Taking false branch
      69.            */
      70.           to_return = e->init(e);
      71.       if (to_return) {
                    ^
      72.           /*
      73.            * OK, we return a functional reference which is also a structural

crypto/engine/eng_init.c:81:5: 
      79.           engine_ref_debug(e, 1, 1);
      80.       }
      81. >     return to_return;
      82.   }
      83.   

crypto/engine/eng_init.c:82:1: return from a call to engine_unlocked_init
      80.       }
      81.       return to_return;
      82. > }
      83.   
      84.   /*

crypto/engine/eng_init.c:135:5: 
    133.       CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
    134.       ret = engine_unlocked_init(e);
    135. >     CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
    136.       return ret;
    137.   }

crypto/lock.c:414:1: start of procedure CRYPTO_lock()
      412.   }
      413.   
      414. > void CRYPTO_lock(int mode, int type, const char *file, int line)
      415.   {
      416.   #ifdef LOCK_DEBUG

crypto/lock.c:441:9: Taking false branch
      439.       }
      440.   #endif
      441.       if (type < 0) {
                     ^
      442.           if (dynlock_lock_callback != NULL) {
      443.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:452:16: Taking true branch
      450.               CRYPTO_destroy_dynlockid(type);
      451.           }
      452.       } else if (locking_callback != NULL)
                            ^
      453.           locking_callback(mode, type, file, line);
      454.   }

crypto/lock.c:453:9: Skipping __function_pointer__(): unresolved function pointer
      451.           }
      452.       } else if (locking_callback != NULL)
      453.           locking_callback(mode, type, file, line);
                     ^
      454.   }
      455.   

crypto/lock.c:441:5: 
      439.       }
      440.   #endif
      441. >     if (type < 0) {
      442.           if (dynlock_lock_callback != NULL) {
      443.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:454:1: return from a call to CRYPTO_lock
      452.       } else if (locking_callback != NULL)
      453.           locking_callback(mode, type, file, line);
      454. > }
      455.   
      456.   int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

crypto/engine/eng_init.c:136:5: 
    134.       ret = engine_unlocked_init(e);
    135.       CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
    136. >     return ret;
    137.   }
    138.   

crypto/engine/eng_init.c:137:1: return from a call to ENGINE_init
    135.       CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
    136.       return ret;
    137. > }
    138.   
    139.   /* The API (locked) version of "finish" */

crypto/evp/digest.c:300:24: Taking true branch
  298.   #ifndef OPENSSL_NO_ENGINE
  299.       /* Make sure it's safe to copy a digest context using an ENGINE */
  300.       if (in->engine && !ENGINE_init(in->engine)) {
                                ^
  301.           EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);
  302.           return 0;

crypto/evp/digest.c:301:9: Skipping ERR_put_error(): empty list of specs
  299.       /* Make sure it's safe to copy a digest context using an ENGINE */
  300.       if (in->engine && !ENGINE_init(in->engine)) {
  301.           EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);
                 ^
  302.           return 0;
  303.       }

crypto/evp/digest.c:302:9: 
  300.       if (in->engine && !ENGINE_init(in->engine)) {
  301.           EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);
  302. >         return 0;
  303.       }
  304.   #endif

crypto/evp/digest.c:348:1: return from a call to EVP_MD_CTX_copy_ex
  346.   
  347.       return 1;
  348. > }
  349.   
  350.   int EVP_Digest(const void *data, size_t count,

ssl/record/ssl3_record.c:850:13: Taking true branch
848.           p = md;
849.           s2n(rec->length, p);
850.           if (EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0
                   ^
851.                   || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0
852.                   || EVP_DigestUpdate(md_ctx, ssl3_pad_1, npad) <= 0

ssl/record/ssl3_record.c:863:13: Skipping EVP_MD_CTX_reset(): empty list of specs
861.                   || EVP_DigestUpdate(md_ctx, md, md_size) <= 0
862.                   || EVP_DigestFinal_ex(md_ctx, md, &md_size_u) <= 0) {
863.               EVP_MD_CTX_reset(md_ctx);
                   ^
864.               return -1;
865.           }

int n_ssl3_mac(SSL *ssl, unsigned char *md, int send)
{
    SSL3_RECORD *rec;
    unsigned char *mac_sec, *seq;
    const EVP_MD_CTX *hash;
    unsigned char *p, rec_char;
    size_t md_size;
    int npad;
    int t;
    if (send) {
        rec = RECORD_LAYER_get_wrec(&ssl->rlayer);
        mac_sec = &(ssl->s3->write_mac_secret[0]);
        seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);
        hash = ssl->write_hash;
    } else {
        rec = RECORD_LAYER_get_rrec(&ssl->rlayer);
        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 -1;
    md_size = t;
    npad = (48 / md_size) * md_size;
    if (!send &&
        EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&
        ssl3_cbc_record_digest_supported(hash)) {
        unsigned char header[75];
        unsigned 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++] = rec->length >> 8;
        header[j++] = 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 -1;
    } else {
        unsigned int md_size_u;
        EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
        if (md_ctx == NULL)
            return -1;
        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 -1;
        }
        md_size = md_size_u;
        EVP_MD_CTX_free(md_ctx);
    }
    ssl3_record_sequence_update(seq);
    return (md_size);
}
['int n_ssl3_mac(SSL *ssl, unsigned char *md, int send)\n{\n    SSL3_RECORD *rec;\n    unsigned char *mac_sec, *seq;\n    const EVP_MD_CTX *hash;\n    unsigned char *p, rec_char;\n    size_t md_size;\n    int npad;\n    int t;\n    if (send) {\n        rec = RECORD_LAYER_get_wrec(&ssl->rlayer);\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        rec = RECORD_LAYER_get_rrec(&ssl->rlayer);\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 -1;\n    md_size = t;\n    npad = (48 / md_size) * md_size;\n    if (!send &&\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        unsigned 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++] = rec->length >> 8;\n        header[j++] = 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 -1;\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 -1;\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 -1;\n        }\n        md_size = md_size_u;\n        EVP_MD_CTX_free(md_ctx);\n    }\n    ssl3_record_sequence_update(seq);\n    return (md_size);\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    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 (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 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    CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);\n    ret = engine_unlocked_init(e);\n    CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);\n    return ret;\n}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n{\n#ifdef LOCK_DEBUG\n    {\n        CRYPTO_THREADID id;\n        char *rw_text, *operation_text;\n        if (mode & CRYPTO_LOCK)\n            operation_text = "lock  ";\n        else if (mode & CRYPTO_UNLOCK)\n            operation_text = "unlock";\n        else\n            operation_text = "ERROR ";\n        if (mode & CRYPTO_READ)\n            rw_text = "r";\n        else if (mode & CRYPTO_WRITE)\n            rw_text = "w";\n        else\n            rw_text = "ERROR";\n        CRYPTO_THREADID_current(&id);\n        fprintf(stderr, "lock:%08lx:(%s)%s %-18s %s:%d\\n",\n                CRYPTO_THREADID_hash(&id), rw_text, operation_text,\n                CRYPTO_get_lock_name(type), file, line);\n    }\n#endif\n    if (type < 0) {\n        if (dynlock_lock_callback != NULL) {\n            struct CRYPTO_dynlock_value *pointer\n                = CRYPTO_get_dynlock_value(type);\n            OPENSSL_assert(pointer != NULL);\n            dynlock_lock_callback(mode, pointer, file, line);\n            CRYPTO_destroy_dynlockid(type);\n        }\n    } else if (locking_callback != NULL)\n        locking_callback(mode, type, file, line);\n}', 'int engine_unlocked_init(ENGINE *e)\n{\n    int to_return = 1;\n    if ((e->funct_ref == 0) && e->init)\n        to_return = e->init(e);\n    if (to_return) {\n        e->struct_ref++;\n        e->funct_ref++;\n        engine_ref_debug(e, 0, 1);\n        engine_ref_debug(e, 1, 1);\n    }\n    return to_return;\n}']