1290650Shselasky/* crypto/md4/md4_locl.h */ 2290650Shselasky/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3290650Shselasky * All rights reserved. 4290650Shselasky * 5290650Shselasky * This package is an SSL implementation written 6290650Shselasky * by Eric Young (eay@cryptsoft.com). 7290650Shselasky * The implementation was written so as to conform with Netscapes SSL. 8290650Shselasky * 9290650Shselasky * This library is free for commercial and non-commercial use as long as 10290650Shselasky * the following conditions are aheared to. The following conditions 11290650Shselasky * apply to all code found in this distribution, be it the RC4, RSA, 12290650Shselasky * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13290650Shselasky * included with this distribution is covered by the same copyright terms 14290650Shselasky * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15290650Shselasky * 16290650Shselasky * Copyright remains Eric Young's, and as such any Copyright notices in 17290650Shselasky * the code are not to be removed. 18290650Shselasky * If this package is used in a product, Eric Young should be given attribution 19290650Shselasky * as the author of the parts of the library used. 20290650Shselasky * This can be in the form of a textual message at program startup or 21290650Shselasky * in documentation (online or textual) provided with the package. 22290650Shselasky * 23290650Shselasky * Redistribution and use in source and binary forms, with or without 24290650Shselasky * modification, are permitted provided that the following conditions 25290650Shselasky * are met: 26290650Shselasky * 1. Redistributions of source code must retain the copyright 27290650Shselasky * notice, this list of conditions and the following disclaimer. 28290650Shselasky * 2. Redistributions in binary form must reproduce the above copyright 29290650Shselasky * notice, this list of conditions and the following disclaimer in the 30290650Shselasky * documentation and/or other materials provided with the distribution. 31290650Shselasky * 3. All advertising materials mentioning features or use of this software 32290650Shselasky * must display the following acknowledgement: 33290650Shselasky * "This product includes cryptographic software written by 34290650Shselasky * Eric Young (eay@cryptsoft.com)" 35290650Shselasky * The word 'cryptographic' can be left out if the rouines from the library 36290650Shselasky * being used are not cryptographic related :-). 37290650Shselasky * 4. If you include any Windows specific code (or a derivative thereof) from 38290650Shselasky * the apps directory (application code) you must include an acknowledgement: 39290650Shselasky * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40290650Shselasky * 41290650Shselasky * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42290650Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43290650Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44290650Shselasky * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45290650Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46290650Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47290650Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48290650Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49290650Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50290650Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51290650Shselasky * SUCH DAMAGE. 52290650Shselasky * 53290650Shselasky * The licence and distribution terms for any publically available version or 54290650Shselasky * derivative of this code cannot be changed. i.e. this code cannot simply be 55290650Shselasky * copied and put under another distribution licence 56290650Shselasky * [including the GNU Public Licence.] 57290650Shselasky */ 58290650Shselasky 59290650Shselasky#include <stdlib.h> 60290650Shselasky#include <string.h> 61290650Shselasky#include <openssl/opensslconf.h> 62290650Shselasky#include <openssl/md4.h> 63290650Shselasky 64290650Shselasky#ifndef MD4_LONG_LOG2 65290650Shselasky#define MD4_LONG_LOG2 2 /* default to 32 bits */ 66290650Shselasky#endif 67290650Shselasky 68290650Shselaskyvoid md4_block_data_order (MD4_CTX *c, const void *p,size_t num); 69290650Shselasky 70290650Shselasky#define DATA_ORDER_IS_LITTLE_ENDIAN 71290650Shselasky 72290650Shselasky#define HASH_LONG MD4_LONG 73290650Shselasky#define HASH_CTX MD4_CTX 74290650Shselasky#define HASH_CBLOCK MD4_CBLOCK 75291184Shselasky#define HASH_UPDATE MD4_Update 76290650Shselasky#define HASH_TRANSFORM MD4_Transform 77290650Shselasky#define HASH_FINAL MD4_Final 78290650Shselasky#define HASH_MAKE_STRING(c,s) do { \ 79290650Shselasky unsigned long ll; \ 80290650Shselasky ll=(c)->A; (void)HOST_l2c(ll,(s)); \ 81290650Shselasky ll=(c)->B; (void)HOST_l2c(ll,(s)); \ 82290650Shselasky ll=(c)->C; (void)HOST_l2c(ll,(s)); \ 83290650Shselasky ll=(c)->D; (void)HOST_l2c(ll,(s)); \ 84290650Shselasky } while (0) 85290650Shselasky#define HASH_BLOCK_DATA_ORDER md4_block_data_order 86290650Shselasky 87290650Shselasky#include "md32_common.h" 88290650Shselasky 89290650Shselasky/* 90290650Shselasky#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) 91290650Shselasky#define G(x,y,z) (((x) & (y)) | ((x) & ((z))) | ((y) & ((z)))) 92290650Shselasky*/ 93290650Shselasky 94290650Shselasky/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be 95290650Shselasky * simplified to the code below. Wei attributes these optimizations 96290650Shselasky * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel. 97290650Shselasky */ 98290650Shselasky#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d)) 99290650Shselasky#define G(b,c,d) (((b) & (c)) | ((b) & (d)) | ((c) & (d))) 100290650Shselasky#define H(b,c,d) ((b) ^ (c) ^ (d)) 101290650Shselasky 102290650Shselasky#define R0(a,b,c,d,k,s,t) { \ 103290650Shselasky a+=((k)+(t)+F((b),(c),(d))); \ 104290650Shselasky a=ROTATE(a,s); }; 105290650Shselasky 106290650Shselasky#define R1(a,b,c,d,k,s,t) { \ 107290650Shselasky a+=((k)+(t)+G((b),(c),(d))); \ 108290650Shselasky a=ROTATE(a,s); };\ 109290650Shselasky 110290650Shselasky#define R2(a,b,c,d,k,s,t) { \ 111290650Shselasky a+=((k)+(t)+H((b),(c),(d))); \ 112290650Shselasky a=ROTATE(a,s); }; 113290650Shselasky