Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
6465 hidnplayr 1
;    libcrash -- cryptographic hash functions
2
;
3
;    Copyright (C) 2012-2014,2016 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
 
18
format MS COFF
19
 
20
public @EXPORT as 'EXPORTS'
21
 
22
include '../../../../struct.inc'
23
include '../../../../proc32.inc'
24
include '../../../../macros.inc'
25
include '../../../../config.inc'
26
;include '../../../../debug.inc'
27
 
28
purge section,mov,add,sub
29
section '.flat' code readable align 16
30
 
31
include 'libcrash.inc'
32
include 'crc32.asm'
33
include 'md4.asm'
34
include 'md5.asm'
35
include 'sha1.asm'
36
include 'sha224_256.asm'
37
include 'sha384_512.asm'
38
include 'sha3.asm'
39
 
40
 
41
proc lib_init
42
        ret
43
endp
44
 
45
 
46
proc crash.hash  _hid, _data, _callback, _ctx
47
locals
48
        size dd ?
49
endl
50
        mov     [size], 0
51
        mov     eax, [_hid]
52
        imul    eax, sizeof.crash_item
53
        lea     edx, [crash._.table + eax]
54
        mov     ebx, [_ctx]
55
 
56
        stdcall [edx + crash_item.init], [_ctx]
57
 
58
  .hash:
59
        mov     esi, [_data]
60
        push    edx
61
        stdcall [edx + crash_item.update], [_ctx], [_data], [size]
62
        mov     [size], 0
63
        pop     edx
64
 
65
        mov     eax, [_callback]
66
        test    eax, eax
67
        jz      .quit
68
        push    edx
69
        stdcall [_callback], [size]
70
        pop     edx
71
        mov     [size], eax
72
        test    eax, eax
73
        jnz     .hash
74
 
75
        stdcall [edx + crash_item.final], [_ctx]
76
  .quit:
77
        ret
78
endp
79
 
80
 
81
proc crash.bin2hex _bin, _hex, _hid
82
        mov     eax, [_hid]
83
        imul    eax, sizeof.crash_item
84
        mov     ecx, [crash._.table + eax + crash_item.len_out]
85
        mov     ebx, crash._.bin2hex_table
86
        mov     esi, [_bin]
87
        mov     edi, [_hex]
88
  .next_byte:
89
        xor     eax, eax
90
        lodsb
91
        shl     eax, 4
92
        shr     al, 4
93
        xlatb
94
        xchg    al, ah
95
        xlatb
96
        stosw
97
        dec     ecx
98
        jnz     .next_byte
99
        xor     al, al
100
        stosb
101
        ret
102
endp
103
 
104
 
105
section '.data' data readable align 16
106
crash._.bin2hex_table   db      '0123456789abcdef'
107
 
108
crash._.table   dd \
109
        crc32.init,   crc32.update,     crc32.final,     CRC32_HASH_SIZE,  \
110
        md4.init,     md4.update,       md4.final,       MD4_HASH_SIZE,    \
111
        md5.init,     md5.update,       md5.final,       MD5_HASH_SIZE,    \
112
        sha1.init,    sha1.update,      sha1.final,      SHA1_HASH_SIZE,   \
113
        sha224.init,  sha224.update,    sha224.final,    SHA224_HASH_SIZE, \
114
        sha256.init,  sha256.update,    sha256.final,    SHA256_HASH_SIZE, \
115
        sha384.init,  sha384.update,    sha384.final,    SHA384_HASH_SIZE, \
116
        sha512.init,  sha512.update,    sha512.final,    SHA512_HASH_SIZE, \
117
        sha3224.init, sha3224.update,   sha3224.final,   SHA3224_HASH_SIZE,\
118
        sha3256.init, sha3256.update,   sha3256.final,   SHA3256_HASH_SIZE,\
119
        sha3384.init, sha3384.update,   sha3384.final,   SHA3384_HASH_SIZE,\
120
        sha3512.init, sha3512.update,   sha3512.final,   SHA3512_HASH_SIZE
121
 
122
align 4
123
@EXPORT:
124
 
125
export                                          \
126
    lib_init,             'lib_init'            , \
127
    crash.hash,           'crash_hash'          , \
128
    crash.bin2hex,        'crash_bin2hex'       , \
129
    crc32.init,           'crc32_init'          , \
130
    crc32.update,         'crc32_update'        , \
131
    crc32.final,          'crc32_final'         , \
132
    md4.init,             'md4_init'            , \
133
    md4.update,           'md4_update'          , \
134
    md4.final,            'md4_final'           , \
135
    md5.init,             'md5_init'            , \
136
    md5.update,           'md5_update'          , \
137
    md5.final,            'md5_final'           , \
138
    sha1.init,            'sha1_init'           , \
139
    sha1.update,          'sha1_update'         , \
140
    sha1.final,           'sha1_final'          , \
141
    sha224.init,          'sha224_init'         , \
142
    sha224.update,        'sha224_update'       , \
143
    sha224.final,         'sha224_final'        , \
144
    sha256.init,          'sha256_init'         , \
145
    sha256.update,        'sha256_update'       , \
146
    sha256.final,         'sha256_final'        , \
147
    sha384.init,          'sha384_init'         , \
148
    sha384.update,        'sha384_update'       , \
149
    sha384.final,         'sha384_final'        , \
150
    sha512.init,          'sha512_init'         , \
151
    sha512.update,        'sha512_update'       , \
152
    sha512.final,         'sha512_final'        , \
153
    sha3224.init,         'sha3_224_init'       , \
154
    sha3224.update,       'sha3_224_update'     , \
155
    sha3224.final,        'sha3_224_final'      , \
156
    sha3256.init,         'sha3_256_init'       , \
157
    sha3256.update,       'sha3_256_update'     , \
158
    sha3256.final,        'sha3_256_final'      , \
159
    sha3384.init,         'sha3_384_init'       , \
160
    sha3384.update,       'sha3_384_update'     , \
161
    sha3384.final,        'sha3_384_final'      , \
162
    sha3512.init,         'sha3_512_init'       , \
163
    sha3512.update,       'sha3_512_update'     , \
164
    sha3512.final,        'sha3_512_final'