Subversion Repositories Kolibri OS

Rev

Rev 3115 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3431 dunkaist 1
;    libcrash -- cryptographic hash functions
2
;
3
;    Copyright (C) 2012-2013 Ivan Baravy (dunkaist)
4
;
5
;    This program is free software: you can redistribute it and/or modify
6
;    it under the terms of the GNU General Public License as published by
7
;    the Free Software Foundation, either version 3 of the License, or
8
;    (at your option) any later version.
9
;
10
;    This program is distributed in the hope that it will be useful,
11
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;    GNU General Public License for more details.
14
;
15
;    You should have received a copy of the GNU General Public License
16
;    along with this program.  If not, see .
17
 
3115 dunkaist 18
proc crash.sha1.f
19
	push	ebx ecx edx
20
	xor	ecx, edx
21
	and	ebx, ecx
22
	xor	ebx, edx
23
	mov	esi, ebx
24
	pop	edx ecx ebx
25
	ret
26
endp
27
 
28
proc crash.sha1.g
29
	push	ebx ecx edx
30
	xor	ebx, ecx
31
	xor	ebx, edx
32
	mov	esi, ebx
33
	pop	edx ecx ebx
34
	ret
35
endp
36
 
37
proc crash.sha1.h
38
	push	ebx ecx edx
39
	mov	esi, ebx
40
	and	ebx, ecx
41
	and	ecx, edx
42
	and	esi, edx
43
	or	ebx, ecx
44
	or	esi, ebx
45
	pop	edx ecx ebx
46
	ret
47
endp
48
 
3431 dunkaist 49
macro crash.sha1.round f, k, c
50
{
51
	mov	esi, eax
52
	rol	esi, 5
53
	mov	[temp], esi
54
	call	f
3115 dunkaist 55
 
3431 dunkaist 56
	add	esi, edi
57
	add	[temp], esi
58
	mov	esi, [w + (c)*4]
59
	add	esi, k
60
	add	[temp], esi
61
 
62
	mov	edi, edx
63
	mov	edx, ecx
64
	mov	ecx, ebx
65
	rol	ecx, 30
66
	mov	ebx, eax
67
	mov	eax, [temp]
68
}
69
 
70
 
71
proc crash.sha1 _sha1, _data
3115 dunkaist 72
locals
3431 dunkaist 73
	temp	 rd 1
74
	w	 rd 80
3115 dunkaist 75
endl
76
	lea	edi, [w]
77
	xor	ecx, ecx
78
    @@:
79
	mov	eax, [esi]
80
	add	esi, 4
81
	bswap	eax
82
	mov	[edi], eax
83
	add	edi, 4
84
	add	ecx, 1
85
	cmp	ecx, 16
86
	jne	@b
87
    @@:
88
	mov	eax, [w + (ecx -  3)*4]
89
	xor	eax, [w + (ecx -  8)*4]
90
	xor	eax, [w + (ecx - 14)*4]
91
	xor	eax, [w + (ecx - 16)*4]
92
	rol	eax, 1
93
	mov	[w + ecx*4], eax
94
	add	ecx, 1
95
	cmp	ecx, 80
96
	jne	@b
97
 
98
	mov	edi, [_sha1]
99
	mov	eax, [edi + 0x00]
100
	mov	ebx, [edi + 0x04]
101
	mov	ecx, [edi + 0x08]
102
	mov	edx, [edi + 0x0c]
103
	mov	edi, [edi + 0x10]
104
 
105
	push	esi
106
 
3431 dunkaist 107
repeat 20
108
	crash.sha1.round	crash.sha1.f, 0x5a827999, %-1
109
end repeat
3115 dunkaist 110
 
3431 dunkaist 111
repeat 20
112
	crash.sha1.round	crash.sha1.g, 0x6ed9eba1, %-1+20
113
end repeat
3115 dunkaist 114
 
3431 dunkaist 115
repeat 20
116
	crash.sha1.round	crash.sha1.h, 0x8f1bbcdc, %-1+40
117
end repeat
3115 dunkaist 118
 
3431 dunkaist 119
repeat 20
120
	crash.sha1.round	crash.sha1.g, 0xca62c1d6, %-1+60
121
end repeat
3115 dunkaist 122
 
123
	pop	esi
124
 
125
	mov	[temp], edi
126
	mov	edi, [_sha1]
127
	add	[edi + 0x00], eax
128
	add	[edi + 0x04], ebx
129
	add	[edi + 0x08], ecx
130
	add	[edi + 0x0c], edx
131
	mov	eax, [temp]
132
	add	[edi + 0x10], eax
133
 
134
	ret
135
endp
136