diff --git a/rt/loader32.asm b/rt/loader32.asm index a54f575..f07742e 100644 --- a/rt/loader32.asm +++ b/rt/loader32.asm @@ -107,8 +107,7 @@ _smol_start: ; source in eax, result in eax %ifdef USE_CRC32C_HASH - push -1 - pop eax + xor ecx, ecx %else %ifndef USE_HASH16 push ebx diff --git a/rt/loader64.asm b/rt/loader64.asm index 3ab9aaf..81a8b45 100644 --- a/rt/loader64.asm +++ b/rt/loader64.asm @@ -112,8 +112,7 @@ _smol_start: pop rbx %else ; crc32 - push -1 - pop rcx + xor ecx, ecx %endif .nexthashiter: %ifndef USE_CRC32C_HASH diff --git a/smol/shared.py b/smol/shared.py index c70003d..458cd00 100644 --- a/smol/shared.py +++ b/smol/shared.py @@ -14,7 +14,7 @@ HASH_CRC32C=2 define_for_hash = { - HASH_DJB2: None + HASH_DJB2: None, HASH_BSD2: 'USE_HASH16', HASH_CRC32C: 'USE_CRC32C_HASH' } @@ -35,9 +35,16 @@ def hash_djb2(s): def hash_crc32c(s): - # crc32 implementation is basically: - # sum = -1; for (; *s; ++s) crc32_instr(&sum, *s); return sum - assert False, "not implemented!" # TODO + crc = 0x0 + for c in s: + k = (crc & 0xff) ^ ord(c) + for i in range(8): + j = k & 1 + if j == 1: + k ^= 0x105EC76F0 + k >>= 1 + crc = ((crc >> 8) ^ k) & 0xFFFFFFFF + return crc def eprintf(*args, **kwargs): diff --git a/smoldd.py b/smoldd.py index 5e35810..ddaec88 100755 --- a/smoldd.py +++ b/smoldd.py @@ -8,8 +8,6 @@ from smol.shared import * from smol.parse import * -# TODO: support for hashes that aren't djb2 - def readbyte(blob, off): return struct.unpack('