md4.cpp

00001 // md4.cpp - modified by Wei Dai from Andrew M. Kuchling's md4.c
00002 // The original code and all modifications are in the public domain.
00003 
00004 // This is the original introductory comment:
00005 
00006 /*
00007  *  md4.c : MD4 hash algorithm.
00008  *
00009  * Part of the Python Cryptography Toolkit, version 1.1
00010  *
00011  * Distribute and use freely; there are no restrictions on further 
00012  * dissemination and usage except those imposed by the laws of your 
00013  * country of residence.
00014  *
00015  */
00016 
00017 #include "pch.h"
00018 #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
00019 #include "md4.h"
00020 #include "misc.h"
00021 
00022 NAMESPACE_BEGIN(CryptoPP)
00023 namespace Weak1 {
00024 
00025 void MD4::InitState(HashWordType *state)
00026 {
00027         state[0] = 0x67452301L;
00028         state[1] = 0xefcdab89L;
00029         state[2] = 0x98badcfeL;
00030         state[3] = 0x10325476L;
00031 }
00032 
00033 void MD4::Transform (word32 *digest, const word32 *in)
00034 {
00035 // #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
00036 #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
00037 #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
00038 #define H(x, y, z) ((x) ^ (y) ^ (z))
00039 
00040     word32 A, B, C, D;
00041 
00042         A=digest[0];
00043         B=digest[1];
00044         C=digest[2];
00045         D=digest[3];
00046 
00047 #define function(a,b,c,d,k,s) a=rotlFixed(a+F(b,c,d)+in[k],s);   
00048           function(A,B,C,D, 0, 3);
00049           function(D,A,B,C, 1, 7);
00050           function(C,D,A,B, 2,11);
00051           function(B,C,D,A, 3,19);
00052           function(A,B,C,D, 4, 3);
00053           function(D,A,B,C, 5, 7);
00054           function(C,D,A,B, 6,11);
00055           function(B,C,D,A, 7,19);
00056           function(A,B,C,D, 8, 3);
00057           function(D,A,B,C, 9, 7);
00058           function(C,D,A,B,10,11);
00059           function(B,C,D,A,11,19);
00060           function(A,B,C,D,12, 3);
00061           function(D,A,B,C,13, 7);
00062           function(C,D,A,B,14,11);
00063           function(B,C,D,A,15,19);
00064 
00065 #undef function   
00066 #define function(a,b,c,d,k,s) a=rotlFixed(a+G(b,c,d)+in[k]+0x5a827999,s);        
00067           function(A,B,C,D, 0, 3);
00068           function(D,A,B,C, 4, 5);
00069           function(C,D,A,B, 8, 9);
00070           function(B,C,D,A,12,13);
00071           function(A,B,C,D, 1, 3);
00072           function(D,A,B,C, 5, 5);
00073           function(C,D,A,B, 9, 9);
00074           function(B,C,D,A,13,13);
00075           function(A,B,C,D, 2, 3);
00076           function(D,A,B,C, 6, 5);
00077           function(C,D,A,B,10, 9);
00078           function(B,C,D,A,14,13);
00079           function(A,B,C,D, 3, 3);
00080           function(D,A,B,C, 7, 5);
00081           function(C,D,A,B,11, 9);
00082           function(B,C,D,A,15,13);
00083 
00084 #undef function  
00085 #define function(a,b,c,d,k,s) a=rotlFixed(a+H(b,c,d)+in[k]+0x6ed9eba1,s);        
00086           function(A,B,C,D, 0, 3);
00087           function(D,A,B,C, 8, 9);
00088           function(C,D,A,B, 4,11);
00089           function(B,C,D,A,12,15);
00090           function(A,B,C,D, 2, 3);
00091           function(D,A,B,C,10, 9);
00092           function(C,D,A,B, 6,11);
00093           function(B,C,D,A,14,15);
00094           function(A,B,C,D, 1, 3);
00095           function(D,A,B,C, 9, 9);
00096           function(C,D,A,B, 5,11);
00097           function(B,C,D,A,13,15);
00098           function(A,B,C,D, 3, 3);
00099           function(D,A,B,C,11, 9);
00100           function(C,D,A,B, 7,11);
00101           function(B,C,D,A,15,15);
00102 
00103         digest[0]+=A;
00104         digest[1]+=B;
00105         digest[2]+=C;
00106         digest[3]+=D;
00107 }
00108 
00109 }
00110 NAMESPACE_END

Generated on Fri Jun 1 11:11:22 2007 for Crypto++ by  doxygen 1.5.2