修复了大量存在的问题,增加了假鸭子类型等等机制

This commit is contained in:
2026-06-25 14:49:46 +08:00
parent 19f2787db0
commit d88d11b646
827 changed files with 32617 additions and 18316 deletions

View File

@@ -16,7 +16,7 @@ def sha512_BigSigma1(x: t.CUInt64T) -> t.CUInt64T: return sha512_ror(x, 14) ^ sh
def sha512_Sigma0(x: t.CUInt64T) -> t.CUInt64T: return sha512_ror(x, 1) ^ sha512_ror(x, 8) ^ sha512_shr(x, 7)
def sha512_Sigma1(x: t.CUInt64T) -> t.CUInt64T: return sha512_ror(x, 19) ^ sha512_ror(x, 61) ^ sha512_shr(x, 6)
sha512_K: list[t.CUInt64T, 80] = [
sha512_K: t.CArray[t.CUInt64T, 80] = [
0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc,
0x3956c25bf348b538, 0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118,
0xd807aa98a3030242, 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2,
@@ -41,9 +41,9 @@ sha512_K: list[t.CUInt64T, 80] = [
@t.Object
class sha512:
state: list[t.CUInt64T, 8]
count: list[t.CUInt64T, 2]
buf: list[t.CUInt8T, SHA512_BLOCK_LEN]
state: t.CArray[t.CUInt64T, 8]
count: t.CArray[t.CUInt64T, 2]
buf: t.CArray[t.CUInt8T, SHA512_BLOCK_LEN]
def __init__(self):
memset(self, 0, sha512.__sizeof__())
self.state[0] = 0x6a09e667f3bcc908
@@ -54,8 +54,8 @@ class sha512:
self.state[5] = 0x9b05688c2b3e6c1f
self.state[6] = 0x1f83d9abfb41bd6b
self.state[7] = 0x5be0cd19137e2179
def transform(self, block: list[t.CUInt8T, SHA512_BLOCK_LEN]):
w: list[t.CUInt64T, 80]
def transform(self, block: t.CArray[t.CUInt8T, SHA512_BLOCK_LEN]):
w: t.CArray[t.CUInt64T, 80]
a: t.CUInt64T
b: t.CUInt64T
c: t.CUInt64T
@@ -121,7 +121,7 @@ class sha512:
length -= SHA512_BLOCK_LEN
if length > 0:
memcpy(self.buf + idx, data, length)
def final(self, out: list[t.CUInt8T, SHA512_DIGEST_LEN]):
def final(self, out: t.CArray[t.CUInt8T, SHA512_DIGEST_LEN]):
bits_lo: t.CUInt64T = self.count[0] << 3
bits_hi: t.CUInt64T = (self.count[1] << 3) | (self.count[0] >> 61)
idx: t.CUInt32T = t.CUInt32T(self.count[0] % SHA512_BLOCK_LEN)