Subversion Repositories Kolibri OS

Rev

Rev 6465 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6465 Rev 7698
1
;    libcrash -- cryptographic hash functions
1
;    libcrash -- cryptographic hash functions
2
;
2
;
3
;    Copyright (C) 2012-2014,2016 Ivan Baravy (dunkaist)
3
;    Copyright (C) 2012-2014,2016 Ivan Baravy (dunkaist)
4
;
4
;
5
;    This program is free software: you can redistribute it and/or modify
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
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
7
;    the Free Software Foundation, either version 3 of the License, or
8
;    (at your option) any later version.
8
;    (at your option) any later version.
9
;
9
;
10
;    This program is distributed in the hope that it will be useful,
10
;    This program is distributed in the hope that it will be useful,
11
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;    GNU General Public License for more details.
13
;    GNU General Public License for more details.
14
;
14
;
15
;    You should have received a copy of the GNU General Public License
15
;    You should have received a copy of the GNU General Public License
16
;    along with this program.  If not, see .
16
;    along with this program.  If not, see .
17
 
17
 
18
format MS COFF
18
format MS COFF
19
 
19
 
20
public @EXPORT as 'EXPORTS'
20
public @EXPORT as 'EXPORTS'
21
 
21
 
22
include '../../../../struct.inc'
22
include 'struct.inc'
23
include '../../../../proc32.inc'
23
include 'proc32.inc'
24
include '../../../../macros.inc'
24
include 'macros.inc'
25
include '../../../../config.inc'
25
include 'config.inc'
26
;include '../../../../debug.inc'
26
include 'kglobals.inc'
27
 
27
 
28
purge section,mov,add,sub
28
purge section,mov,add,sub
29
section '.flat' code readable align 16
29
section '.flat' code readable align 16
30
 
30
 
31
include 'libcrash.inc'
31
include 'libcrash.inc'
32
include 'crc32.asm'
32
include 'crc32.asm'
33
include 'md4.asm'
33
include 'md4.asm'
34
include 'md5.asm'
34
include 'md5.asm'
35
include 'sha1.asm'
35
include 'sha1.asm'
36
include 'sha224_256.asm'
36
include 'sha224_256.asm'
37
include 'sha384_512.asm'
37
include 'sha384_512.asm'
38
include 'sha3.asm'
38
include 'sha3.asm'
39
 
39
 
40
 
40
 
41
proc lib_init
41
proc lib_init
42
        ret
42
        ret
43
endp
43
endp
44
 
44
 
45
 
45
 
46
proc crash.hash  _hid, _data, _callback, _ctx
46
proc crash.hash  _hid, _data, _callback, _ctx
47
locals
47
locals
48
        size dd ?
48
        size dd ?
49
endl
49
endl
50
        mov     [size], 0
50
        mov     [size], 0
51
        mov     eax, [_hid]
51
        mov     eax, [_hid]
52
        imul    eax, sizeof.crash_item
52
        imul    eax, sizeof.crash_item
53
        lea     edx, [crash._.table + eax]
53
        lea     edx, [crash._.table + eax]
54
        mov     ebx, [_ctx]
54
        mov     ebx, [_ctx]
55
 
55
 
56
        stdcall [edx + crash_item.init], [_ctx]
56
        stdcall [edx + crash_item.init], [_ctx]
57
 
57
 
58
  .hash:
58
  .hash:
59
        mov     esi, [_data]
59
        mov     esi, [_data]
60
        push    edx
60
        push    edx
61
        stdcall [edx + crash_item.update], [_ctx], [_data], [size]
61
        stdcall [edx + crash_item.update], [_ctx], [_data], [size]
62
        mov     [size], 0
62
        mov     [size], 0
63
        pop     edx
63
        pop     edx
64
 
64
 
65
        mov     eax, [_callback]
65
        mov     eax, [_callback]
66
        test    eax, eax
66
        test    eax, eax
67
        jz      .quit
67
        jz      .quit
68
        push    edx
68
        push    edx
69
        stdcall [_callback], [size]
69
        stdcall [_callback], [size]
70
        pop     edx
70
        pop     edx
71
        mov     [size], eax
71
        mov     [size], eax
72
        test    eax, eax
72
        test    eax, eax
73
        jnz     .hash
73
        jnz     .hash
74
 
74
 
75
        stdcall [edx + crash_item.final], [_ctx]
75
        stdcall [edx + crash_item.final], [_ctx]
76
  .quit:
76
  .quit:
77
        ret
77
        ret
78
endp
78
endp
79
 
79
 
80
 
80
 
81
proc crash.bin2hex _bin, _hex, _hid
81
proc crash.bin2hex _bin, _hex, _hid
82
        mov     eax, [_hid]
82
        mov     eax, [_hid]
83
        imul    eax, sizeof.crash_item
83
        imul    eax, sizeof.crash_item
