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