libcrash: Sync with upstream.

* Add oneshot wrappers.
* Move tables to data section.
* Add/rename macros and fix their use in ssh.

git-svn-id: svn://kolibrios.org@7698 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Ivan Baravy 2019-10-21 22:33:41 +00:00
parent 488a034278
commit b51d135d5c
15 changed files with 2631 additions and 2448 deletions

View File

@ -1,3 +1,5 @@
if tup.getconfig("NO_FASM") ~= "" then return end
tup.rule("libcrash.asm", "fasm %f %o " .. tup.getconfig("KPACK_CMD"), "libcrash.obj")
tup.rule("crashtest.asm", "fasm %f %o " .. tup.getconfig("KPACK_CMD"), "crashtest")
HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../../.." or tup.getconfig("HELPERDIR")
tup.include(HELPERDIR .. "/use_fasm.lua")
tup.rule("libcrash.asm", FASM .. " %f %o " .. tup.getconfig("KPACK_CMD"), "libcrash.obj")
tup.rule("crashtest.asm", FASM .. " %f %o " .. tup.getconfig("KPACK_CMD"), "crashtest")

View File

@ -1,6 +1,6 @@
; libcrash -- cryptographic hash functions
;
; Copyright (C) 2012-2013,2016 Ivan Baravy (dunkaist)
; Copyright (C) 2012-2013,2016,2019 Ivan Baravy (dunkaist)
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
@ -16,6 +16,19 @@
; along with this program. If not, see <http://www.gnu.org/licenses/>.
CRC32_HASH_SIZE = 4
CRC32_ALIGN = 4
CRC32_ALIGN_MASK = CRC32_ALIGN - 1
struct ctx_crc32
hash rd 1
ends
if defined sizeof.crash_ctx
assert sizeof.crash_ctx >= sizeof.ctx_crc32
end if
proc crc32.init _ctx
mov ebx, [_ctx]
lea edi, [ebx + ctx_crc32.hash]
@ -61,8 +74,16 @@ proc crc32.final _ctx
endp
align CRC32_ALIGN
proc crc32.oneshot _ctx, _data, _len
stdcall crc32.init, [_ctx]
stdcall crc32.update, [_ctx], [_data], [_len]
stdcall crc32.final, [_ctx]
ret
endp
iglobal
align CRC32_ALIGN
crc32._.hash_init dd 0xffffffff
crc32._.table dd \
@ -109,4 +130,4 @@ crc32._.table dd \
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,\
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
endg

View File

