1N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 1N/A * Use is subject to license terms. 1N/A ********************************************************************** 1N/A ** RSA Data Security, Inc. MD4 Message Digest Algorithm ** 1N/A ** Created: 2/17/90 RLR ** 1N/A ** Revised: 1/91 SRD,AJ,BSK,JT Reference C Version ** 1N/A ********************************************************************** 1N/A ********************************************************************** 1N/A ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. ** 1N/A ** License to copy and use this software is granted provided that ** 1N/A ** it is identified as the "RSA Data Security, Inc. MD4 Message ** 1N/A ** Digest Algorithm" in all material mentioning or referencing this ** 1N/A ** software or this function. ** 1N/A ** License is also granted to make and use derivative works ** 1N/A ** provided that such works are identified as "derived from the RSA ** 1N/A ** Data Security, Inc. MD4 Message Digest Algorithm" in all ** 1N/A ** material mentioning or referencing the derived work. ** 1N/A ** RSA Data Security, Inc. makes no representations concerning ** 1N/A ** either the merchantability of this software or the suitability ** 1N/A ** of this software for any particular purpose. It is provided "as ** 1N/A ** is" without express or implied warranty of any kind. ** 1N/A ** These notices must be retained in any copies of any part of this ** 1N/A ********************************************************************** 1N/A/* forward declaration */ 1N/A 0x80,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
1N/A 0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
1N/A 0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
1N/A 0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
1N/A 0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
1N/A 0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
1N/A 0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
1N/A 0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00 1N/A/* F, G and H are basic MD4 functions: selection, majority, parity */ 1N/A#
define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
1N/A#
define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
1N/A#
define H(x, y, z) ((x) ^ (y) ^ (z))
/* ROTATE_LEFT rotates x left n bits */ #
define ROTATE_LEFT(x, n) ((((x) << (n)) &
0xffffffff) | ((x) >> (
32-(n))))
/* FF, GG and HH are MD4 transformations for rounds 1, 2 and 3 */ /* Rotation is separate from addition to prevent recomputation */ #
define FF(a, b, c, d, x, s) \
{(a) += F ((b), (c), (d)) + (x); \
#
define GG(a, b, c, d, x, s) \
{(a) += G ((b), (c), (d)) + (x) + 0
13240474631UL; \
#
define HH(a, b, c, d, x, s) \
{(a) += H ((b), (c), (d)) + (x) + 0
15666365641UL; \
/* Load magic initialization constants. /* compute number of bytes mod 64 */ /* update number of bits */ /* add new character to buffer, increment mdi */ /* transform if necessary */ for (i = 0,
ii = 0; i <
16; i++,
ii +=
4)
/* save number of bits */ /* compute number of bytes mod 64 */ /* pad out to 56 mod 64 */ /* append length in bits and transform */ for (i = 0,
ii = 0; i <
14; i++,
ii +=
4)
/* store buffer in digest */ for (i = 0,
ii = 0; i <
4; i++,
ii +=
4) {
/* Basic MD4 step. Transform buf based on in. for (i = 0; i <
16; i++) {
static const unsigned char round1consts[] = {
3,
7,
11,
19, };
for (i = 0; i <
16; i++) {
0,
4,
8,
12,
1,
5,
9,
13,
2,
6,
10,
14,
3,
7,
11,
15 static const unsigned char round2consts[] = {
3,
5,
9,
13 };
for (i = 0; i <
16; i++) {
0,
8,
4,
12,
2,
10,
6,
14,
1,
9,
5,
13,
3,
11,
7,
15 static const unsigned char round3consts[] = {
3,
9,
11,
15 };
FF (a, b, c, d,
in[ 0],
3);
FF (d, a, b, c,
in[
1],
7);
FF (c, d, a, b,
in[
2],
11);
FF (b, c, d, a,
in[
3],
19);
FF (a, b, c, d,
in[
4],
3);
FF (d, a, b, c,
in[
5],
7);
FF (c, d, a, b,
in[
6],
11);
FF (b, c, d, a,
in[
7],
19);
FF (a, b, c, d,
in[
8],
3);
FF (d, a, b, c,
in[
9],
7);
FF (c, d, a, b,
in[
10],
11);
FF (b, c, d, a,
in[
11],
19);
FF (a, b, c, d,
in[
12],
3);
FF (d, a, b, c,
in[
13],
7);
FF (c, d, a, b,
in[
14],
11);
FF (b, c, d, a,
in[
15],
19);
GG (a, b, c, d,
in[ 0],
3);
GG (d, a, b, c,
in[
4],
5);
GG (c, d, a, b,
in[
8],
9);
GG (b, c, d, a,
in[
12],
13);
GG (a, b, c, d,
in[
1],
3);
GG (d, a, b, c,
in[
5],
5);
GG (c, d, a, b,
in[
9],
9);
GG (b, c, d, a,
in[
13],
13);
GG (a, b, c, d,
in[
2],
3);
GG (d, a, b, c,
in[
6],
5);
GG (c, d, a, b,
in[
10],
9);
GG (b, c, d, a,
in[
14],
13);
GG (a, b, c, d,
in[
3],
3);
GG (d, a, b, c,
in[
7],
5);
GG (c, d, a, b,
in[
11],
9);
GG (b, c, d, a,
in[
15],
13);
HH (a, b, c, d,
in[ 0],
3);
HH (d, a, b, c,
in[
8],
9);
HH (c, d, a, b,
in[
4],
11);
HH (b, c, d, a,
in[
12],
15);
HH (a, b, c, d,
in[
2],
3);
HH (d, a, b, c,
in[
10],
9);
HH (c, d, a, b,
in[
6],
11);
HH (b, c, d, a,
in[
14],
15);
HH (a, b, c, d,
in[
1],
3);
HH (d, a, b, c,
in[
9],
9);
HH (c, d, a, b,
in[
5],
11);
HH (b, c, d, a,
in[
13],
15);
HH (a, b, c, d,
in[
3],
3);
HH (d, a, b, c,
in[
11],
9);
HH (c, d, a, b,
in[
7],
11);
HH (b, c, d, a,
in[
15],
15);
********************************************************************** ******************************* (cut) ********************************