Subversion Repositories Kolibri OS

Rev

Rev 3532 | 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 '../../../../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,  sha224256.update, sha224256.final, SHA224_HASH_SIZE, \
  114.         sha256.init,  sha224256.update, sha224256.final, SHA256_HASH_SIZE, \
  115.         sha384.init,  sha384512.update, sha384512.final, SHA384_HASH_SIZE, \
  116.         sha512.init,  sha384512.update, sha384512.final, SHA512_HASH_SIZE, \
  117.         sha3224.init, sha3.update,      sha3.final,      SHA3224_HASH_SIZE,\
  118.         sha3256.init, sha3.update,      sha3.final,      SHA3256_HASH_SIZE,\
  119.         sha3384.init, sha3.update,      sha3.final,      SHA3384_HASH_SIZE,\
  120.         sha3512.init, sha3.update,      sha3.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.  
  130.