@ -19,11 +19,11 @@ format MS COFF
public @EXPORT as 'EXPORTS'
include '../../../../struct.inc'
include '../../../../proc32.inc'
include '../../../../macros.inc'
include '../../../../config.inc'
;include '../../../../debug.inc'
include 'struct.inc'
include 'proc32.inc'
include 'macros.inc'
include 'config.inc'
include 'kglobals.inc'
purge section,mov,add,sub
section '.flat' code readable align 16
@ -106,18 +106,20 @@ section '.data' data readable align 16
crash._.bin2hex_table db '0123456789abcdef'
crash._.table dd \
crc32.init, crc32.update, crc32.final, CRC32_HASH_SIZE, \
md4.init, md4.update, md4.final, MD4_HASH_SIZE, \
md5.init, md5.update, md5.final, MD5_HASH_SIZE, \
sha1.init, sha1.update, sha1.final, SHA1_HASH_SIZE, \
sha224.init, sha224.update, sha224.final, SHA224_HASH_SIZE, \
sha256.init, sha256.update, sha256.final, SHA256_HASH_SIZE, \
sha384.init, sha384.update, sha384.final, SHA384_HASH_SIZE, \
sha512.init, sha512.update, sha512.final, SHA512_HASH_SIZE, \
sha3224.init, sha3224.update, sha3224.final, SHA3224_HASH_SIZE,\
sha3256.init, sha3256.update, sha3256.final, SHA3256_HASH_SIZE,\
sha3384.init, sha3384.update, sha3384.final, SHA3384_HASH_SIZE,\
sha3512.init, sha3512.update, sha3512.final, SHA3512_HASH_SIZE
crc32.init, crc32.update, crc32.final, crc32.oneshot, CRC32_HASH_SIZE, \
md4.init, md4.update, md4.final, md4.oneshot, MD4_HASH_SIZE, \
md5.init, md5.update, md5.final, md5.oneshot, MD5_HASH_SIZE, \
sha1.init, sha1.update, sha1.final, sha1.oneshot, SHA1_HASH_SIZE, \
sha224.init, sha224.update, sha224.final, sha224.oneshot, SHA224_HASH_SIZE, \
sha256.init, sha256.update, sha256.final, sha256.oneshot, SHA256_HASH_SIZE, \
sha384.init, sha384.update, sha384.final, sha384.oneshot, SHA384_HASH_SIZE, \
sha512.init, sha512.update, sha512.final, sha512.oneshot, SHA512_HASH_SIZE, \
sha3_224.init, sha3_224.update, sha3_224.final, sha3_224.oneshot, SHA3_224_HASH_SIZE,\
sha3_256.init, sha3_256.update, sha3_256.final, sha3_256.oneshot, SHA3_256_HASH_SIZE,\
sha3_384.init, sha3_384.update, sha3_384.final, sha3_384.oneshot, SHA3_384_HASH_SIZE,\
sha3_512.init, sha3_512.update, sha3_512.final, sha3_512.oneshot, SHA3_512_HASH_SIZE
IncludeIGlobals
align 4
@EXPORT:
@ -129,36 +131,48 @@ export \
crc32.init, 'crc32_init' , \
crc32.update, 'crc32_update' , \
crc32.final, 'crc32_final' , \
crc32.oneshot, 'crc32_oneshot' , \
md4.init, 'md4_init' , \
md4.update, 'md4_update' , \
md4.final, 'md4_final' , \
md4.oneshot, 'md4_oneshot' , \
md5.init, 'md5_init' , \
md5.update, 'md5_update' , \
md5.final, 'md5_final' , \
md5.oneshot, 'md5_oneshot' , \
sha1.init, 'sha1_init' , \
sha1.update, 'sha1_update' , \
sha1.final, 'sha1_final' , \
sha1.oneshot, 'sha1_oneshot' , \
sha224.init, 'sha224_init' , \
sha224.update, 'sha224_update' , \
sha224.final, 'sha224_final' , \
sha224.oneshot, 'sha224_oneshot' , \
sha256.init, 'sha256_init' , \
sha256.update, 'sha256_update' , \
sha256.final, 'sha256_final' , \
sha256.oneshot, 'sha256_oneshot' , \
sha384.init, 'sha384_init' , \
sha384.update, 'sha384_update' , \
sha384.final, 'sha384_final' , \
sha384.oneshot, 'sha384_oneshot' , \
sha512.init, 'sha512_init' , \
sha512.update, 'sha512_update' , \
sha512.final, 'sha512_final' , \
sha3224.init, 'sha3_224_init' , \
sha3224.update, 'sha3_224_update' , \
sha3224.final, 'sha3_224_final' , \
sha3256.init, 'sha3_256_init' , \
sha3256.update, 'sha3_256_update' , \
sha3256.final, 'sha3_256_final' , \
sha3384.init, 'sha3_384_init' , \
sha3384.update, 'sha3_384_update' , \
sha3384.final, 'sha3_384_final' , \
sha3512.init, 'sha3_512_init' , \
sha3512.update, 'sha3_512_update' , \
sha3512.final, 'sha3_512_final'
sha512.oneshot, 'sha512_oneshot' , \
sha3_224.init, 'sha3_224_init' , \
sha3_224.update, 'sha3_224_update' , \
sha3_224.final, 'sha3_224_final' , \
sha3_224.oneshot, 'sha3_224_oneshot' , \
sha3_256.init, 'sha3_256_init' , \
sha3_256.update, 'sha3_256_update' , \
sha3_256.final, 'sha3_256_final' , \
sha3_256.oneshot, 'sha3_256_oneshot' , \
sha3_384.init, 'sha3_384_init' , \
sha3_384.update, 'sha3_384_update' , \
sha3_384.final, 'sha3_384_final' , \
sha3_384.oneshot, 'sha3_384_oneshot' , \
sha3_512.init, 'sha3_512_init' , \
sha3_512.update, 'sha3_512_update' , \
sha3_512.final, 'sha3_512_final' , \
sha3_512.oneshot, 'sha3_512_oneshot'

View File