84
        mov     ecx, [crash._.table + eax + crash_item.len_out]
84
        mov     ecx, [crash._.table + eax + crash_item.len_out]
85
        mov     ebx, crash._.bin2hex_table
85
        mov     ebx, crash._.bin2hex_table
86
        mov     esi, [_bin]
86
        mov     esi, [_bin]
87
        mov     edi, [_hex]
87
        mov     edi, [_hex]
88
  .next_byte:
88
  .next_byte:
89
        xor     eax, eax
89
        xor     eax, eax
90
        lodsb
90
        lodsb
91
        shl     eax, 4
91
        shl     eax, 4
92
        shr     al, 4
92
        shr     al, 4
93
        xlatb
93
        xlatb
94
        xchg    al, ah
94
        xchg    al, ah
95
        xlatb
95
        xlatb
96
        stosw
96
        stosw
97
        dec     ecx
97
        dec     ecx
98
        jnz     .next_byte
98
        jnz     .next_byte
99
        xor     al, al
99
        xor     al, al
100
        stosb
100
        stosb
101
        ret
101
        ret
102
endp
102
endp
103
 
103
 
104
 
104
 
105
section '.data' data readable align 16
105
section '.data' data readable align 16
106
crash._.bin2hex_table   db      '0123456789abcdef'
106
crash._.bin2hex_table   db '0123456789abcdef'
107
 
107
 
108
crash._.table   dd \
108
crash._.table   dd \
109
        crc32.init,   crc32.update,     crc32.final,     CRC32_HASH_SIZE,  \
109
        crc32.init,    crc32.update,      crc32.final,      crc32.oneshot,    CRC32_HASH_SIZE,  \
110
        md4.init,     md4.update,       md4.final,       MD4_HASH_SIZE,    \
110
        md4.init,      md4.update,        md4.final,        md4.oneshot,      MD4_HASH_SIZE,    \
111
        md5.init,     md5.update,       md5.final,       MD5_HASH_SIZE,    \
111
        md5.init,      md5.update,        md5.final,        md5.oneshot,      MD5_HASH_SIZE,    \
112
        sha1.init,    sha1.update,      sha1.final,      SHA1_HASH_SIZE,   \
112
        sha1.init,     sha1.update,       sha1.final,       sha1.oneshot,     SHA1_HASH_SIZE,   \
113
        sha224.init,  sha224.update,    sha224.final,    SHA224_HASH_SIZE, \
113
        sha224.init,   sha224.update,     sha224.final,     sha224.oneshot,   SHA224_HASH_SIZE, \
114
        sha256.init,  sha256.update,    sha256.final,    SHA256_HASH_SIZE, \
114
        sha256.init,   sha256.update,     sha256.final,     sha256.oneshot,   SHA256_HASH_SIZE, \
115
        sha384.init,  sha384.update,    sha384.final,    SHA384_HASH_SIZE, \
115
        sha384.init,   sha384.update,     sha384.final,     sha384.oneshot,   SHA384_HASH_SIZE, \
116
        sha512.init,  sha512.update,    sha512.final,    SHA512_HASH_SIZE, \
116
        sha512.init,   sha512.update,     sha512.final,     sha512.oneshot,   SHA512_HASH_SIZE, \
117
        sha3224.init, sha3224.update,   sha3224.final,   SHA3224_HASH_SIZE,\
117
        sha3_224.init, sha3_224.update,   sha3_224.final,   sha3_224.oneshot, SHA3_224_HASH_SIZE,\
118
        sha3256.init, sha3256.update,   sha3256.final,   SHA3256_HASH_SIZE,\
118
        sha3_256.init, sha3_256.update,   sha3_256.final,   sha3_256.oneshot, SHA3_256_HASH_SIZE,\
119
        sha3384.init, sha3384.update,   sha3384.final,   SHA3384_HASH_SIZE,\
119
        sha3_384.init, sha3_384.update,   sha3_384.final,   sha3_384.oneshot, SHA3_384_HASH_SIZE,\
120
        sha3512.init, sha3512.update,   sha3512.final,   SHA3512_HASH_SIZE
120
        sha3_512.init, sha3_512.update,   sha3_512.final,   sha3_512.oneshot, SHA3_512_HASH_SIZE
-
 
121
 
-
 
122
IncludeIGlobals
121
 
123
 
122
align 4
124
align 4
123
@EXPORT:
125
@EXPORT:
124
 
126
 
125
export                                          \
127
export                                          \
126
    lib_init,             'lib_init'            , \
128
    lib_init,             'lib_init'            , \
127
    crash.hash,           'crash_hash'          , \
129
    crash.hash,           'crash_hash'          , \
128
    crash.bin2hex,        'crash_bin2hex'       , \
130
    crash.bin2hex,        'crash_bin2hex'       , \
129
    crc32.init,           'crc32_init'          , \
