示例
golang.org/x/crypto v0.54.0: blake2b.New256
已验证示例 — golang golang.org/x/crypto v0.54.0: blake2b.New256. contract 在 go 1.26 · linux alpine/x64 · docker 上运行并通过: blake2b.New256(nil) returns a 32-byte…
sha256:c05b1ec5dbb34c4fc6e88ea75426f801f5d8a13e2f9c3ed4bbffcde3e0b45f33
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-30 |
案例
HOW- 目标
- verify blake2b.New256 in pkg:golang/golang.org/x/crypto@v0.54.0
- 符号
-
- blake2b.New256
- 环境
- go 1.26
- 创建时间
- 2026-08-30T13:41:15Z
契约
- blake2b.New256(nil) returns a 32-byte hash.Hash with BlockSize 128 without error
- blake2b.New256(nil) digest matches blake2b.Sum256 output for identical inputs
- blake2b.New256 with a non-nil key up to 64 bytes functions as a MAC producing keyed digests
- blake2b.New256 returns an error when key length exceeds 64 bytes
- blake2b.New256 hasher Reset clears state allowing subsequent digest recomputation
文件
- PROMPT.md
- contract_test.go
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
源代码
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify blake2b.New256 in pkg:golang/golang.org/x/crypto@v0.54.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/crypto@v0.54.0
Demonstrate these symbols/APIs:
- blake2b.New256
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
package sample
import (
"bytes"
"testing"
"golang.org/x/crypto/blake2b"
)
func TestNew256BasicProperties(t *testing.T) {
h, err := blake2b.New256(nil)
if err != nil {
t.Fatalf("expected nil error, got %v", err)
}
if size := h.Size(); size != 32 {
t.Fatalf("expected size 32, got %d", size)
}
if blockSize := h.BlockSize(); blockSize != 128 {
t.Fatalf("expected block size 128, got %d", blockSize)
}
}
func TestNew256MatchesSum256(t *testing.T) {
data := []byte("The quick brown fox jumps over the lazy dog")
h, err := blake2b.New256(nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
h.Write(data)
digest := h.Sum(nil)
expected := blake2b.Sum256(data)
if !bytes.Equal(digest, expected[:]) {
t.Fatalf("digest mismatch: got %x, expected %x", digest, expected)
}
}
func TestNew256WithKey(t *testing.T) {
data := []byte("authenticated message")
key := []byte("secret-key-up-to-64-bytes-long")
hKeyed, err := blake2b.New256(key)
if err != nil {
t.Fatalf("unexpected error with valid key: %v", err)
}
hKeyed.Write(data)
keyedDigest := hKeyed.Sum(nil)
hUnkeyed, err := blake2b.New256(nil)
if err != nil {
t.Fatalf("unexpected error with nil key: %v", err)
}
hUnkeyed.Write(data)
unkeyedDigest := hUnkeyed.Sum(nil)
if bytes.Equal(keyedDigest, unkeyedDigest) {
t.Fatalf("expected keyed digest to differ from unkeyed digest")
}
if len(keyedDigest) != 32 {
t.Fatalf("expected 32-byte digest, got %d bytes", len(keyedDigest))
}
}
func TestNew256KeyTooLong(t *testing.T) {
key65 := make([]byte, 65)
_, err := blake2b.New256(key65)
if err == nil {
t.Fatalf("expected error for key longer than 64 bytes, got nil")
}
}
func TestNew256Reset(t *testing.T) {
data := []byte("test data for reset")
h, err := blake2b.New256(nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
h.Write(data)
digest1 := h.Sum(nil)
h.Reset()
h.Write(data)
digest2 := h.Sum(nil)
if !bytes.Equal(digest1, digest2) {
t.Fatalf("expected identical digests after Reset, got %x vs %x", digest1, digest2)
}
}
{"case":{"caseId":"case:sha256:a397f90ff5bb331ed9a936dd83605d4a5306ba1043cf1a26ac9a8ef30aa7b0e1","contract":["blake2b.New256(nil) returns a 32-byte hash.Hash with BlockSize 128 without error","blake2b.New256(nil) digest matches blake2b.Sum256 output for identical inputs","blake2b.New256 with a non-nil key up to 64 bytes functions as a MAC producing keyed digests","blake2b.New256 returns an error when key length exceeds 64 bytes","blake2b.New256 hasher Reset clears state allowing subsequent digest recomputation"],"goal":"verify blake2b.New256 in pkg:golang/golang.org/x/crypto@v0.54.0","kind":"HOW","packages":["pkg:golang/golang.org/x/crypto@v0.54.0"],"schemaVersion":1,"symbols":["blake2b.New256"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/crypto@v0.54.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/crypto@v0.54.0","symbols":["blake2b.New256"],"verifierAdapter":"golang@1"}
module sample-98948192
go 1.26.6
require golang.org/x/crypto v0.54.0
require golang.org/x/sys v0.47.0 // indirect
golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw=
golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
package sample
import (
"hash"
"golang.org/x/crypto/blake2b"
)
// Hash256 computes the BLAKE2b-256 digest of data with an optional MAC key.
func Hash256(data []byte, key []byte) ([]byte, error) {
h, err := blake2b.New256(key)
if err != nil {
return nil, err
}
h.Write(data)
return h.Sum(nil), nil
}
// NewHasher returns a new BLAKE2b-256 hash.Hash instance.
func NewHasher(key []byte) (hash.Hash, error) {
return blake2b.New256(key)
}
{
"schemaVersion": 1,
"goal": "verify blake2b.New256 in pkg:golang/golang.org/x/crypto@v0.54.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/crypto@v0.54.0"
],
"symbols": [
"blake2b.New256"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
原始种子者
匿名