Fix support for linux 3.x
[rrq/maintain_lilo.git] / src / shs3.S
1 ; shs3.S
2 /*
3 Copyright 2000-2004 John Coffman.
4 All rights reserved.
5
6 Licensed under the terms contained in the file 'COPYING' in the 
7 source directory.
8
9 */
10 ;
11 ;;;     group   dgroup _data
12
13 ;;;     segment _data public align=16 class=data
14
15 ;               global  _shsInfo
16 #ifdef BSS_DATA
17 #if 0
18                 .align  4
19 _shsInfo:
20 shs_digest:     .blkb   5*4
21 shs_count:      .blkb   2*4
22
23 Wshs:         .blkb     16*4
24 #else
25 _shsInfo        =       *
26 shs_digest      =       *
27                 .org    *+5*4
28 shs_count       =       *
29                 .org    *+2*4
30
31 Wshs            =       *
32                 .org    *+16*4
33 #endif
34 #else
35
36 ;;;     segment _text public align=16 class=code
37
38 #define Ashs eax
39 #define Bshs esi
40 #define Cshs ecx
41 #define Dshs edx
42 #define Eshs edi
43 #define temp_shs ebp
44
45 shsTransform:
46         push    bp
47         push    di
48         push    si
49
50         mov     di,#shs_digest    ;##
51         mov     Ashs,dword (di)
52         mov     Bshs,dword (di+4)
53         mov     Cshs,dword (di+8)
54         mov     Dshs,dword (di+12)
55         mov     Eshs,dword (di+16)
56         sub     bx,bx              ; count = 0
57
58 ;       align   4              ;align
59 shs_F356:
60         mov     temp_shs,Bshs
61         and     temp_shs,Cshs
62         push    Bshs
63         not     Bshs
64         and     Bshs,Dshs
65         or      temp_shs,Bshs
66         pop     Bshs
67         add     temp_shs,#0x5a827999    ;##
68
69         call    shsTransCommon
70         
71         cmp     bx,#20*4                ;##
72         jb      shs_F356
73
74 ;       align   4              ;align
75 shs_F359:
76         mov     temp_shs,Dshs
77         xor     temp_shs,Cshs
78         xor     temp_shs,Bshs
79         add     temp_shs,#0x6ed9eba1
80
81         call    shsTransCommon
82
83         cmp     bx,#40*4
84         jb      shs_F359
85
86 ;       align   4              ;align
87 shs_F362:
88         mov     temp_shs,Cshs
89         and     temp_shs,Bshs
90         push    Cshs
91         or      Cshs,Bshs
92         and     Cshs,Dshs
93         or      temp_shs,Cshs
94         pop     Cshs
95         sub     temp_shs,#0x70e44324
96
97         call    shsTransCommon
98         
99         cmp     bx,#60*4
100         jb      shs_F362
101
102 ;       align   4              ;align
103 shs_F365:
104         mov     temp_shs,Dshs
105         xor     temp_shs,Cshs
106         xor     temp_shs,Bshs
107         sub     temp_shs,#0x359d3e2a
108
109         call    shsTransCommon
110
111         cmp     bx,#80*4
112         jb      shs_F365
113
114         mov     bx,#shs_digest   ;##
115         add     dword (bx),Ashs
116         add     dword (bx+4),Bshs
117         add     dword (bx+8),Cshs
118         add     dword (bx+12),Dshs
119         add     dword (bx+16),Eshs
120
121         pop     si
122         pop     di
123         pop     bp
124         ret     
125
126 ;       align   4
127 shsTransCommon:
128         add     temp_shs,Eshs
129         mov     Eshs,Dshs
130         mov     Dshs,Cshs
131         ror     Bshs,2
132         mov     Cshs,Bshs
133         mov     Bshs,Ashs
134         rol     Ashs,5
135         add     temp_shs,Ashs
136         cmp     bx,#16*4
137         jae     shsJ1
138         mov     Ashs,dword Wshs(bx)
139         jmp     shsJ2
140 shsJ1:
141         push    bx
142         add     bx,#13*4
143         and     bx,#15*4
144         mov     Ashs,dword Wshs(bx)
145         sub     bx,#5*4
146         and     bx,#15*4
147         xor     Ashs,dword Wshs(bx)
148         sub     bx,#6*4
149         and     bx,#15*4
150         xor     Ashs,dword Wshs(bx)
151         sub     bx,#2*4
152         and     bx,#15*4
153         xor     Ashs,dword Wshs(bx)
154         rol     Ashs,1
155         mov     dword Wshs(bx),Ashs
156         pop     bx
157 shsJ2:
158         add     Ashs,temp_shs
159         add     bx,#4
160         ret
161
162 ;       align   4
163 byteReverse:
164         push    di
165         mov     cx,#16     ;##
166         mov     di,#Wshs            ;##
167
168 ;       align   4              ;align
169 shs_F376:
170         mov     eax,dword (di)
171 ;;;     bswap   eax
172         xchg    ah,al
173         rol     eax,16
174         xchg    ah,al
175
176         stosd
177         loop    shs_F376
178
179         pop     di
180         ret
181
182  
183
184
185 ;       align   4
186
187 ;       global  _shsInit, _shsUpdate, _shsFinal
188 _shsInit:
189         push    bp
190         mov     bp,sp
191 ;       push    ds
192         push    di
193
194         mov     di,#shs_digest                  ;##
195         mov     dword (di),#0x67452301          ;##
196         mov     dword (di+4),#0xefcdab89
197         mov     dword (di+8),#0x98badcfe
198         mov     dword (di+12),#0x10325476
199         mov     dword (di+16),#0xc3d2e1f0       ;##
200         sub     eax,eax
201         mov     dword (di+20),eax
202         mov     dword (di+24),eax
203
204         pop     di
205 ;       pop     ds
206         leave
207         ret
208
209
210 ;       align   4
211
212 _shsUpdate:
213         push    bp
214         mov     bp,sp
215
216 ;       buffer  [bp+4]
217 ;       count   [bp+6]
218
219         push    si
220         push    di
221 ;       push    ds
222
223         push    ds
224         pop     es
225
226 ;   remain = shsInfo.countLo & (SHS_BLOCKSIZE-1);
227         mov     di,[shs_count]
228         and     di,#63     ;##
229
230         movzx   eax,word (bp+6)      ;count
231         add     [shs_count],eax
232         adc     dword [shs_count+4],#0 ;##
233
234         mov     si,(bp+4)       ;buffer
235
236 shs_J4:
237         mov     cx,#64     ;##
238         sub     cx,di      ;CX = SHS_BLOCKSIZE-remain
239         cmp     ax,cx      ; count >= SHS_BLOCKSIZE-remain
240         jb      shs_J6
241
242         add     di,#Wshs            ;##
243         sub     ax,cx      ; count -= SHS_BLOCKSIZE-remain
244         push    ax
245         rep
246 #ifdef SHS_PASSWORDS
247           seg ss
248 #endif
249              movsb         ;memcpy
250
251         call    byteReverse
252         call    shsTransform
253
254         pop     ax
255         sub     di,di      ;remain
256         jmp     shs_J4
257 shs_J6:
258         add     di,#Wshs            ;##
259         mov     cx,ax
260         rep
261 #ifdef SHS_PASSWORDS
262           seg ss
263 #endif
264              movsb
265
266 ;       pop     ds
267         pop     di
268         pop     si
269         leave
270         ret
271
272 ;       align   4
273 _shsFinal:
274         push    bp
275         mov     bp,sp
276         push    si
277         push    di
278 ;       push    ds
279
280         push    ds
281         pop     es
282
283         mov     di,[shs_count]
284         and     di,#63     ;##
285         mov     byte Wshs(di),#0x80     ;##
286         inc     di
287         sub     ax,ax
288         cmp     di,#56     ;##
289         jbe     shs_J10
290 ; count > 56
291         mov     cx,#64
292         sub     cx,di      ;SHS_BLOCKSIZE - count
293         add     di,#Wshs            ;##
294         rep
295              stosb
296
297         call    byteReverse
298         call    shsTransform
299
300         mov     cx,#56                   ;##
301         mov     di,#Wshs                    ;##
302         sub     ax,ax
303         jmp     shs_J11
304 shs_J10:
305         mov     cx,#56     ;##
306         sub     cx,di
307         add     di,#Wshs            ;##
308 shs_J11:
309         rep
310              stosb
311         call    byteReverse
312         mov     eax,[shs_count]
313         mov     ebx,[shs_count+4]
314         shld    ebx,eax,3
315         shl     eax,3
316         mov     [Wshs+14*4],ebx
317         mov     [Wshs+15*4],eax
318         call    shsTransform
319
320 ;       pop     ds
321         pop     di
322         pop     si
323         leave
324         ret
325
326 #undef Ashs
327 #undef Bshs
328 #undef Cshs
329 #undef Dshs
330 #undef Eshs
331 #undef temp_shs
332
333 #endif  /* BSS_DATA */
334
335 ; end shs3.S
336