@ -1,6 +1,6 @@
; libcrash -- cryptographic hash functions
;
; Copyright (C) 2012-2014,2016 Ivan Baravy (dunkaist)
; Copyright (C) 2012-2014,2016,2019 Ivan Baravy (dunkaist)
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
@ -35,141 +35,47 @@ struct crash_item
init dd ?
update dd ?
final dd ?
oneshot dd ?
len_out dd ?
ends
; CRC32
struct crash_ctx
hash rb 1024 ; context starts with hash data
ends
CRC32_HASH_SIZE = 4
CRC32_ALIGN = 4
CRC32_ALIGN_MASK = CRC32_ALIGN - 1
CRC32_BLOCK_SIZE = 1
struct ctx_crc32
hash rd 1
ends
; MD4
MD4_BLOCK_SIZE = 64
MD4_HASH_SIZE = 16
MD4_ALIGN = 4
MD4_ALIGN_MASK = MD4_ALIGN - 1
MD4_BLOCK_SIZE = 64
struct ctx_md4
hash rb MD4_HASH_SIZE
block rb MD4_BLOCK_SIZE
index rd 1
msglen_0 rd 1
msglen_1 rd 1
ends
; MD5
MD5_BLOCK_SIZE = 64
MD5_HASH_SIZE = 16
MD5_ALIGN = 4
MD5_ALIGN_MASK = MD5_ALIGN - 1
MD5_BLOCK_SIZE = 64
struct ctx_md5
hash rb MD5_HASH_SIZE
block rb MD5_BLOCK_SIZE
index rd 1
msglen_0 rd 1
msglen_1 rd 1
ends
; SHA1
SHA1_BLOCK_SIZE = 64
SHA1_HASH_SIZE = 20
SHA1_ALIGN = 4
SHA1_ALIGN_MASK = SHA1_ALIGN - 1
SHA1_BLOCK_SIZE = 64
struct ctx_sha1
hash rb SHA1_HASH_SIZE
block rb SHA1_BLOCK_SIZE
index rd 1
msglen_0 rd 1
msglen_1 rd 1
ends
; SHA2
SHA224256_BLOCK_SIZE = 64
SHA224256_INIT_SIZE = 32
SHA224_HASH_SIZE = 28
SHA224_BLOCK_SIZE = 64
SHA256_HASH_SIZE = 32
SHA224256_ALIGN = 4
SHA224256_ALIGN_MASK = SHA224256_ALIGN - 1
struct ctx_sha224256
hash rb SHA224256_INIT_SIZE
block rb SHA224256_BLOCK_SIZE
index rd 1
msglen_0 rd 1
msglen_1 rd 1
ends
SHA384512_BLOCK_SIZE = 128
SHA384512_INIT_SIZE = 64
SHA256_BLOCK_SIZE = 64
SHA384_HASH_SIZE = 48
SHA384_BLOCK_SIZE = 128
SHA512_HASH_SIZE = 64
SHA512_BLOCK_SIZE = 128
SHA384512_ALIGN = 16
SHA384512_ALIGN_MASK = SHA384512_ALIGN - 1
SHA3_224_HASH_SIZE = 28
SHA3_224_BLOCK_SIZE = 144
struct ctx_sha384512
hash rb SHA384512_INIT_SIZE
block rb SHA384512_BLOCK_SIZE
index rd 1
msglen_0 rd 1
msglen_1 rd 1
msglen_2 rd 1
msglen_3 rd 1
rd 3 ; align
; tmp vars
w rq 80
A rq 1
B rq 1
C rq 1
D rq 1
E rq 1
F rq 1
G rq 1
H rq 1
temp rq 1
ends
SHA3_256_HASH_SIZE = 32
SHA3_256_BLOCK_SIZE = 136
; SHA3
SHA3224_BLOCK_SIZE = 144
SHA3256_BLOCK_SIZE = 136
SHA3384_BLOCK_SIZE = 104
SHA3512_BLOCK_SIZE = 72
SHA3MAX_BLOCK_SIZE = SHA3224_BLOCK_SIZE
SHA3_INIT_SIZE = 200
SHA3224_HASH_SIZE = 28
SHA3256_HASH_SIZE = 32
SHA3384_HASH_SIZE = 48
SHA3512_HASH_SIZE = 64
SHA3_ALIGN = 16
SHA3_ALIGN_MASK = SHA3_ALIGN-1
struct ctx_sha3
hash rb SHA3_INIT_SIZE
rb SHA3_ALIGN - (SHA3_INIT_SIZE mod SHA3_ALIGN)
block rb SHA3MAX_BLOCK_SIZE
rb SHA3_ALIGN - (SHA3MAX_BLOCK_SIZE mod SHA3_ALIGN)
index rd 1
block_size rd 1
rounds_cnt rd 1
rd 1 ; align
; tmp vars
C rq 5
D rq 5
ends
SHA3_384_HASH_SIZE = 48
SHA3_384_BLOCK_SIZE = 104
SHA3_512_HASH_SIZE = 64
SHA3_512_BLOCK_SIZE = 72

