Crypto++ 8.9 Free C++ class library of cryptographic schemes

md4.cpp
1 // md4.cpp - modified by Wei Dai from Andrew M. Kuchling's md4.c
2 // The original code and all modifications are in the public domain.
3
4 // This is the original introductory comment:
5
6 /*
7 * md4.c : MD4 hash algorithm.
8 *
9 * Part of the Python Cryptography Toolkit, version 1.1
10 *
11 * Distribute and use freely; there are no restrictions on further
12 * dissemination and usage except those imposed by the laws of your
13 * country of residence.
14 *
15 */
16
17 #include "pch.h"
18 #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
19 #include "md4.h"
20 #include "misc.h"
21
22 NAMESPACE_BEGIN(CryptoPP)
23 namespace Weak1 {
24
25 void MD4::InitState(HashWordType *state)
26 {
27 state[0] = 0x67452301L;
28 state[1] = 0xefcdab89L;
29 state[2] = 0x98badcfeL;
30 state[3] = 0x10325476L;
31 }
32
33 void MD4::Transform (word32 *digest, const word32 *in)
34 {
35 // #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
36 #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
37 #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
38 #define H(x, y, z) ((x) ^ (y) ^ (z))
39
40 word32 A, B, C, D;
41
42 A=digest[0];
43 B=digest[1];
44 C=digest[2];
45 D=digest[3];
46
47 #define function(a,b,c,d,k,s) a=rotlVariable(a+F(b,c,d)+in[k],s);
48 function(A,B,C,D, 0, 3);
49 function(D,A,B,C, 1, 7);
50 function(C,D,A,B, 2,11);
51 function(B,C,D,A, 3,19);
52 function(A,B,C,D, 4, 3);
53 function(D,A,B,C, 5, 7);
54 function(C,D,A,B, 6,11);
55 function(B,C,D,A, 7,19);
56 function(A,B,C,D, 8, 3);
57 function(D,A,B,C, 9, 7);
58 function(C,D,A,B,10,11);
59 function(B,C,D,A,11,19);
60 function(A,B,C,D,12, 3);
61 function(D,A,B,C,13, 7);
62 function(C,D,A,B,14,11);
63 function(B,C,D,A,15,19);
64
65 #undef function
66 #define function(a,b,c,d,k,s) a=rotlVariable(a+G(b,c,d)+in[k]+0x5a827999,s);
67 function(A,B,C,D, 0, 3);
68 function(D,A,B,C, 4, 5);
69 function(C,D,A,B, 8, 9);
70 function(B,C,D,A,12,13);
71 function(A,B,C,D, 1, 3);
72 function(D,A,B,C, 5, 5);
73 function(C,D,A,B, 9, 9);
74 function(B,C,D,A,13,13);
75 function(A,B,C,D, 2, 3);
76 function(D,A,B,C, 6, 5);
77 function(C,D,A,B,10, 9);
78 function(B,C,D,A,14,13);
79 function(A,B,C,D, 3, 3);
80 function(D,A,B,C, 7, 5);
81 function(C,D,A,B,11, 9);
82 function(B,C,D,A,15,13);
83
84 #undef function
85 #define function(a,b,c,d,k,s) a=rotlVariable(a+H(b,c,d)+in[k]+0x6ed9eba1,s);
86 function(A,B,C,D, 0, 3);
87 function(D,A,B,C, 8, 9);
88 function(C,D,A,B, 4,11);
89 function(B,C,D,A,12,15);
90 function(A,B,C,D, 2, 3);
91 function(D,A,B,C,10, 9);
92 function(C,D,A,B, 6,11);
93 function(B,C,D,A,14,15);
94 function(A,B,C,D, 1, 3);
95 function(D,A,B,C, 9, 9);
96 function(C,D,A,B, 5,11);
97 function(B,C,D,A,13,15);
98 function(A,B,C,D, 3, 3);
99 function(D,A,B,C,11, 9);
100 function(C,D,A,B, 7,11);
101 function(B,C,D,A,15,15);
102
103 digest[0]+=A;
104 digest[1]+=B;
105 digest[2]+=C;
106 digest[3]+=D;
107 }
108
109 }
110 NAMESPACE_END
word32
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:72
misc.h
Utility functions for the Crypto++ library.
CryptoPP
Crypto++ library namespace.
pch.h
Precompiled header file.