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

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 md5_I(x: t.CUInt32T, y: t.CUInt32T, z: t.CUInt32T) -> t.CUInt32T: return y ^
def md5_rotl(x: t.CUInt32T, n: t.CInt) -> t.CUInt32T: return (x << n) | (x >> (32 - n))
# MD5 常量表、移位表
md5_T: list[t.CUInt32T, 64] = [
md5_T: t.CArray[t.CUInt32T, 64] = [
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
@@ -27,7 +27,7 @@ md5_T: list[t.CUInt32T, 64] = [
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
]
md5_S: list[t.CInt, 64] = [
md5_S: t.CArray[t.CInt, 64] = [
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
@@ -37,9 +37,9 @@ md5_S: list[t.CInt, 64] = [
# MD5 上下文结构体
@t.Object
class md5:
state: list[t.CUInt32T, 4] # 4个32位状态寄存器
state: t.CArray[t.CUInt32T, 4] # 4个32位状态寄存器
count: t.CUInt64T # 已处理比特数
buf: list[t.CUInt8T, MD5_BLOCK_LEN] # 分组缓冲区
buf: t.CArray[t.CUInt8T, MD5_BLOCK_LEN] # 分组缓冲区
# 初始化MD5上下文
def __init__(self):
memset(self.buf, 0, MD5_BLOCK_LEN)
@@ -54,7 +54,7 @@ class md5:
b: t.CUInt32T = self.state[1]
c: t.CUInt32T = self.state[2]
d: t.CUInt32T = self.state[3]
w: list[t.CUInt32T, 16]
w: t.CArray[t.CUInt32T, 16]
# 字节序转32位字
for i in range(16):
w[i] = ((t.CUInt32T(block[i * 4 + 0]) << 0) |
@@ -105,7 +105,7 @@ class md5:
if length > 0:
memcpy(self.buf + idx, data, length)
# 结束计算输出16字节摘要
def final(self, out: list[t.CUInt8T, MD5_DIGEST_LEN]):
def final(self, out: t.CArray[t.CUInt8T, MD5_DIGEST_LEN]):
idx: t.CSizeT = self.count % MD5_BLOCK_LEN
# 填充0x80结尾
self.buf[idx] = 0x80