1/* 2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the Apache License 2.0 (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10/* 11 * MD5 low level APIs are deprecated for public use, but still ok for 12 * internal use. 13 */ 14#include "internal/deprecated.h" 15 16#include <stdio.h> 17#include <string.h> 18#include <openssl/md5.h> 19#include <openssl/crypto.h> 20 21#ifdef CHARSET_EBCDIC 22# include <openssl/ebcdic.h> 23#endif 24 25unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md) 26{ 27 MD5_CTX c; 28 static unsigned char m[MD5_DIGEST_LENGTH]; 29 30 if (md == NULL) 31 md = m; 32 if (!MD5_Init(&c)) 33 return NULL; 34#ifndef CHARSET_EBCDIC 35 MD5_Update(&c, d, n); 36#else 37 { 38 char temp[1024]; 39 unsigned long chunk; 40 41 while (n > 0) { 42 chunk = (n > sizeof(temp)) ? sizeof(temp) : n; 43 ebcdic2ascii(temp, d, chunk); 44 MD5_Update(&c, temp, chunk); 45 n -= chunk; 46 d += chunk; 47 } 48 } 49#endif 50 MD5_Final(md, &c); 51 OPENSSL_cleanse(&c, sizeof(c)); /* security consideration */ 52 return md; 53} 54