131
    crc32.init,           'crc32_init'          , \
130
    crc32.update,         'crc32_update'        , \
132
    crc32.update,         'crc32_update'        , \
131
    crc32.final,          'crc32_final'         , \
133
    crc32.final,          'crc32_final'         , \
-
 
134
    crc32.oneshot,        'crc32_oneshot'       , \
132
    md4.init,             'md4_init'            , \
135
    md4.init,             'md4_init'            , \
133
    md4.update,           'md4_update'          , \
136
    md4.update,           'md4_update'          , \
134
    md4.final,            'md4_final'           , \
137
    md4.final,            'md4_final'           , \
-
 
138
    md4.oneshot,          'md4_oneshot'         , \
135
    md5.init,             'md5_init'            , \
139
    md5.init,             'md5_init'            , \
136
    md5.update,           'md5_update'          , \
140
    md5.update,           'md5_update'          , \
137
    md5.final,            'md5_final'           , \
141
    md5.final,            'md5_final'           , \
-
 
142
    md5.oneshot,          'md5_oneshot'         , \
138
    sha1.init,            'sha1_init'           , \
143
    sha1.init,            'sha1_init'           , \
139
    sha1.update,          'sha1_update'         , \
144
    sha1.update,          'sha1_update'         , \
140
    sha1.final,           'sha1_final'          , \
145
    sha1.final,           'sha1_final'          , \
-
 
146
    sha1.oneshot,         'sha1_oneshot'        , \
141
    sha224.init,          'sha224_init'         , \
147
    sha224.init,          'sha224_init'         , \
142
    sha224.update,        'sha224_update'       , \
148
    sha224.update,        'sha224_update'       , \
143
    sha224.final,         'sha224_final'        , \
149
    sha224.final,         'sha224_final'        , \
-
 
150
    sha224.oneshot,       'sha224_oneshot'      , \
144
    sha256.init,          'sha256_init'         , \
151
    sha256.init,          'sha256_init'         , \
145
    sha256.update,        'sha256_update'       , \
152
    sha256.update,        'sha256_update'       , \
146
    sha256.final,         'sha256_final'        , \
153
    sha256.final,         'sha256_final'        , \
-
 
154
    sha256.oneshot,       'sha256_oneshot'      , \
147
    sha384.init,          'sha384_init'         , \
155
    sha384.init,          'sha384_init'         , \
148
    sha384.update,        'sha384_update'       , \
156
    sha384.update,        'sha384_update'       , \
149
    sha384.final,         'sha384_final'        , \
157
    sha384.final,         'sha384_final'        , \
-
 
158
    sha384.oneshot,       'sha384_oneshot'      , \
150
    sha512.init,          'sha512_init'         , \
159
    sha512.init,          'sha512_init'         , \
151
    sha512.update,        'sha512_update'       , \
160
    sha512.update,        'sha512_update'       , \
152
    sha512.final,         'sha512_final'        , \
161
    sha512.final,         'sha512_final'        , \
-
 
162
    sha512.oneshot,       'sha512_oneshot'      , \
153
    sha3224.init,         'sha3_224_init'       , \
163
    sha3_224.init,        'sha3_224_init'       , \
154
    sha3224.update,       'sha3_224_update'     , \
164
    sha3_224.update,      'sha3_224_update'     , \
155
    sha3224.final,        'sha3_224_final'      , \
165
    sha3_224.final,       'sha3_224_final'      , \
-
 
166
    sha3_224.oneshot,     'sha3_224_oneshot'    , \
156
    sha3256.init,         'sha3_256_init'       , \
167
    sha3_256.init,        'sha3_256_init'       , \
157
    sha3256.update,       'sha3_256_update'     , \
168
    sha3_256.update,      'sha3_256_update'     , \
158
    sha3256.final,        'sha3_256_final'      , \
169
    sha3_256.final,       'sha3_256_final'      , \
-
 
170
    sha3_256.oneshot,     'sha3_256_oneshot'    , \
159
    sha3384.init,         'sha3_384_init'       , \
171
    sha3_384.init,        'sha3_384_init'       , \
160
    sha3384.update,       'sha3_384_update'     , \
172
    sha3_384.update,      'sha3_384_update'     , \
161
    sha3384.final,        'sha3_384_final'      , \
173
    sha3_384.final,       'sha3_384_final'      , \
-
 
174
    sha3_384.oneshot,     'sha3_384_oneshot'    , \
162
    sha3512.init,         'sha3_512_init'       , \
175
    sha3_512.init,        'sha3_512_init'       , \
163
    sha3512.update,       'sha3_512_update'     , \
176
    sha3_512.update,      'sha3_512_update'     , \
164
    sha3512.final,        'sha3_512_final'
177
    sha3_512.final,       'sha3_512_final'      , \
-
 
178
    sha3_512.oneshot,     'sha3_512_oneshot'