Repository navigation
Conversation
- internal/word.cr: fixed-width word arithmetic with an explicit width parameter. Width is an algorithm argument, not a type; operations use /, %, * and conditionals only (no new IR opcodes). - internal/bytes.cr: the single stdlib boundary for raw byte access. rawbuf.cr now delegates to it instead of naming load8/store8. - hash.cr: CRC-32/ISO-HDLC with configurable init and polynomial, SHA-256, HMAC-SHA256, HKDF-SHA256 and PBKDF2-HMAC-SHA256. Output lengths, iteration counts, seeds and polynomials are explicit. - test_hash.py checks every primitive against hashlib/hmac and a second CRC implementation. The SHA-256 K table is function-local because dynamic subscript on a global array currently reads zero (noted in the source; separate defect).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
新增标准库内部字/字节层与公开哈希/KDF 面。
内部层(非 pub,用户不可见)
src/stdlib/internal/word.cr:任意宽度的 word 运算(wordAnd/Or/Xor/Not/Shl/Shr/Rotl/Rotr/Add/Sub/Mul)。宽度是算法参数(
bits: int),用/、%、*与条件实现,不新增 IR opcode、不引入宽度类型。src/stdlib/internal/bytes.cr:标准库唯一的 raw 字节边界。rawbuf.cr改为委托这里,不再直接命名
load8/store8。公开面(
hash.cr)crc32/crc32With(data, init, poly)/crc32Hex,以及增量
crc32Init/crc32Update/crc32Final。sha256/sha256Hex。hmacSha256/hmacSha256Hex。hkdfSha256/hkdfSha256Extract/hkdfSha256Expand/hkdfSha256Hex。pbkdf2Sha256/pbkdf2Sha256Hex。验证
selfhost-tests全绿(新增test_hash.py)bootstrap-tests全绿check全绿canary5/5,值不变test_hash.py用 Pythonhashlib/hmac+ 第二份 CRC 实现对拍,覆盖:CRC-32 空串/标准向量/自定义 init/CRC-32C 多项式/增量;
SHA-256 空串/abc/200B 跨块;
HMAC RFC 4231 case 1/2;
HKDF RFC 5869 test case 1(42B)与 64B 参数;
PBKDF2 c=1/2/8,输出 20/32 字节。
备注
sha256Compress的 K 常量表放在函数内:全局数组的动态下标目前读 0(既有后端缺陷,已在源码注释登记),本批不改该路径,避免把哈希实现建立在未验证的行为上。