Subversion Repositories Kolibri OS

Rev

Rev 6465 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  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 <http://www.gnu.org/licenses/>.
  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 'kglobals.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.oneshot,    CRC32_HASH_SIZE,  \
  110.         md4.init,      md4.update,        md4.final,        md4.oneshot,      MD4_HASH_SIZE,    \
  111.         md5.init,      md5.update,        md5.final,        md5.oneshot,      MD5_HASH_SIZE,    \
  112.         sha1.init,     sha1.update,       sha1.final,       sha1.oneshot,     SHA1_HASH_SIZE,   \
  113.         sha224.init,   sha224.update,     sha224.final,     sha224.oneshot,   SHA224_HASH_SIZE, \
  114.         sha256.init,   sha256.update,     sha256.final,     sha256.oneshot,   SHA256_HASH_SIZE, \
  115.         sha384.init,   sha384.update,     sha384.final,     sha384.oneshot,   SHA384_HASH_SIZE, \
  116.         sha512.init,   sha512.update,     sha512.final,     sha512.oneshot,   SHA512_HASH_SIZE, \
  117.         sha3_224.init, sha3_224.update,   sha3_224.final,   sha3_224.oneshot, SHA3_224_HASH_SIZE,\
  118.         sha3_256.init, sha3_256.update,   sha3_256.final,   sha3_256.oneshot, SHA3_256_HASH_SIZE,\
  119.         sha3_384.init, sha3_384.update,   sha3_384.final,   sha3_384.oneshot, SHA3_384_HASH_SIZE,\
  120.         sha3_512.init, sha3_512.update,   sha3_512.final,   sha3_512.oneshot, SHA3_512_HASH_SIZE
  121.  
  122. IncludeIGlobals
  123.  
  124. align 4
  125. @EXPORT:
  126.  
  127. export                                          \
  128.     lib_init,             'lib_init'            , \
  129.     crash.hash,           'crash_hash'          , \
  130.     crash.bin2hex,        'crash_bin2hex'       , \
  131.     crc32.init,           'crc32_init'          , \
  132.     crc32.update,         'crc32_update'        , \
  133.     crc32.final,          'crc32_final'         , \
  134.     crc32.oneshot,        'crc32_oneshot'       , \
  135.     md4.init,             'md4_init'            , \
  136.     md4.update,           'md4_update'          , \
  137.     md4.final,            'md4_final'           , \
  138.     md4.oneshot,          'md4_oneshot'         , \
  139.     md5.init,             'md5_init'            , \
  140.     md5.update,           'md5_update'          , \
  141.     md5.final,            'md5_final'           , \
  142.     md5.oneshot,          'md5_oneshot'         , \
  143.     sha1.init,            'sha1_init'           , \
  144.     sha1.update,          'sha1_update'         , \
  145.     sha1.final,           'sha1_final'          , \
  146.     sha1.oneshot,         'sha1_oneshot'        , \
  147.     sha224.init,          'sha224_init'         , \
  148.     sha224.update,        'sha224_update'       , \
  149.     sha224.final,         'sha224_final'        , \
  150.     sha224.oneshot,       'sha224_oneshot'      , \
  151.     sha256.init,          'sha256_init'         , \
  152.     sha256.update,        'sha256_update'       , \
  153.     sha256.final,         'sha256_final'        , \
  154.     sha256.oneshot,       'sha256_oneshot'      , \
  155.     sha384.init,          'sha384_init'         , \
  156.     sha384.update,        'sha384_update'       , \
  157.     sha384.final,         'sha384_final'        , \
  158.     sha384.oneshot,       'sha384_oneshot'      , \
  159.     sha512.init,          'sha512_init'         , \
  160.     sha512.update,        'sha512_update'       , \
  161.     sha512.final,         'sha512_final'        , \
  162.     sha512.oneshot,       'sha512_oneshot'      , \
  163.     sha3_224.init,        'sha3_224_init'       , \
  164.     sha3_224.update,      'sha3_224_update'     , \
  165.     sha3_224.final,       'sha3_224_final'      , \
  166.     sha3_224.oneshot,     'sha3_224_oneshot'    , \
  167.     sha3_256.init,        'sha3_256_init'       , \
  168.     sha3_256.update,      'sha3_256_update'     , \
  169.     sha3_256.final,       'sha3_256_final'      , \
  170.     sha3_256.oneshot,     'sha3_256_oneshot'    , \
  171.     sha3_384.init,        'sha3_384_init'       , \
  172.     sha3_384.update,      'sha3_384_update'     , \
  173.     sha3_384.final,       'sha3_384_final'      , \
  174.     sha3_384.oneshot,     'sha3_384_oneshot'    , \
  175.     sha3_512.init,        'sha3_512_init'       , \
  176.     sha3_512.update,      'sha3_512_update'     , \
  177.     sha3_512.final,       'sha3_512_final'      , \
  178.     sha3_512.oneshot,     'sha3_512_oneshot'
  179.