示例
golang.org/x/crypto v0.58.0: argon2.IDKey, bcrypt.GenerateFromPassword, bcrypt.CompareHashAndPassword
已验证示例 — golang golang.org/x/crypto v0.58.0: argon2.IDKey, bcrypt.GenerateFromPassword, bcrypt.CompareHashAndPassword. contract 在 go 1.26 · linux debian/x64 …
sha256:e7a03011c02651cc7f3b0deab237f39eed428c05912bdc00e7a37a8445267a14
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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 debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-10-29 |
案例
HOW- 目标
- verify pkg:golang/golang.org/x/crypto@v0.58.0
- 符号
-
- argon2.IDKey
- bcrypt.GenerateFromPassword
- bcrypt.CompareHashAndPassword
- sha3.Sum256
- 环境
- go 1.26.6
- 创建时间
- 2026-10-29T17:03:05Z
契约
- argon2.IDKey derives deterministic 32-byte key slices and produces distinct keys when password or salt changes
- bcrypt.GenerateFromPassword hashes passwords at the requested cost and bcrypt.CompareHashAndPassword accepts the matching password while returning bcrypt.ErrMismatchedHashAndPassword on mismatch
- sha3.Sum256 and streaming sha3.New256 produce identical 32-byte digests for the same input and distinct digests for different inputs
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
源代码
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 pkg:golang/golang.org/x/crypto@v0.58.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/crypto@v0.58.0
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.
{"case":{"caseId":"case:sha256:cdff1b51f3e6a7941c3c0eb53962b56cee88beb42a3f0a7af48c33d7dcf876af","contract":["argon2.IDKey derives deterministic 32-byte key slices and produces distinct keys when password or salt changes","bcrypt.GenerateFromPassword hashes passwords at the requested cost and bcrypt.CompareHashAndPassword accepts the matching password while returning bcrypt.ErrMismatchedHashAndPassword on mismatch","sha3.Sum256 and streaming sha3.New256 produce identical 32-byte digests for the same input and distinct digests for different inputs"],"goal":"verify pkg:golang/golang.org/x/crypto@v0.58.0","kind":"HOW","packages":["pkg:golang/golang.org/x/crypto@v0.58.0"],"schemaVersion":1,"symbols":["argon2.IDKey","bcrypt.GenerateFromPassword","bcrypt.CompareHashAndPassword","sha3.Sum256"]},"contractCommand":["go","run","./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.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/crypto@v0.58.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/crypto@v0.58.0","symbols":["argon2.IDKey","bcrypt.GenerateFromPassword","bcrypt.CompareHashAndPassword","sha3.Sum256"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require golang.org/x/crypto v0.58.0
require golang.org/x/sys v0.49.0 // indirect
golang.org/x/crypto v0.58.0 h1:COkYLr4k7nDI4r6QtMML2AfzeIswWHAJthLS6K/M/54=
golang.org/x/crypto v0.58.0/go.mod h1:Xh+kl5A+M0gMiWDytH2Hhr5Z7WbNCpv/eB/EFgfSk+w=
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
package main
import (
"encoding/hex"
"fmt"
"golang.org/x/crypto/argon2"
"golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/sha3"
)
func main() {
password := []byte("example-passphrase")
salt := []byte("example-salt-16b")
derived := argon2.IDKey(password, salt, 1, 32*1024, 2, 32)
fmt.Printf("argon2id: %s\n", hex.EncodeToString(derived))
hashed, err := bcrypt.GenerateFromPassword(password, bcrypt.MinCost)
if err != nil {
panic(err)
}
if err := bcrypt.CompareHashAndPassword(hashed, password); err != nil {
panic(err)
}
digest := sha3.Sum256(password)
fmt.Printf("sha3-256: %s\n", hex.EncodeToString(digest[:]))
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/golang.org/x/crypto@v0.58.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/crypto@v0.58.0"
]
}
package main
import (
"bytes"
"errors"
"fmt"
"os"
"golang.org/x/crypto/argon2"
"golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/sha3"
)
func main() {
pass := []byte("verification-passphrase")
salt := []byte("verification-salt-16")
// 1. argon2.IDKey derives deterministic key bytes matching requested length and varies with password or salt
key1 := argon2.IDKey(pass, salt, 1, 32*1024, 2, 32)
if len(key1) != 32 {
fmt.Fprintf(os.Stderr, "expected key length 32, got %d\n", len(key1))
os.Exit(1)
}
key2 := argon2.IDKey(pass, salt, 1, 32*1024, 2, 32)
if !bytes.Equal(key1, key2) {
fmt.Fprintf(os.Stderr, "expected deterministic argon2.IDKey output\n")
os.Exit(1)
}
keyDiffPass := argon2.IDKey([]byte("other-passphrase"), salt, 1, 32*1024, 2, 32)
if bytes.Equal(key1, keyDiffPass) {
fmt.Fprintf(os.Stderr, "expected different argon2.IDKey output for different password\n")
os.Exit(1)
}
keyDiffSalt := argon2.IDKey(pass, []byte("other-salt-value-16"), 1, 32*1024, 2, 32)
if bytes.Equal(key1, keyDiffSalt) {
fmt.Fprintf(os.Stderr, "expected different argon2.IDKey output for different salt\n")
os.Exit(1)
}
// 2. bcrypt.GenerateFromPassword and bcrypt.CompareHashAndPassword verify matching passwords and reject mismatches
hash, err := bcrypt.GenerateFromPassword(pass, bcrypt.MinCost)
if err != nil {
fmt.Fprintf(os.Stderr, "bcrypt.GenerateFromPassword failed: %v\n", err)
os.Exit(1)
}
cost, err := bcrypt.Cost(hash)
if err != nil || cost != bcrypt.MinCost {
fmt.Fprintf(os.Stderr, "expected bcrypt cost %d, got %d (err=%v)\n", bcrypt.MinCost, cost, err)
os.Exit(1)
}
if err := bcrypt.CompareHashAndPassword(hash, pass); err != nil {
fmt.Fprintf(os.Stderr, "expected bcrypt.CompareHashAndPassword to succeed: %v\n", err)
os.Exit(1)
}
if err := bcrypt.CompareHashAndPassword(hash, []byte("wrong-passphrase")); !errors.Is(err, bcrypt.ErrMismatchedHashAndPassword) {
fmt.Fprintf(os.Stderr, "expected ErrMismatchedHashAndPassword, got: %v\n", err)
os.Exit(1)
}
// 3. sha3.Sum256 and sha3.New256 produce identical 32-byte digests for the same input
sum := sha3.Sum256(pass)
h := sha3.New256()
_, _ = h.Write(pass)
streamSum := h.Sum(nil)
if !bytes.Equal(sum[:], streamSum) {
fmt.Fprintf(os.Stderr, "expected sha3.Sum256 and sha3.New256 to match\n")
os.Exit(1)
}
otherSum := sha3.Sum256([]byte("different-input"))
if bytes.Equal(sum[:], otherSum[:]) {
fmt.Fprintf(os.Stderr, "expected different sha3-256 digests for distinct inputs\n")
os.Exit(1)
}
fmt.Println("Contract passed.")
}
原始种子者
匿名