md4_one.c revision 302408
120253Sjoerg/* crypto/md4/md4_one.c */ 220302Sjoerg/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 320302Sjoerg * All rights reserved. 420253Sjoerg * 520253Sjoerg * This package is an SSL implementation written 620253Sjoerg * by Eric Young (eay@cryptsoft.com). 720253Sjoerg * The implementation was written so as to conform with Netscapes SSL. 820253Sjoerg * 920302Sjoerg * This library is free for commercial and non-commercial use as long as 1020253Sjoerg * the following conditions are aheared to. The following conditions 1120253Sjoerg * apply to all code found in this distribution, be it the RC4, RSA, 1220253Sjoerg * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1320253Sjoerg * included with this distribution is covered by the same copyright terms 1420302Sjoerg * except that the holder is Tim Hudson (tjh@cryptsoft.com). 1520253Sjoerg * 1620253Sjoerg * Copyright remains Eric Young's, and as such any Copyright notices in 1720302Sjoerg * the code are not to be removed. 1820253Sjoerg * If this package is used in a product, Eric Young should be given attribution 1920253Sjoerg * as the author of the parts of the library used. 2020253Sjoerg * This can be in the form of a textual message at program startup or 2120253Sjoerg * in documentation (online or textual) provided with the package. 2220253Sjoerg * 2320253Sjoerg * Redistribution and use in source and binary forms, with or without 2420253Sjoerg * modification, are permitted provided that the following conditions 2520253Sjoerg * are met: 2620253Sjoerg * 1. Redistributions of source code must retain the copyright 2730259Scharnier * notice, this list of conditions and the following disclaimer. 2830259Scharnier * 2. Redistributions in binary form must reproduce the above copyright 2950479Speter * notice, this list of conditions and the following disclaimer in the 3030259Scharnier * documentation and/or other materials provided with the distribution. 3130259Scharnier * 3. All advertising materials mentioning features or use of this software 32242349Sbapt * must display the following acknowledgement: 33242349Sbapt * "This product includes cryptographic software written by 34242349Sbapt * Eric Young (eay@cryptsoft.com)" 3520253Sjoerg * The word 'cryptographic' can be left out if the rouines from the library 3620253Sjoerg * being used are not cryptographic related :-). 3720253Sjoerg * 4. If you include any Windows specific code (or a derivative thereof) from 3844229Sdavidn * the apps directory (application code) you must include an acknowledgement: 3920253Sjoerg * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 4020253Sjoerg * 4120253Sjoerg * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4244229Sdavidn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4344229Sdavidn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4420253Sjoerg * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4544229Sdavidn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4644229Sdavidn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4744229Sdavidn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4844229Sdavidn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49243898Seadler * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50243898Seadler * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51243898Seadler * SUCH DAMAGE. 52243898Seadler * 53243898Seadler * The licence and distribution terms for any publically available version or 5444229Sdavidn * derivative of this code cannot be changed. i.e. this code cannot simply be 5544229Sdavidn * copied and put under another distribution licence 5644229Sdavidn * [including the GNU Public Licence.] 5744229Sdavidn */ 5844229Sdavidn 5944229Sdavidn#include <stdio.h> 6044229Sdavidn#include <string.h> 6144229Sdavidn#include <openssl/md4.h> 6244229Sdavidn#include <openssl/crypto.h> 6344229Sdavidn 6444229Sdavidn#ifdef CHARSET_EBCDIC 6544229Sdavidn# include <openssl/ebcdic.h> 66242349Sbapt#endif 67242349Sbapt 6844229Sdavidnunsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md) 69242349Sbapt{ 70242349Sbapt MD4_CTX c; 71242349Sbapt static unsigned char m[MD4_DIGEST_LENGTH]; 7244229Sdavidn 73242349Sbapt if (md == NULL) 74242349Sbapt md = m; 7520253Sjoerg if (!MD4_Init(&c)) 76242349Sbapt return NULL; 77242349Sbapt#ifndef CHARSET_EBCDIC 7820747Sdavidn MD4_Update(&c, d, n); 79242349Sbapt#else 80242349Sbapt { 8120747Sdavidn char temp[1024]; 82242349Sbapt unsigned long chunk; 83242349Sbapt 84242349Sbapt while (n > 0) { 8520747Sdavidn chunk = (n > sizeof(temp)) ? sizeof(temp) : n; 86242349Sbapt ebcdic2ascii(temp, d, chunk); 87242349Sbapt MD4_Update(&c, temp, chunk); 88242349Sbapt n -= chunk; 8944229Sdavidn d += chunk; 90242349Sbapt } 91242349Sbapt } 92242349Sbapt#endif 93242349Sbapt MD4_Final(md, &c); 94242349Sbapt OPENSSL_cleanse(&c, sizeof(c)); /* security consideration */ 95242349Sbapt return (md); 96242349Sbapt} 97242349Sbapt