View File

@ -1,6 +1,6 @@
; libcrash -- cryptographic hash functions
;
; Copyright (C) 2012-2013,2016 Ivan Baravy (dunkaist)
; Copyright (C) 2012-2013,2016,2019 Ivan Baravy (dunkaist)
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
@ -16,6 +16,24 @@
; along with this program. If not, see <http://www.gnu.org/licenses/>.
MD4_HASH_SIZE = 16
MD4_BLOCK_SIZE = 64
MD4_ALIGN = 4
MD4_ALIGN_MASK = MD4_ALIGN - 1
struct ctx_md4
hash rb MD4_HASH_SIZE
block rb MD4_BLOCK_SIZE
index rd 1
msglen_0 rd 1
msglen_1 rd 1
ends
if defined sizeof.crash_ctx
assert sizeof.crash_ctx >= sizeof.ctx_md4
end if
macro md4._.f b, c, d
{
mov eax, c
@ -231,7 +249,15 @@ proc md4.final _ctx
endp
proc md4.oneshot _ctx, _data, _len
stdcall md4.init, [_ctx]
stdcall md4.update, [_ctx], [_data], [_len]
stdcall md4.final, [_ctx]
ret
endp
iglobal
align MD4_ALIGN
md4._.hash_init dd 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
endg

View File

@ -1,6 +1,6 @@
; libcrash -- cryptographic hash functions
;
; Copyright (C) 2012-2013,2016 Ivan Baravy (dunkaist)
; Copyright (C) 2012-2013,2016,2019 Ivan Baravy (dunkaist)
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
@ -16,6 +16,24 @@
; along with this program. If not, see <http://www.gnu.org/licenses/>.
MD5_HASH_SIZE = 16
MD5_BLOCK_SIZE = 64
MD5_ALIGN = 4
MD5_ALIGN_MASK = MD5_ALIGN - 1
struct ctx_md5
hash rb MD5_HASH_SIZE
block rb MD5_BLOCK_SIZE
index rd 1
msglen_0 rd 1
msglen_1 rd 1
ends
if defined sizeof.crash_ctx
assert sizeof.crash_ctx >= sizeof.ctx_md5
end if
macro md5._.f b, c, d
{
push c
@ -259,7 +277,15 @@ proc md5.final _ctx
endp
proc md5.oneshot _ctx, _data, _len
stdcall md5.init, [_ctx]
stdcall md5.update, [_ctx], [_data], [_len]
stdcall md5.final, [_ctx]
ret
endp
iglobal
align MD5_ALIGN
md5._.hash_init dd 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
endg

View File

@ -1,6 +1,6 @@
; libcrash -- cryptographic hash functions
;
; Copyright (C) 2012-2013,2016 Ivan Baravy (dunkaist)
; Copyright (C) 2012-2013,2016,2019 Ivan Baravy (dunkaist)
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
@ -16,6 +16,24 @@
; along with this program. If not, see <http://www.gnu.org/licenses/>.
SHA1_HASH_SIZE = 20
SHA1_BLOCK_SIZE = 64
SHA1_ALIGN = 4
SHA1_ALIGN_MASK = SHA1_ALIGN - 1
struct ctx_sha1
hash rb SHA1_HASH_SIZE
block rb SHA1_BLOCK_SIZE
index rd 1
msglen_0 rd 1
msglen_1 rd 1
ends
if defined sizeof.crash_ctx
assert sizeof.crash_ctx >= sizeof.ctx_sha1
end if
proc sha1._.f
push ebx ecx edx
xor ecx, edx
@ -267,7 +285,15 @@ proc sha1._.postprocess _ctx, _hash
endp
proc sha1.oneshot _ctx, _data, _len
stdcall sha1.init, [_ctx]
stdcall sha1.update, [_ctx], [_data], [_len]
stdcall sha1.final, [_ctx]
ret
endp
iglobal
align SHA1_ALIGN
sha1._.hash_init dd 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
endg

View File

@ -1,6 +1,6 @@
; libcrash -- cryptographic hash functions
;
; Copyright (C) 2012-2013,2016 Ivan Baravy (dunkaist)
; Copyright (C) 2012-2013,2016,2019 Ivan Baravy (dunkaist)
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
@ -16,6 +16,29 @@
; along with this program. If not, see <http://www.gnu.org/licenses/>.
SHA224256_BLOCK_SIZE = 64
SHA224_BLOCK_SIZE = SHA224256_BLOCK_SIZE
SHA256_BLOCK_SIZE = SHA224256_BLOCK_SIZE
SHA224_HASH_SIZE = 28
SHA256_HASH_SIZE = 32
SHA224256_INIT_SIZE = 32
SHA224256_ALIGN = 4
SHA224256_ALIGN_MASK = SHA224256_ALIGN - 1
struct ctx_sha224256
hash rb SHA224256_INIT_SIZE
block rb SHA224256_BLOCK_SIZE
index rd 1
msglen_0 rd 1
msglen_1 rd 1
ends
if defined sizeof.crash_ctx
assert sizeof.crash_ctx >= sizeof.ctx_sha224256
end if
macro sha224256._.chn x, y, z
{
mov eax, [y]
@ -253,8 +276,10 @@ end repeat
ret
endp
sha256.update = sha224.update
proc sha224.update _ctx, _msg, _size
sha224.update = sha224256.update
sha256.update = sha224256.update
proc sha224256.update _ctx, _msg, _size
mov ebx, [_ctx]
mov ecx, [_size]
add [ebx + ctx_sha224256.msglen_0], ecx
@ -310,8 +335,9 @@ proc sha224.update _ctx, _msg, _size
endp
sha256.final = sha224.final
proc sha224.final _ctx
sha224.final = sha224256.final
sha256.final = sha224256.final
proc sha224256.final _ctx
mov ebx, [_ctx]
lea edi, [ebx + ctx_sha224256.block]
mov ecx, [ebx + ctx_sha224256.msglen_0]
@ -372,8 +398,24 @@ proc sha224256._.postprocess _ctx, _hash
endp
align SHA224256_ALIGN
proc sha224.oneshot _ctx, _data, _len
stdcall sha224.init, [_ctx]
stdcall sha224.update, [_ctx], [_data], [_len]
stdcall sha224.final, [_ctx]
ret
endp
proc sha256.oneshot _ctx, _data, _len
stdcall sha256.init, [_ctx]
stdcall sha256.update, [_ctx], [_data], [_len]
stdcall sha256.final, [_ctx]
ret
endp
iglobal
align SHA224256_ALIGN
sha224._.hash_init dd 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,\
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
@ -396,4 +438,4 @@ sha256_table dd 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,\
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,\
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
endg

View File

@ -1,6 +1,6 @@
; libcrash -- cryptographic hash functions
;
; Copyright (C) 2013,2016 Ivan Baravy (dunkaist)
; Copyright (C) 2013,2016,2019 Ivan Baravy (dunkaist)
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
@ -16,6 +16,39 @@
; along with this program. If not, see <http://www.gnu.org/licenses/>.
SHA3_224_HASH_SIZE = 28
SHA3_256_HASH_SIZE = 32
SHA3_384_HASH_SIZE = 48
SHA3_512_HASH_SIZE = 64
SHA3_224_BLOCK_SIZE = 144
SHA3_256_BLOCK_SIZE = 136
SHA3_384_BLOCK_SIZE = 104
SHA3_512_BLOCK_SIZE = 72
SHA3MAX_BLOCK_SIZE = SHA3_224_BLOCK_SIZE
SHA3_INIT_SIZE = 200
SHA3_ALIGN = 16
SHA3_ALIGN_MASK = SHA3_ALIGN-1
struct ctx_sha3
hash rb SHA3_INIT_SIZE
rb SHA3_ALIGN - (SHA3_INIT_SIZE mod SHA3_ALIGN)
block rb SHA3MAX_BLOCK_SIZE
rb SHA3_ALIGN - (SHA3MAX_BLOCK_SIZE mod SHA3_ALIGN)
index rd 1
block_size rd 1
rounds_cnt rd 1
rd 1 ; align
; tmp vars
C rq 5
D rq 5
ends
if defined sizeof.crash_ctx
assert sizeof.crash_ctx >= sizeof.ctx_sha3
end if
macro sha3._.rol_xor nd, ncl, ncr
{
movq mm0, [C + 8*(ncl)]
@ -244,33 +277,33 @@ proc sha3._.init _ctx
endp
proc sha3224.init _ctx
proc sha3_224.init _ctx
mov ebx, [_ctx]
mov eax, SHA3224_BLOCK_SIZE
mov eax, SHA3_224_BLOCK_SIZE
stdcall sha3._.init
ret
endp
proc sha3256.init _ctx
proc sha3_256.init _ctx
mov ebx, [_ctx]
mov eax, SHA3256_BLOCK_SIZE
mov eax, SHA3_256_BLOCK_SIZE
stdcall sha3._.init
ret
endp
proc sha3384.init _ctx
proc sha3_384.init _ctx
mov ebx, [_ctx]
mov eax, SHA3384_BLOCK_SIZE
mov eax, SHA3_384_BLOCK_SIZE
stdcall sha3._.init
ret
endp
proc sha3512.init _ctx
proc sha3_512.init _ctx
mov ebx, [_ctx]
mov eax, SHA3512_BLOCK_SIZE
mov eax, SHA3_512_BLOCK_SIZE
stdcall sha3._.init
ret
endp
@ -293,10 +326,10 @@ proc sha3._.block _hash
endp
sha3224.update = sha3.update
sha3256.update = sha3.update
sha3384.update = sha3.update
sha3512.update = sha3.update
sha3_224.update = sha3.update
sha3_256.update = sha3.update
sha3_384.update = sha3.update
sha3_512.update = sha3.update
proc sha3.update _ctx, _msg, _size
.next_block:
mov ebx, [_ctx]
@ -355,10 +388,10 @@ proc sha3.update _ctx, _msg, _size
endp
sha3224.final = sha3.final
sha3256.final = sha3.final
sha3384.final = sha3.final
sha3512.final = sha3.final
sha3_224.final = sha3.final
sha3_256.final = sha3.final
sha3_384.final = sha3.final
sha3_512.final = sha3.final
proc sha3.final _ctx
pushad
mov ebx, [_ctx]
@ -404,8 +437,40 @@ proc sha3._.postprocess _ctx, _hash
endp
align SHA3_ALIGN
proc sha3_224.oneshot _ctx, _data, _len
stdcall sha3_224.init, [_ctx]
stdcall sha3.update, [_ctx], [_data], [_len]
stdcall sha3.final, [_ctx]
ret
endp
proc sha3_256.oneshot _ctx, _data, _len
stdcall sha3_256.init, [_ctx]
stdcall sha3.update, [_ctx], [_data], [_len]
stdcall sha3.final, [_ctx]
ret
endp
proc sha3_384.oneshot _ctx, _data, _len
stdcall sha3_384.init, [_ctx]
stdcall sha3.update, [_ctx], [_data], [_len]
stdcall sha3.final, [_ctx]
ret
endp
proc sha3_512.oneshot _ctx, _data, _len
stdcall sha3_512.init, [_ctx]
stdcall sha3.update, [_ctx], [_data], [_len]
stdcall sha3.final, [_ctx]
ret
endp
iglobal
align SHA3_ALIGN
sha3._.round dq 0x0000000000000001, 0x0000000000008082, 0x800000000000808A,\
0x8000000080008000, 0x000000000000808B, 0x0000000080000001,\
0x8000000080008081, 0x8000000000008009, 0x000000000000008A,\
@ -414,4 +479,4 @@ sha3._.round dq 0x0000000000000001, 0x0000000000008082, 0x800000000000808A,\
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,\
0x000000000000800A, 0x800000008000000A, 0x8000000080008081,\
0x8000000000008080, 0x0000000080000001, 0x8000000080008008
endg

View File

@ -1,6 +1,6 @@
; libcrash -- cryptographic hash functions
;
; Copyright (C) 2012-2013,2016 Ivan Baravy (dunkaist)
; Copyright (C) 2012-2013,2016,2019 Ivan Baravy (dunkaist)
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
@ -16,6 +16,42 @@
; along with this program. If not, see <http://www.gnu.org/licenses/>.
SHA384512_BLOCK_SIZE = 128
SHA384_BLOCK_SIZE = SHA384512_BLOCK_SIZE
SHA512_BLOCK_SIZE = SHA384512_BLOCK_SIZE
SHA384_HASH_SIZE = 48
SHA512_HASH_SIZE = 64
SHA384512_INIT_SIZE = 64
SHA384512_ALIGN = 16
SHA384512_ALIGN_MASK = SHA384512_ALIGN - 1
struct ctx_sha384512
hash rb SHA384512_INIT_SIZE
block rb SHA384512_BLOCK_SIZE
index rd 1
msglen_0 rd 1
msglen_1 rd 1
msglen_2 rd 1
msglen_3 rd 1
rd 3 ; align
; tmp vars
w rq 80
A rq 1
B rq 1
C rq 1
D rq 1
E rq 1
F rq 1
G rq 1
H rq 1
temp rq 1
ends
if defined sizeof.crash_ctx
assert sizeof.crash_ctx >= sizeof.ctx_sha384512
end if
macro sha384512._.chn x, y, z
{
movq mm0, [y]
@ -318,8 +354,10 @@ end repeat
restore w,A,B,C,D,E,F,G,H,temp
endp
sha512.update = sha384.update
proc sha384.update _ctx, _msg, _size
sha384.update = sha384512.update
sha512.update = sha384512.update
proc sha384512.update _ctx, _msg, _size
mov ebx, [_ctx]
mov ecx, [_size]
add [ebx + ctx_sha384512.msglen_0], ecx
@ -377,8 +415,9 @@ proc sha384.update _ctx, _msg, _size
endp
sha512.final = sha384.final
proc sha384.final _ctx
sha384.final = sha384512.final
sha512.final = sha384512.final
proc sha384512.final _ctx
mov ebx, [_ctx]
lea edi, [ebx + ctx_sha384512.block]
mov ecx, [ebx + ctx_sha384512.msglen_0]
@ -456,8 +495,24 @@ proc sha384512._.postprocess _ctx, _hash
endp
align SHA384512_ALIGN
proc sha384.oneshot _ctx, _data, _len
stdcall sha384.init, [_ctx]
stdcall sha384.update, [_ctx], [_data], [_len]
stdcall sha384.final, [_ctx]
ret
endp
proc sha512.oneshot _ctx, _data, _len
stdcall sha512.init, [_ctx]
stdcall sha512.update, [_ctx], [_data], [_len]
stdcall sha512.final, [_ctx]
ret
endp
iglobal
align SHA384512_ALIGN
sha384._.hash_init dq 0xcbbb9d5dc1059ed8, 0x629a292a367cd507,\
0x9159015a3070dd17, 0x152fecd8f70e5939,\
0x67332667ffc00b31, 0x8eb44a8768581511,\
@ -508,4 +563,4 @@ sha384512._.table dq 0x428a2f98d728ae22, 0x7137449123ef65cd,\
0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c,\
0x4cc5d4becb3e42b6, 0x597f299cfc657e2a,\
0x5fcb6fab3ad6faec, 0x6c44198c4a475817
endg

View File

@ -231,7 +231,7 @@ end if
mov esi, con.k_h_ctx
mov edi, con.temp_ctx
mov ecx, sizeof.ctx_sha224256/4
mov ecx, sizeof.crash_ctx
rep movsd
mov [con.session_id_prefix], 'A'
invoke sha256_update, con.temp_ctx, con.session_id_prefix, 32+1
@ -249,7 +249,7 @@ end if
mov esi, con.k_h_ctx
mov edi, con.temp_ctx
mov ecx, sizeof.ctx_sha224256/4
mov ecx, sizeof.crash_ctx/4
rep movsd
inc [con.session_id_prefix]
invoke sha256_update, con.temp_ctx, con.session_id_prefix, 32+1
@ -267,7 +267,7 @@ end if
mov esi, con.k_h_ctx
mov edi, con.temp_ctx
mov ecx, sizeof.ctx_sha224256/4
mov ecx, sizeof.crash_ctx
rep movsd
inc [con.session_id_prefix]
invoke sha256_update, con.temp_ctx, con.session_id_prefix, 32+1
@ -285,7 +285,7 @@ end if
mov esi, con.k_h_ctx
mov edi, con.temp_ctx
mov ecx, sizeof.ctx_sha224256/4
mov ecx, sizeof.crash_ctx/4
rep movsd
inc [con.session_id_prefix]
invoke sha256_update, con.temp_ctx, con.session_id_prefix, 32+1
@ -303,7 +303,7 @@ end if
mov esi, con.k_h_ctx
mov edi, con.temp_ctx
mov ecx, sizeof.ctx_sha224256/4
mov ecx, sizeof.crash_ctx/4
rep movsd
inc [con.session_id_prefix]
invoke sha256_update, con.temp_ctx, con.session_id_prefix, 32+1
@ -321,7 +321,7 @@ end if
mov esi, con.k_h_ctx
mov edi, con.temp_ctx
mov ecx, sizeof.ctx_sha224256/4
mov ecx, sizeof.crash_ctx/4
rep movsd
inc [con.session_id_prefix]
invoke sha256_update, con.temp_ctx, con.session_id_prefix, 32+1

View File

@ -22,8 +22,8 @@
struct hmac_md5_context
hash rb MD5_HASH_SIZE
ipad_ctx ctx_md5
opad_ctx ctx_md5
ipad_ctx crash_ctx
opad_ctx crash_ctx
ends
; We will precompute partial hashes of K XOR ipad and K XOR opad,

View File

@ -22,8 +22,8 @@
struct hmac_sha1_context
hash rb SHA1_HASH_SIZE
ipad_ctx ctx_sha1
opad_ctx ctx_sha1
ipad_ctx crash_ctx
opad_ctx crash_ctx
ends
; We will precompute partial hashes of K XOR ipad and K XOR opad,

View File

@ -22,8 +22,8 @@
struct hmac_sha256_context
hash rb SHA256_HASH_SIZE
ipad_ctx ctx_sha224256
opad_ctx ctx_sha224256
ipad_ctx crash_ctx
opad_ctx crash_ctx
ends
; We will precompute partial hashes of K XOR ipad and K XOR opad,
@ -32,21 +32,21 @@ ends
proc hmac_sha256_setkey ctx, key, key_length
locals
k_temp rb SHA224256_BLOCK_SIZE
k_temp rb SHA256_BLOCK_SIZE
endl
pusha
; input esi = key, ecx=key_length
mov ecx, [key_length]
cmp ecx, SHA224256_BLOCK_SIZE
cmp ecx, SHA256_BLOCK_SIZE
ja .hash_it
; Key is smaller then or equal to blocksize,
; copy key to ipad
mov esi, [key]
lea edi, [k_temp]
rep movsb
mov ecx, SHA224256_BLOCK_SIZE
mov ecx, SHA256_BLOCK_SIZE
sub ecx, [key_length]
jz .finish
; append zeros to the key
@ -64,13 +64,13 @@ endl
mov ecx, SHA256_HASH_SIZE/4
rep movsd
xor eax, eax
mov ecx, (SHA224256_BLOCK_SIZE-SHA256_HASH_SIZE)/4
mov ecx, (SHA256_BLOCK_SIZE-SHA256_HASH_SIZE)/4
rep stosd
.finish:
; xor ipad buffer with 0x36363...
lea esi, [k_temp]
mov ecx, SHA224256_BLOCK_SIZE/4
mov ecx, SHA256_BLOCK_SIZE/4
@@:
xor dword[esi], 0x36363636 ; ipad constant
add esi, 4
@ -84,15 +84,15 @@ endl
lea esi, [k_temp]
DEBUGF 1, "HASH: "
stdcall dump_hex, esi, SHA224256_BLOCK_SIZE/4
stdcall dump_hex, esi, SHA256_BLOCK_SIZE/4
mov ebx, [ctx]
lea edi, [ebx+hmac_sha256_context.ipad_ctx]
invoke sha256_update, edi, esi, SHA224256_BLOCK_SIZE
invoke sha256_update, edi, esi, SHA256_BLOCK_SIZE
; xor opad buffer with 0x5c5c5...
lea esi, [k_temp]
mov ecx, SHA224256_BLOCK_SIZE/4
mov ecx, SHA256_BLOCK_SIZE/4
@@:
xor dword[esi], 0x36363636 xor 0x5c5c5c5c ; opad constant
add esi, 4
@ -106,11 +106,11 @@ endl
lea esi, [k_temp]
DEBUGF 1, "HASH: "
stdcall dump_hex, esi, SHA224256_BLOCK_SIZE/4
stdcall dump_hex, esi, SHA256_BLOCK_SIZE/4
mov ebx, [ctx]
lea edi, [ebx+hmac_sha256_context.opad_ctx]
invoke sha256_update, edi, esi, SHA224256_BLOCK_SIZE
invoke sha256_update, edi, esi, SHA256_BLOCK_SIZE
popa
ret
@ -124,8 +124,8 @@ endp
proc hmac_sha256 ctx, _data, _length
locals
inner_ctx ctx_sha224256
outer_ctx ctx_sha224256
inner_ctx crash_ctx
outer_ctx crash_ctx
endl
pusha
@ -138,7 +138,7 @@ endl
mov esi, [ctx]
lea esi, [esi+hmac_sha256_context.ipad_ctx]
lea edi, [inner_ctx]
repeat (sizeof.ctx_sha224256)/4*2
repeat (sizeof.crash_ctx)/4*2
movsd
end repeat

View File

@ -165,8 +165,8 @@ struct ssh_connection
dh_signature dd ?
rb MAX_BITS/8
temp_ctx ctx_sha224256
k_h_ctx ctx_sha224256
temp_ctx crash_ctx
k_h_ctx crash_ctx
mpint_tmp dd ?
rb MAX_BITS/8