md4_locl.h revision 296465
150477Speter/* crypto/md4/md4_locl.h */
2139749Simp/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3196008Smjacob * All rights reserved.
4167403Smjacob *
5167403Smjacob * This package is an SSL implementation written
6167403Smjacob * by Eric Young (eay@cryptsoft.com).
7167403Smjacob * The implementation was written so as to conform with Netscapes SSL.
8167403Smjacob *
9167403Smjacob * This library is free for commercial and non-commercial use as long as
10167403Smjacob * the following conditions are aheared to.  The following conditions
11167403Smjacob * apply to all code found in this distribution, be it the RC4, RSA,
12167403Smjacob * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13167403Smjacob * included with this distribution is covered by the same copyright terms
14167403Smjacob * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15167403Smjacob *
16167403Smjacob * Copyright remains Eric Young's, and as such any Copyright notices in
17167403Smjacob * the code are not to be removed.
18167403Smjacob * If this package is used in a product, Eric Young should be given attribution
19167403Smjacob * as the author of the parts of the library used.
20167403Smjacob * This can be in the form of a textual message at program startup or
21167403Smjacob * in documentation (online or textual) provided with the package.
22167403Smjacob *
23167403Smjacob * Redistribution and use in source and binary forms, with or without
24167403Smjacob * modification, are permitted provided that the following conditions
25167403Smjacob * are met:
26167403Smjacob * 1. Redistributions of source code must retain the copyright
27196008Smjacob *    notice, this list of conditions and the following disclaimer.
28167403Smjacob * 2. Redistributions in binary form must reproduce the above copyright
29167403Smjacob *    notice, this list of conditions and the following disclaimer in the
3035388Smjacob *    documentation and/or other materials provided with the distribution.
3135388Smjacob * 3. All advertising materials mentioning features or use of this software
3235388Smjacob *    must display the following acknowledgement:
3335388Smjacob *    "This product includes cryptographic software written by
3435388Smjacob *     Eric Young (eay@cryptsoft.com)"
3535388Smjacob *    The word 'cryptographic' can be left out if the rouines from the library
3635388Smjacob *    being used are not cryptographic related :-).
3735388Smjacob * 4. If you include any Windows specific code (or a derivative thereof) from
3835388Smjacob *    the apps directory (application code) you must include an acknowledgement:
3935388Smjacob *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
4035388Smjacob *
4135388Smjacob * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4235388Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4335388Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4435388Smjacob * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4535388Smjacob * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4635388Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4735388Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4835388Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4935388Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5035388Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5135388Smjacob * SUCH DAMAGE.
5235388Smjacob *
5335388Smjacob * The licence and distribution terms for any publically available version or
5435388Smjacob * derivative of this code cannot be changed.  i.e. this code cannot simply be
5546967Smjacob * copied and put under another distribution licence
5646967Smjacob * [including the GNU Public Licence.]
5746967Smjacob */
5846967Smjacob
5946967Smjacob#include <stdlib.h>
6046967Smjacob#include <string.h>
6146967Smjacob#include <openssl/opensslconf.h>
6246967Smjacob#include <openssl/md4.h>
6335388Smjacob
6435388Smjacob#ifndef MD4_LONG_LOG2
6544819Smjacob# define MD4_LONG_LOG2 2        /* default to 32 bits */
6635388Smjacob#endif
6744819Smjacob
6844819Smjacobvoid md4_block_data_order(MD4_CTX *c, const void *p, size_t num);
6982689Smjacob
70163899Smjacob#define DATA_ORDER_IS_LITTLE_ENDIAN
7135388Smjacob
7235388Smjacob#define HASH_LONG               MD4_LONG
7344819Smjacob#define HASH_CTX                MD4_CTX
7435388Smjacob#define HASH_CBLOCK             MD4_CBLOCK
7535388Smjacob#define HASH_UPDATE             MD4_Update
7644819Smjacob#define HASH_TRANSFORM          MD4_Transform
7735388Smjacob#define HASH_FINAL              MD4_Final
7835388Smjacob#define HASH_MAKE_STRING(c,s)   do {    \
7944819Smjacob        unsigned long ll;               \
8044819Smjacob        ll=(c)->A; HOST_l2c(ll,(s));    \
8144819Smjacob        ll=(c)->B; HOST_l2c(ll,(s));    \
8244819Smjacob        ll=(c)->C; HOST_l2c(ll,(s));    \
8364088Smjacob        ll=(c)->D; HOST_l2c(ll,(s));    \
8464088Smjacob        } while (0)
8564088Smjacob#define HASH_BLOCK_DATA_ORDER   md4_block_data_order
8635388Smjacob
8735388Smjacob#include "md32_common.h"
8835388Smjacob
8935388Smjacob/*-
9035388Smjacob#define F(x,y,z)        (((x) & (y))  |  ((~(x)) & (z)))
9144819Smjacob#define G(x,y,z)        (((x) & (y))  |  ((x) & ((z))) | ((y) & ((z))))
9244819Smjacob*/
9344819Smjacob
9444819Smjacob/*
9544819Smjacob * As pointed out by Wei Dai <weidai@eskimo.com>, the above can be simplified
9644819Smjacob * to the code below.  Wei attributes these optimizations to Peter Gutmann's
9744819Smjacob * SHS code, and he attributes it to Rich Schroeppel.
9844819Smjacob */
9935388Smjacob#define F(b,c,d)        ((((c) ^ (d)) & (b)) ^ (d))
10035388Smjacob#define G(b,c,d)        (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
10135388Smjacob#define H(b,c,d)        ((b) ^ (c) ^ (d))
10235388Smjacob
10344819Smjacob#define R0(a,b,c,d,k,s,t) { \
10454671Smjacob        a+=((k)+(t)+F((b),(c),(d))); \
10554671Smjacob        a=ROTATE(a,s); };
10654671Smjacob
10754671Smjacob#define R1(a,b,c,d,k,s,t) { \
10854671Smjacob        a+=((k)+(t)+G((b),(c),(d))); \
10954671Smjacob        a=ROTATE(a,s); };\
11054671Smjacob
11154671Smjacob#define R2(a,b,c,d,k,s,t) { \
11254671Smjacob        a+=((k)+(t)+H((b),(c),(d))); \
11354671Smjacob        a=ROTATE(a,s); };
11454671Smjacob