xref: /plan9/sys/src/cmd/unix/drawterm/win32-386/sha1block.spp (revision 8ccd4a6360d974db7bd7bbd4f37e7018419ea908)
1*8ccd4a63SDavid du Colombier.text
2*8ccd4a63SDavid du Colombier
3*8ccd4a63SDavid du Colombier.p2align 2,0x90
4*8ccd4a63SDavid du Colombier.globl ___sha1block
5*8ccd4a63SDavid du Colombier___sha1block:
6*8ccd4a63SDavid du Colombier	jmp sha1block
7*8ccd4a63SDavid du Colombier
8*8ccd4a63SDavid du Colombier.p2align 2,0x90
9*8ccd4a63SDavid du Colombier.globl __sha1block
10*8ccd4a63SDavid du Colombier__sha1block:
11*8ccd4a63SDavid du Colombier	jmp sha1block
12*8ccd4a63SDavid du Colombier
13*8ccd4a63SDavid du Colombier.p2align 2,0x90
14*8ccd4a63SDavid du Colombier.globl _sha1block
15*8ccd4a63SDavid du Colombier_sha1block:
16*8ccd4a63SDavid du Colombier	jmp sha1block
17*8ccd4a63SDavid du Colombier
18*8ccd4a63SDavid du Colombier.p2align 2,0x90
19*8ccd4a63SDavid du Colombier.globl sha1block
20*8ccd4a63SDavid du Colombiersha1block:
21*8ccd4a63SDavid du Colombier
22*8ccd4a63SDavid du Colombier/* x = (wp[off-f] ^ wp[off-8] ^ wp[off-14] ^ wp[off-16]) <<< 1;
23*8ccd4a63SDavid du Colombier * wp[off] = x;
24*8ccd4a63SDavid du Colombier * x += A <<< 5;
25*8ccd4a63SDavid du Colombier * E += 0xca62c1d6 + x;
26*8ccd4a63SDavid du Colombier * x = FN(B,C,D);
27*8ccd4a63SDavid du Colombier * E += x;
28*8ccd4a63SDavid du Colombier * B >>> 2
29*8ccd4a63SDavid du Colombier */
30*8ccd4a63SDavid du Colombier#define BSWAPDI	BYTE $0x0f; BYTE $0xcf;
31*8ccd4a63SDavid du Colombier
32*8ccd4a63SDavid du Colombier#define BODY(off,FN,V,A,B,C,D,E)\
33*8ccd4a63SDavid du Colombier	movl (off-64)(%ebp), %edi;\
34*8ccd4a63SDavid du Colombier	xorl (off-56)(%ebp), %edi;\
35*8ccd4a63SDavid du Colombier	xorl (off-32)(%ebp), %edi;\
36*8ccd4a63SDavid du Colombier	xorl (off-12)(%ebp), %edi;\
37*8ccd4a63SDavid du Colombier	roll $1, %edi;\
38*8ccd4a63SDavid du Colombier	movl %edi, off(%ebp);\
39*8ccd4a63SDavid du Colombier	leal V(%edi, E, 1), E;\
40*8ccd4a63SDavid du Colombier	movl A, %edi;\
41*8ccd4a63SDavid du Colombier	roll $5, %edi;\
42*8ccd4a63SDavid du Colombier	addl %edi, E;\
43*8ccd4a63SDavid du Colombier	FN(B,C,D)\
44*8ccd4a63SDavid du Colombier	addl %edi, E;\
45*8ccd4a63SDavid du Colombier	rorl $2, B;\
46*8ccd4a63SDavid du Colombier
47*8ccd4a63SDavid du Colombier#define BODY0(off,FN,V,A,B,C,D,E)\
48*8ccd4a63SDavid du Colombier	movl off(%ebx), %edi;\
49*8ccd4a63SDavid du Colombier	bswap %edi;\
50*8ccd4a63SDavid du Colombier	movl %edi, off(%ebp);\
51*8ccd4a63SDavid du Colombier	leal V(%edi,E,1), E;\
52*8ccd4a63SDavid du Colombier	movl A, %edi;\
53*8ccd4a63SDavid du Colombier	roll $5,%edi;\
54*8ccd4a63SDavid du Colombier	addl %edi,E;\
55*8ccd4a63SDavid du Colombier	FN(B,C,D)\
56*8ccd4a63SDavid du Colombier	addl %edi,E;\
57*8ccd4a63SDavid du Colombier	rorl $2,B;\
58*8ccd4a63SDavid du Colombier
59*8ccd4a63SDavid du Colombier/*
60*8ccd4a63SDavid du Colombier * fn1 = (((C^D)&B)^D);
61*8ccd4a63SDavid du Colombier */
62*8ccd4a63SDavid du Colombier#define FN1(B,C,D)\
63*8ccd4a63SDavid du Colombier	movl C, %edi;\
64*8ccd4a63SDavid du Colombier	xorl D, %edi;\
65*8ccd4a63SDavid du Colombier	andl B, %edi;\
66*8ccd4a63SDavid du Colombier	xorl D, %edi;\
67*8ccd4a63SDavid du Colombier
68*8ccd4a63SDavid du Colombier/*
69*8ccd4a63SDavid du Colombier * fn24 = B ^ C ^ D
70*8ccd4a63SDavid du Colombier */
71*8ccd4a63SDavid du Colombier#define FN24(B,C,D)\
72*8ccd4a63SDavid du Colombier	movl B, %edi;\
73*8ccd4a63SDavid du Colombier	xorl C, %edi;\
74*8ccd4a63SDavid du Colombier	xorl D, %edi;\
75*8ccd4a63SDavid du Colombier
76*8ccd4a63SDavid du Colombier/*
77*8ccd4a63SDavid du Colombier * fn3 = ((B ^ C) & (D ^= B)) ^ B
78*8ccd4a63SDavid du Colombier * D ^= B to restore D
79*8ccd4a63SDavid du Colombier */
80*8ccd4a63SDavid du Colombier#define FN3(B,C,D)\
81*8ccd4a63SDavid du Colombier	movl B, %edi;\
82*8ccd4a63SDavid du Colombier	xorl C, %edi;\
83*8ccd4a63SDavid du Colombier	xorl B, D;\
84*8ccd4a63SDavid du Colombier	andl D, %edi;\
85*8ccd4a63SDavid du Colombier	xorl B, %edi;\
86*8ccd4a63SDavid du Colombier	xorl B, D;\
87*8ccd4a63SDavid du Colombier
88*8ccd4a63SDavid du Colombier/*
89*8ccd4a63SDavid du Colombier * stack offsets
90*8ccd4a63SDavid du Colombier * void sha1block(uchar *DATA, int LEN, ulong *STATE)
91*8ccd4a63SDavid du Colombier */
92*8ccd4a63SDavid du Colombier#define STACKSIZE (48+80*4)
93*8ccd4a63SDavid du Colombier#define	DATA	(STACKSIZE+8)
94*8ccd4a63SDavid du Colombier#define	LEN	(STACKSIZE+12)
95*8ccd4a63SDavid du Colombier#define	STATE	(STACKSIZE+16)
96*8ccd4a63SDavid du Colombier
97*8ccd4a63SDavid du Colombier/*
98*8ccd4a63SDavid du Colombier * stack offsets for locals
99*8ccd4a63SDavid du Colombier * ulong w[80];
100*8ccd4a63SDavid du Colombier * uchar *edata;
101*8ccd4a63SDavid du Colombier * ulong *w15, *w40, *w60, *w80;
102*8ccd4a63SDavid du Colombier * register local
103*8ccd4a63SDavid du Colombier * ulong *wp = %ebp
104*8ccd4a63SDavid du Colombier * ulong a = eax, b = ebx, c = ecx, d = edx, e = esi
105*8ccd4a63SDavid du Colombier * ulong tmp = edi
106*8ccd4a63SDavid du Colombier */
107*8ccd4a63SDavid du Colombier#define WARRAY	(STACKSIZE-4-(80*4))
108*8ccd4a63SDavid du Colombier#define TMP1	(STACKSIZE-8-(80*4))
109*8ccd4a63SDavid du Colombier#define TMP2	(STACKSIZE-12-(80*4))
110*8ccd4a63SDavid du Colombier#define W15	(STACKSIZE-16-(80*4))
111*8ccd4a63SDavid du Colombier#define W40	(STACKSIZE-20-(80*4))
112*8ccd4a63SDavid du Colombier#define W60	(STACKSIZE-24-(80*4))
113*8ccd4a63SDavid du Colombier#define W80	(STACKSIZE-28-(80*4))
114*8ccd4a63SDavid du Colombier#define EDATA	(STACKSIZE-32-(80*4))
115*8ccd4a63SDavid du Colombier#define OLDEBX	(STACKSIZE-36-(80*4))
116*8ccd4a63SDavid du Colombier#define OLDESI	(STACKSIZE-40-(80*4))
117*8ccd4a63SDavid du Colombier#define OLDEDI	(STACKSIZE-44-(80*4))
118*8ccd4a63SDavid du Colombier
119*8ccd4a63SDavid du Colombier	/* Prelude */
120*8ccd4a63SDavid du Colombier	pushl %ebp
121*8ccd4a63SDavid du Colombier	subl $(STACKSIZE), %esp
122*8ccd4a63SDavid du Colombier
123*8ccd4a63SDavid du Colombier	mov %ebx, OLDEBX(%esp)
124*8ccd4a63SDavid du Colombier	mov %esi, OLDESI(%esp)
125*8ccd4a63SDavid du Colombier	mov %edi, OLDEDI(%esp)
126*8ccd4a63SDavid du Colombier
127*8ccd4a63SDavid du Colombier	movl DATA(%esp), %eax
128*8ccd4a63SDavid du Colombier	addl LEN(%esp), %eax
129*8ccd4a63SDavid du Colombier	movl %eax, EDATA(%esp)
130*8ccd4a63SDavid du Colombier
131*8ccd4a63SDavid du Colombier	leal (WARRAY+15*4)(%esp), %edi	/* aw15 */
132*8ccd4a63SDavid du Colombier	movl %edi, W15(%esp)
133*8ccd4a63SDavid du Colombier	leal (WARRAY+40*4)(%esp), %edx	/* aw40 */
134*8ccd4a63SDavid du Colombier	movl %edx, W40(%esp)
135*8ccd4a63SDavid du Colombier	leal (WARRAY+60*4)(%esp), %ecx	/* aw60 */
136*8ccd4a63SDavid du Colombier	movl %ecx, W60(%esp)
137*8ccd4a63SDavid du Colombier	leal (WARRAY+80*4)(%esp), %edi	/* aw80 */
138*8ccd4a63SDavid du Colombier	movl %edi, W80(%esp)
139*8ccd4a63SDavid du Colombier
140*8ccd4a63SDavid du Colombier0:
141*8ccd4a63SDavid du Colombier	leal WARRAY(%esp), %ebp		/* warray */
142*8ccd4a63SDavid du Colombier
143*8ccd4a63SDavid du Colombier	movl STATE(%esp), %edi		/* state */
144*8ccd4a63SDavid du Colombier	movl (%edi),%eax
145*8ccd4a63SDavid du Colombier	movl 4(%edi),%ebx
146*8ccd4a63SDavid du Colombier	movl %ebx, TMP1(%esp)		/* tmp1 */
147*8ccd4a63SDavid du Colombier	movl 8(%edi), %ecx
148*8ccd4a63SDavid du Colombier	movl 12(%edi), %edx
149*8ccd4a63SDavid du Colombier	movl 16(%edi), %esi
150*8ccd4a63SDavid du Colombier
151*8ccd4a63SDavid du Colombier	movl DATA(%esp), %ebx		/* data */
152*8ccd4a63SDavid du Colombier
153*8ccd4a63SDavid du Colombier1:
154*8ccd4a63SDavid du Colombier	BODY0(0,FN1,0x5a827999,%eax,TMP1(%esp),%ecx,%edx,%esi)
155*8ccd4a63SDavid du Colombier	movl %esi,TMP2(%esp)
156*8ccd4a63SDavid du Colombier	BODY0(4,FN1,0x5a827999,%esi,%eax,TMP1(%esp),%ecx,%edx)
157*8ccd4a63SDavid du Colombier	movl TMP1(%esp),%esi
158*8ccd4a63SDavid du Colombier	BODY0(8,FN1,0x5a827999,%edx,TMP2(%esp),%eax,%esi,%ecx)
159*8ccd4a63SDavid du Colombier	BODY0(12,FN1,0x5a827999,%ecx,%edx,TMP2(%esp),%eax,%esi)
160*8ccd4a63SDavid du Colombier	movl %esi,TMP1(%esp)
161*8ccd4a63SDavid du Colombier	BODY0(16,FN1,0x5a827999,%esi,%ecx,%edx,TMP2(%esp),%eax)
162*8ccd4a63SDavid du Colombier	movl TMP2(%esp),%esi
163*8ccd4a63SDavid du Colombier
164*8ccd4a63SDavid du Colombier	addl $20, %ebx
165*8ccd4a63SDavid du Colombier	addl $20, %ebp
166*8ccd4a63SDavid du Colombier	cmpl W15(%esp), %ebp	/* w15 */
167*8ccd4a63SDavid du Colombier	jb 1b
168*8ccd4a63SDavid du Colombier
169*8ccd4a63SDavid du Colombier	BODY0(0,FN1,0x5a827999,%eax,TMP1(%esp),%ecx,%edx,%esi)
170*8ccd4a63SDavid du Colombier	addl $4, %ebx
171*8ccd4a63SDavid du Colombier	MOVL %ebx, DATA(%esp)	/* data */
172*8ccd4a63SDavid du Colombier	MOVL TMP1(%esp),%ebx
173*8ccd4a63SDavid du Colombier
174*8ccd4a63SDavid du Colombier	BODY(4,FN1,0x5a827999,%esi,%eax,%ebx,%ecx,%edx)
175*8ccd4a63SDavid du Colombier	BODY(8,FN1,0x5a827999,%edx,%esi,%eax,%ebx,%ecx)
176*8ccd4a63SDavid du Colombier	BODY(12,FN1,0x5a827999,%ecx,%edx,%esi,%eax,%ebx)
177*8ccd4a63SDavid du Colombier	BODY(16,FN1,0x5a827999,%ebx,%ecx,%edx,%esi,%eax)
178*8ccd4a63SDavid du Colombier
179*8ccd4a63SDavid du Colombier	addl $20, %ebp
180*8ccd4a63SDavid du Colombier
181*8ccd4a63SDavid du Colombier2:
182*8ccd4a63SDavid du Colombier	BODY(0,FN24,0x6ed9eba1,%eax,%ebx,%ecx,%edx,%esi)
183*8ccd4a63SDavid du Colombier	BODY(4,FN24,0x6ed9eba1,%esi,%eax,%ebx,%ecx,%edx)
184*8ccd4a63SDavid du Colombier	BODY(8,FN24,0x6ed9eba1,%edx,%esi,%eax,%ebx,%ecx)
185*8ccd4a63SDavid du Colombier	BODY(12,FN24,0x6ed9eba1,%ecx,%edx,%esi,%eax,%ebx)
186*8ccd4a63SDavid du Colombier	BODY(16,FN24,0x6ed9eba1,%ebx,%ecx,%edx,%esi,%eax)
187*8ccd4a63SDavid du Colombier
188*8ccd4a63SDavid du Colombier	addl $20,%ebp
189*8ccd4a63SDavid du Colombier	cmpl W40(%esp), %ebp
190*8ccd4a63SDavid du Colombier	jb 2b
191*8ccd4a63SDavid du Colombier
192*8ccd4a63SDavid du Colombier3:
193*8ccd4a63SDavid du Colombier	BODY(0,FN3,0x8f1bbcdc,%eax,%ebx,%ecx,%edx,%esi)
194*8ccd4a63SDavid du Colombier	BODY(4,FN3,0x8f1bbcdc,%esi,%eax,%ebx,%ecx,%edx)
195*8ccd4a63SDavid du Colombier	BODY(8,FN3,0x8f1bbcdc,%edx,%esi,%eax,%ebx,%ecx)
196*8ccd4a63SDavid du Colombier	BODY(12,FN3,0x8f1bbcdc,%ecx,%edx,%esi,%eax,%ebx)
197*8ccd4a63SDavid du Colombier	BODY(16,FN3,0x8f1bbcdc,%ebx,%ecx,%edx,%esi,%eax)
198*8ccd4a63SDavid du Colombier
199*8ccd4a63SDavid du Colombier	addl $20, %ebp
200*8ccd4a63SDavid du Colombier	cmpl W60(%esp), %ebp 	/* w60 */
201*8ccd4a63SDavid du Colombier	jb 3b
202*8ccd4a63SDavid du Colombier
203*8ccd4a63SDavid du Colombier4:
204*8ccd4a63SDavid du Colombier	BODY(0,FN24,0xca62c1d6,%eax,%ebx,%ecx,%edx,%esi)
205*8ccd4a63SDavid du Colombier	BODY(4,FN24,0xca62c1d6,%esi,%eax,%ebx,%ecx,%edx)
206*8ccd4a63SDavid du Colombier	BODY(8,FN24,0xca62c1d6,%edx,%esi,%eax,%ebx,%ecx)
207*8ccd4a63SDavid du Colombier	BODY(12,FN24,0xca62c1d6,%ecx,%edx,%esi,%eax,%ebx)
208*8ccd4a63SDavid du Colombier	BODY(16,FN24,0xca62c1d6,%ebx,%ecx,%edx,%esi,%eax)
209*8ccd4a63SDavid du Colombier
210*8ccd4a63SDavid du Colombier	addl $20, %ebp
211*8ccd4a63SDavid du Colombier	cmpl W80(%esp), %ebp 	/* w80 */
212*8ccd4a63SDavid du Colombier	jb 4b
213*8ccd4a63SDavid du Colombier
214*8ccd4a63SDavid du Colombier	movl STATE(%esp), %edi	/* state */
215*8ccd4a63SDavid du Colombier	addl %eax, 0(%edi)
216*8ccd4a63SDavid du Colombier	addl %ebx, 4(%edi)
217*8ccd4a63SDavid du Colombier	addl %ecx, 8(%edi)
218*8ccd4a63SDavid du Colombier	addl %edx, 12(%edi)
219*8ccd4a63SDavid du Colombier	addl %esi, 16(%edi)
220*8ccd4a63SDavid du Colombier
221*8ccd4a63SDavid du Colombier	movl EDATA(%esp), %edi	/* edata */
222*8ccd4a63SDavid du Colombier	cmpl %edi, DATA(%esp)	/* data */
223*8ccd4a63SDavid du Colombier	jb 0b
224*8ccd4a63SDavid du Colombier
225*8ccd4a63SDavid du Colombier	/* Postlude */
226*8ccd4a63SDavid du Colombier	mov OLDEBX(%esp), %ebx
227*8ccd4a63SDavid du Colombier	mov OLDESI(%esp), %esi
228*8ccd4a63SDavid du Colombier	mov OLDEDI(%esp), %edi
229*8ccd4a63SDavid du Colombier	addl $(STACKSIZE), %esp
230*8ccd4a63SDavid du Colombier	popl %ebp
231*8ccd4a63SDavid du Colombier	ret
232