2016-05-18 02:51:34 +08:00
|
|
|
/*
|
2020-04-23 20:55:52 +08:00
|
|
|
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2000-08-14 22:05:53 +08:00
|
|
|
*
|
2018-12-06 20:44:44 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:51:34 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2000-08-14 22:05:53 +08:00
|
|
|
*/
|
|
|
|
|
2020-01-09 08:37:28 +08:00
|
|
|
/*
|
|
|
|
* MD4 low level APIs are deprecated for public use, but still ok for
|
|
|
|
* internal use.
|
|
|
|
*/
|
|
|
|
#include "internal/deprecated.h"
|
|
|
|
|
2000-08-14 22:05:53 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <openssl/md4.h>
|
2002-12-03 22:20:44 +08:00
|
|
|
#include <openssl/crypto.h>
|
2000-08-14 22:05:53 +08:00
|
|
|
|
|
|
|
#ifdef CHARSET_EBCDIC
|
2015-01-22 11:40:55 +08:00
|
|
|
# include <openssl/ebcdic.h>
|
2000-08-14 22:05:53 +08:00
|
|
|
#endif
|
|
|
|
|
2004-05-15 19:29:55 +08:00
|
|
|
unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
MD4_CTX c;
|
|
|
|
static unsigned char m[MD4_DIGEST_LENGTH];
|
2000-08-14 22:05:53 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (md == NULL)
|
|
|
|
md = m;
|
|
|
|
if (!MD4_Init(&c))
|
|
|
|
return NULL;
|
2000-08-14 22:05:53 +08:00
|
|
|
#ifndef CHARSET_EBCDIC
|
2015-01-22 11:40:55 +08:00
|
|
|
MD4_Update(&c, d, n);
|
2000-08-14 22:05:53 +08:00
|
|
|
#else
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
char temp[1024];
|
|
|
|
unsigned long chunk;
|
2000-08-14 22:05:53 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
while (n > 0) {
|
|
|
|
chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
|
|
|
|
ebcdic2ascii(temp, d, chunk);
|
|
|
|
MD4_Update(&c, temp, chunk);
|
|
|
|
n -= chunk;
|
|
|
|
d += chunk;
|
|
|
|
}
|
|
|
|
}
|
2000-08-14 22:05:53 +08:00
|
|
|
#endif
|
2015-01-22 11:40:55 +08:00
|
|
|
MD4_Final(md, &c);
|
|
|
|
OPENSSL_cleanse(&c, sizeof(c)); /* security consideration */
|
2017-10-17 22:04:09 +08:00
|
|
|
return md;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|