1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/*************************************************
* MD4 Source File *
* (C) 1999-2006 The Botan Project *
*************************************************/
#include <botan/asm_macr.h>
START_LISTING(md4core.S)
START_FUNCTION(md4_core)
SPILL_REGS()
#define PUSHED 4
ASSIGN(EBP, ARG(2)) /* input block */
ASSIGN(EDI, ARG(3)) /* expanded words */
ZEROIZE(ESI)
START_LOOP(.LOAD_INPUT)
ADD_IMM(ESI, 4)
ASSIGN(EAX, ARRAY4(EBP, 0))
ASSIGN(EBX, ARRAY4(EBP, 1))
ASSIGN(ECX, ARRAY4(EBP, 2))
ASSIGN(EDX, ARRAY4(EBP, 3))
ADD_IMM(EBP, 16)
ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-4), EAX)
ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-3), EBX)
ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-2), ECX)
ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-1), EDX)
LOOP_UNTIL_EQ(ESI, 16, .LOAD_INPUT)
ASSIGN(EBP, ARG(1))
ASSIGN(EAX, ARRAY4(EBP, 0))
ASSIGN(EBX, ARRAY4(EBP, 1))
ASSIGN(ECX, ARRAY4(EBP, 2))
ASSIGN(EDX, ARRAY4(EBP, 3))
#define T1 ESI
#define T2 EBP
#define FF(A, B, C, D, MSG, S) \
ASSIGN(T1, ARRAY4(EDI, MSG)) ; \
ASSIGN(T2, C) ; \
XOR(T2, D) ; \
AND(T2, B) ; \
XOR(T2, D) ; \
ADD(A, T1) ; \
ADD(A, T2) ; \
ROTL_IMM(A, S) ;
#define GG(A, B, C, D, MSG, S) \
ASSIGN(T1, ARRAY4(EDI, MSG)) ; \
ASSIGN(T2, B) ; \
OR(T2, C) ; \
AND(T2, D) ; \
ADD3_IMM(A, T1, 0x5A827999) ; \
ASSIGN(T1, B) ; \
AND(T1, C) ; \
OR(T2, T1) ; \
ADD(A, T2) ; \
ROTL_IMM(A, S) ;
#define HH(A, B, C, D, MSG, S) \
ASSIGN(T1, ARRAY4(EDI, MSG)) ; \
ASSIGN(T2, B) ; \
XOR(T2, C) ; \
XOR(T2, D) ; \
ADD3_IMM(A, T1, 0x6ED9EBA1) ; \
ADD(A, T2) ; \
ROTL_IMM(A, S) ;
FF(EAX,EBX,ECX,EDX, 0, 3);
FF(EDX,EAX,EBX,ECX, 1, 7);
FF(ECX,EDX,EAX,EBX, 2,11);
FF(EBX,ECX,EDX,EAX, 3,19);
FF(EAX,EBX,ECX,EDX, 4, 3);
FF(EDX,EAX,EBX,ECX, 5, 7);
FF(ECX,EDX,EAX,EBX, 6,11);
FF(EBX,ECX,EDX,EAX, 7,19);
FF(EAX,EBX,ECX,EDX, 8, 3);
FF(EDX,EAX,EBX,ECX, 9, 7);
FF(ECX,EDX,EAX,EBX,10,11);
FF(EBX,ECX,EDX,EAX,11,19);
FF(EAX,EBX,ECX,EDX,12, 3);
FF(EDX,EAX,EBX,ECX,13, 7);
FF(ECX,EDX,EAX,EBX,14,11);
FF(EBX,ECX,EDX,EAX,15,19);
GG(EAX,EBX,ECX,EDX, 0, 3);
GG(EDX,EAX,EBX,ECX, 4, 5);
GG(ECX,EDX,EAX,EBX, 8, 9);
GG(EBX,ECX,EDX,EAX,12,13);
GG(EAX,EBX,ECX,EDX, 1, 3);
GG(EDX,EAX,EBX,ECX, 5, 5);
GG(ECX,EDX,EAX,EBX, 9, 9);
GG(EBX,ECX,EDX,EAX,13,13);
GG(EAX,EBX,ECX,EDX, 2, 3);
GG(EDX,EAX,EB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