Home > Back-end >  A speed MD5 implementation code
A speed MD5 implementation code

Time:12-21

 
//is online to find the original code, but there is a problem, the code is lack of words, and the length of the data processing has limited
//has perfect code, solved the problem of the data length limit
//note after assembly macro at the end of the line of code \ cannot have any content, otherwise it will affect, on this point had lost, hereby remind,

# include & lt; The VCL. H>

Struct MD5_CTX {
Unsigned int state [4];//encypted the message context. The state [0] is a 32-bit unsigned integer, pay attention to the memory byte order
Unsigned long long count;
Char STR [33]={0};
Unsigned char buffer [64].
};

# define S11 7
# define speed 12 12
# define/S13 17
# define/S14 22
# define S21 5
9 # define S22
# define S23 14
# define S24 20
# define S31 4
# define S32 11
# define S33 16
# define S34 23
# define S41 6
# define S42 10
# define S43 15
# define S44 21

# define a esi
# define edi b
C # define edx
# define d ebx
# define tmp1 eax
# define tmp2 ecx

# define x (I) [x + 4 * I]

# define FF (a, b, c, d, x, s, ac) \
The __asm mov tmp1, b \
The __asm and tmp1, c \
The __asm mov tmp2, b \
The __asm not tmp2 \
The __asm and tmp2, d \
The __asm or tmp2, tmp1 \
__asm lea a, [tmp2 + a + ac] \
The __asm add a, x \
The __asm rol a, s \
__asm add a, b

# define GG (a, b, c, d, x, s, ac) \
The __asm mov tmp1, b \
The __asm and tmp1, d \
The __asm mov tmp2, d \
The __asm not tmp2 \
The __asm and tmp2, c \
The __asm or tmp2, tmp1 \
__asm lea a, [tmp2 + a + ac] \
The __asm add a, x \
The __asm rol a, s \
__asm add a, b

# define HH (a, b, c, d, x, s, ac) \
The __asm mov tmp2, b \
The __asm xor tmp2, c \
The __asm xor tmp2, d \
__asm lea a, [tmp2 + a + ac] \
The __asm add a, x \
The __asm rol a, s \
__asm add a, b

# define II (a, b, c, d, x, s, ac) \
The __asm mov tmp2, d \
The __asm not tmp2 \
The __asm or tmp2, b \
The __asm xor tmp2, c \
__asm lea a, [tmp2 + a + ac] \
The __asm add a, x \
The __asm rol a, s \
__asm add a, b

The static unsigned char PADDING [64]={
0 x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

The static void MD5Transform (unsigned int * state, unsigned char * block)
{
DWORD x [16].
The __asm
{
Mov tmp1, DWORD PTR [state]
Mov, a DWORD PTR [tmp1]
Mov b, DWORD PTR [tmp1 + 4]
Mov c, DWORD PTR [tmp1 + 8]
Mov d, DWORD PTR [tmp1 + 12]

Push esi
Push edi

Xor ecx, ecx
Mov esi, DWORD PTR [block]
Lea edi, [x]
ROLL:
Mov eax, DWORD PTR [esi + ecx]
Mov DWORD PTR [edi + ecx], eax
The add ecx, 4
CMP ecx, 64
Jb ROLL

Pop edi
Pop esi
}

//Round 1
FF (a, b, c, d, x (0), S11, 0 xd76aa478);
FF (d, a, b, c, x (1), speed 12, 0 xe8c7b756);
FF (c, d, a, b, x (2),/S13, 0 x242070db);
FF (b, c, d, a, (3), x/S14, 0 xc1bdceee);
FF (a, b, c, d, x (4), S11, 0 xf57c0faf);
FF (d, a, b, c, x (5), speed 12, 0 x4787c62a);
FF (c, d, a, b, (6), x/S13, 0 xa8304613);
FF (b, c, d, a, (7), x/S14, 0 xfd469501);
FF (a, b, c, d, x (8), S11, 0 x698098d8);
FF (d, a, b, c, x (9), speed 12, 0 x8b44f7af);
FF (c, d, a, b, x (10),/S13, 0 xffff5bb1);
FF (b, c, d, a, (11), x/S14, 0 x895cd7be);
FF (a, b, c, d, x (12), S11, 0 x6b901122);
FF (d, a, b, c, x (13), speed 12, 0 xfd987193);
FF (c, d, a, b, x (14),/S13, 0 xa679438e);
FF (b, c, d, a, (15), x/S14, 0 x49b40821);

//Round 2
GG (a, b, c, d, x (1), S21, 0 xf61e2562);
GG (d, a, b, c, x (6), S22, 0 xc040b340);
GG (c, d, a, b, x (11), S23, 0 x265e5a51);
GG (b, c, d, a, x (0), S24, 0 xe9b6c7aa);
GG (a, b, c, d, x (5), S21, 0 xd62f105d);
GG (d, a, b, c, x (10), S22, 0 x2441453);
GG (c, d, a, b, x (15), S23, 0 xd8a1e681);
GG (b, c, d, a, x (4), S24, 0 xe7d3fbc8);
GG (a, b, c, d, x (9), S21, 0 x21e1cde6);
GG (d, a, b, c, x (14), S22, 0 xc33707d6);
GG (c, d, a, b, x (3), S23, 0 xf4d50d87);
GG (b, c, d, a, x (8), S24, 0 x455a14ed);
GG (a, b, c, d, x (13), S21, 0 xa9e3e905);
GG (d, a, b, c, x (2), S22, 0 xfcefa3f8);
GG (c, d, a, b, x (7), S23, 0 x676f02d9);
GG (b, c, d, a, x (12), S24, 0 x8d2a4c8a);

//Round 3
HH (a, b, c, d, x (5), S31, 0 xfffa3942);
HH (d, a, b, c, x (8), S32, 0 x8771f681);
HH (c, d, a, b, x (11), S33, 0 x6d9d6122);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related