CodeSampleX

示例

golang.org/x/crypto v0.36.0: argon2.IDKey

已验证示例 — golang golang.org/x/crypto v0.36.0: argon2.IDKey. contract 在 go 1.26 · linux alpine/x64 · docker 上运行并通过: argon2.IDKey derives deterministic key bytes…

sha256:0c78b9cf475434936e29b4a088ff138b5b46b6f44967a47dedbbbac15765797a

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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-26

案例

HOW
目标
verify argon2.IDKey in pkg:golang/golang.org/x/crypto@v0.36.0
包
符号
  • argon2.IDKey
环境
go 1.26.6
创建时间
2026-08-26T01:18:24Z

契约

  1. argon2.IDKey derives deterministic key bytes matching the specified key length
  2. argon2.IDKey produces different derived keys for different passwords with identical salt and cost parameters
  3. argon2.IDKey produces different derived keys for different salts with identical password and cost parameters
  4. argon2.IDKey produces different derived keys when time parameter is varied
  5. argon2.IDKey produces different derived keys when memory parameter is varied
  6. argon2.IDKey produces different derived keys than argon2.Key with identical input parameters

文件

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

下载源代码构件 (tar.gz)

源代码

PROMPT.md
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 argon2.IDKey in pkg:golang/golang.org/x/crypto@v0.36.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/crypto@v0.36.0
Demonstrate these symbols/APIs:
  - argon2.IDKey
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.
csx.json
{"case":{"caseId":"case:sha256:0ca692fb8dbd20e36ea0219b0ff76f50bc5a1f03af22699ba9ade7384336adb0","contract":["argon2.IDKey derives deterministic key bytes matching the specified key length","argon2.IDKey produces different derived keys for different passwords with identical salt and cost parameters","argon2.IDKey produces different derived keys for different salts with identical password and cost parameters","argon2.IDKey produces different derived keys when time parameter is varied","argon2.IDKey produces different derived keys when memory parameter is varied","argon2.IDKey produces different derived keys than argon2.Key with identical input parameters"],"goal":"verify argon2.IDKey in pkg:golang/golang.org/x/crypto@v0.36.0","kind":"HOW","packages":["pkg:golang/golang.org/x/crypto@v0.36.0"],"schemaVersion":1,"symbols":["argon2.IDKey"]},"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.36.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/crypto@v0.36.0","symbols":["argon2.IDKey"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require golang.org/x/crypto v0.36.0

require golang.org/x/sys v0.31.0 // indirect
go.sum
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
main.go
package main

import (
	"encoding/hex"
	"fmt"

	"golang.org/x/crypto/argon2"
)

func main() {
	password := []byte("example-secret-passphrase")
	salt := []byte("example-unique-salt-16b")

	// Argon2id parameters
	var (
		time    uint32 = 1
		memory  uint32 = 64 * 1024 // 64 MB in KiB
		threads uint8  = 4
		keyLen  uint32 = 32 // 32-byte (256-bit) key
	)

	// Derive a 32-byte key using Argon2id
	derivedKey := argon2.IDKey(password, salt, time, memory, threads, keyLen)

	fmt.Printf("Derived key length: %d bytes\n", len(derivedKey))
	fmt.Printf("Derived key (hex): %s\n", hex.EncodeToString(derivedKey))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify argon2.IDKey in pkg:golang/golang.org/x/crypto@v0.36.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/crypto@v0.36.0"
  ],
  "symbols": [
    "argon2.IDKey"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"golang.org/x/crypto/argon2"
)

func main() {
	pass := []byte("secure-user-password")
	salt := []byte("random-salt-1234")

	var (
		time    uint32 = 1
		memory  uint32 = 32 * 1024 // 32 MB in KiB
		threads uint8  = 2
		keyLen  uint32 = 32
	)

	// 1. argon2.IDKey derives deterministic key bytes matching the specified key length
	key1 := argon2.IDKey(pass, salt, time, memory, threads, keyLen)
	if len(key1) != int(keyLen) {
		fmt.Fprintf(os.Stderr, "Expected key length %d, got %d\n", keyLen, len(key1))
		os.Exit(1)
	}

	key2 := argon2.IDKey(pass, salt, time, memory, threads, keyLen)
	if !bytes.Equal(key1, key2) {
		fmt.Fprintf(os.Stderr, "Expected deterministic output for identical parameters, but keys differed\n")
		os.Exit(1)
	}

	// 2. argon2.IDKey produces different derived keys for different passwords with identical salt and cost parameters
	otherPass := []byte("different-user-password")
	keyDiffPass := argon2.IDKey(otherPass, salt, time, memory, threads, keyLen)
	if bytes.Equal(key1, keyDiffPass) {
		fmt.Fprintf(os.Stderr, "Expected different keys for different passwords, but got identical keys\n")
		os.Exit(1)
	}

	// 3. argon2.IDKey produces different derived keys for different salts with identical password and cost parameters
	otherSalt := []byte("different-salt-5678")
	keyDiffSalt := argon2.IDKey(pass, otherSalt, time, memory, threads, keyLen)
	if bytes.Equal(key1, keyDiffSalt) {
		fmt.Fprintf(os.Stderr, "Expected different keys for different salts, but got identical keys\n")
		os.Exit(1)
	}

	// 4. argon2.IDKey produces different derived keys when time parameter is varied
	keyDiffTime := argon2.IDKey(pass, salt, time+1, memory, threads, keyLen)
	if bytes.Equal(key1, keyDiffTime) {
		fmt.Fprintf(os.Stderr, "Expected different keys for different time parameters, but got identical keys\n")
		os.Exit(1)
	}

	// 5. argon2.IDKey produces different derived keys when memory parameter is varied
	keyDiffMemory := argon2.IDKey(pass, salt, time, memory*2, threads, keyLen)
	if bytes.Equal(key1, keyDiffMemory) {
		fmt.Fprintf(os.Stderr, "Expected different keys for different memory parameters, but got identical keys\n")
		os.Exit(1)
	}

	// 6. argon2.IDKey produces different derived keys than argon2.Key with identical input parameters
	argon2iKey := argon2.Key(pass, salt, time, memory, threads, keyLen)
	if bytes.Equal(key1, argon2iKey) {
		fmt.Fprintf(os.Stderr, "Expected argon2.IDKey (Argon2id) to differ from argon2.Key (Argon2i), but got identical keys\n")
		os.Exit(1)
	}

	fmt.Println("All contract assertions passed.")
}

原始种子者

匿名