修复了大量存在的问题,增加了假鸭子类型等等机制
This commit is contained in:
@@ -17,9 +17,9 @@ def sha1_f3(b: t.CUInt32T, c: t.CUInt32T, d: t.CUInt32T) -> t.CUInt32T: return (
|
||||
# SHA1 上下文
|
||||
@t.Object
|
||||
class sha1:
|
||||
state: list[t.CUInt32T, 5]
|
||||
state: t.CArray[t.CUInt32T, 5]
|
||||
count: t.CUInt64T
|
||||
buf: list[t.CUInt8T, SHA1_BLOCK_LEN]
|
||||
buf: t.CArray[t.CUInt8T, SHA1_BLOCK_LEN]
|
||||
def __init__(self):
|
||||
memset(self.buf, 0, SHA1_BLOCK_LEN)
|
||||
self.state[0] = 0x67452301
|
||||
@@ -30,7 +30,7 @@ class sha1:
|
||||
self.count = 0
|
||||
# 单分组压缩
|
||||
def transform(self, block: t.CUInt8T | t.CPtr):
|
||||
w: list[t.CUInt32T, 80]
|
||||
w: t.CArray[t.CUInt32T, 80]
|
||||
data: t.CUInt8T | t.CPtr = block
|
||||
# 前16个字
|
||||
for i in range(16):
|
||||
@@ -97,7 +97,7 @@ class sha1:
|
||||
length -= SHA1_BLOCK_LEN
|
||||
if length > 0:
|
||||
memcpy(self.buf + idx, data, length)
|
||||
def final(self, out: list[t.CUInt8T, SHA1_DIGEST_LEN]):
|
||||
def final(self, out: t.CArray[t.CUInt8T, SHA1_DIGEST_LEN]):
|
||||
idx: t.CSizeT = self.count % SHA1_BLOCK_LEN
|
||||
self.buf[idx] = 0x80
|
||||
idx += 1
|
||||
|
||||
Reference in New Issue
Block a user