Blame crypto/md5/md5_one.c

Packit c4476c
/*
Packit c4476c
 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
 *
Packit c4476c
 * Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
 * this file except in compliance with the License.  You can obtain a copy
Packit c4476c
 * in the file LICENSE in the source distribution or at
Packit c4476c
 * https://www.openssl.org/source/license.html
Packit c4476c
 */
Packit c4476c
Packit c4476c
#include <stdio.h>
Packit c4476c
#include <string.h>
Packit c4476c
#include <openssl/md5.h>
Packit c4476c
#include <openssl/crypto.h>
Packit c4476c
Packit c4476c
#ifdef CHARSET_EBCDIC
Packit c4476c
# include <openssl/ebcdic.h>
Packit c4476c
#endif
Packit c4476c
Packit c4476c
unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)
Packit c4476c
{
Packit c4476c
    MD5_CTX c;
Packit c4476c
    static unsigned char m[MD5_DIGEST_LENGTH];
Packit c4476c
Packit c4476c
    if (md == NULL)
Packit c4476c
        md = m;
Packit c4476c
    if (!MD5_Init(&c))
Packit c4476c
        return NULL;
Packit c4476c
#ifndef CHARSET_EBCDIC
Packit c4476c
    MD5_Update(&c, d, n);
Packit c4476c
#else
Packit c4476c
    {
Packit c4476c
        char temp[1024];
Packit c4476c
        unsigned long chunk;
Packit c4476c
Packit c4476c
        while (n > 0) {
Packit c4476c
            chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
Packit c4476c
            ebcdic2ascii(temp, d, chunk);
Packit c4476c
            MD5_Update(&c, temp, chunk);
Packit c4476c
            n -= chunk;
Packit c4476c
            d += chunk;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
    MD5_Final(md, &c);
Packit c4476c
    OPENSSL_cleanse(&c, sizeof(c)); /* security consideration */
Packit c4476c
    return md;
Packit c4476c
}