From 3dd5bca28ee716ebc9e00a51036bf2da853cbe9a Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sun, 11 Oct 2026 11:05:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(narrow):=20hashlib=20=E6=91=98=E8=A6=81?= =?UTF-8?q?=E5=86=99=E5=AD=97=E8=8A=82=E6=94=B9=E7=94=A8=20uint8(...)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sha256/sha1/md5 的 digest 阶段把 32/64 位掩码结果写入 bytes 元素(i8),触发隐式窄化;统一加 uint8(...)(与 __sha512 一致) --- hashlib/__md5.vp | 10 +++++----- hashlib/__sha1.vp | 10 +++++----- hashlib/__sha256.vp | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/hashlib/__md5.vp b/hashlib/__md5.vp index b378547..b6ed956 100644 --- a/hashlib/__md5.vp +++ b/hashlib/__md5.vp @@ -118,11 +118,11 @@ class md5: # Write total bit count bits: uint64 = self.count << 3 for i in range(8): - self.buf[MD5_BLOCK_LEN - 8 + i] = (bits >> (i * 8)) & 0xFF + self.buf[MD5_BLOCK_LEN - 8 + i] = uint8((bits >> (i * 8)) & 0xFF) self.transform(self.buf) # State registers to little-endian byte output output for i in range(4): - out[i * 4 + 0] = (self.state[i] >> 0) & 0xFF - out[i * 4 + 1] = (self.state[i] >> 8) & 0xFF - out[i * 4 + 2] = (self.state[i] >> 16) & 0xFF - out[i * 4 + 3] = (self.state[i] >> 24) & 0xFF + out[i * 4 + 0] = uint8((self.state[i] >> 0) & 0xFF) + out[i * 4 + 1] = uint8((self.state[i] >> 8) & 0xFF) + out[i * 4 + 2] = uint8((self.state[i] >> 16) & 0xFF) + out[i * 4 + 3] = uint8((self.state[i] >> 24) & 0xFF) diff --git a/hashlib/__sha1.vp b/hashlib/__sha1.vp index d25a0b6..2116072 100644 --- a/hashlib/__sha1.vp +++ b/hashlib/__sha1.vp @@ -105,11 +105,11 @@ class sha1: bits: uint64 = self.count << 3 # SHA1 big-endian write length for i in range(8): - self.buf[SHA1_BLOCK_LEN - 8 + i] = (bits >> (56 - i * 8)) & 0xFF + self.buf[SHA1_BLOCK_LEN - 8 + i] = uint8((bits >> (56 - i * 8)) & 0xFF) self.transform(self.buf) # State registers to big-endian byte output output output for i in range(5): - out[i * 4 + 0] = (self.state[i] >> 24) & 0xFF - out[i * 4 + 1] = (self.state[i] >> 16) & 0xFF - out[i * 4 + 2] = (self.state[i] >> 8) & 0xFF - out[i * 4 + 3] = (self.state[i] >> 0) & 0xFF + out[i * 4 + 0] = uint8((self.state[i] >> 24) & 0xFF) + out[i * 4 + 1] = uint8((self.state[i] >> 16) & 0xFF) + out[i * 4 + 2] = uint8((self.state[i] >> 8) & 0xFF) + out[i * 4 + 3] = uint8((self.state[i] >> 0) & 0xFF) diff --git a/hashlib/__sha256.vp b/hashlib/__sha256.vp index f2b1221..3d9ae6a 100644 --- a/hashlib/__sha256.vp +++ b/hashlib/__sha256.vp @@ -108,11 +108,11 @@ class sha256: string.memset(self.buf + idx, 0, SHA256_BLOCK_LEN - 8 - idx) bits: uint64 = self.count << 3 for i in range(8): - self.buf[SHA256_BLOCK_LEN-8+i] = (bits >> (56 - i*8)) & 0xFF + self.buf[SHA256_BLOCK_LEN-8+i] = uint8((bits >> (56 - i*8)) & 0xFF) self.transform(self.buf) # Byte order 32-bit words for i in range(8): - out[i * 4 + 0] = (self.state[i] >> 24) & 0xFF - out[i * 4 + 1] = (self.state[i] >> 16) & 0xFF - out[i * 4 + 2] = (self.state[i] >> 8) & 0xFF - out[i * 4 + 3] = (self.state[i] >> 0) & 0xFF + out[i * 4 + 0] = uint8((self.state[i] >> 24) & 0xFF) + out[i * 4 + 1] = uint8((self.state[i] >> 16) & 0xFF) + out[i * 4 + 2] = uint8((self.state[i] >> 8) & 0xFF) + out[i * 4 + 3] = uint8((self.state[i] >> 0) & 0xFF)