CodeSampleX

샘플

golang.org/x/crypto v0.56.0: pbkdf2.Key

검증된 샘플 — golang golang.org/x/crypto v0.56.0: pbkdf2.Key. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: pbkdf2.Key derives key bytes matching…

sha256:e2e88860e3d3d29724e220b1f54baee1c917326dc7c2395b32622b363dce4792

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 go

검증 실행 환경

환경 컨트랙트 단계 실행일
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-09-04

케이스

HOW
목표
verify pkg:golang/golang.org/x/crypto@v0.56.0
패키지
심벌
  • pbkdf2.Key
생성일
2026-09-04T15:50:41Z

컨트랙트

  1. pbkdf2.Key derives key bytes matching requested length
  2. pbkdf2.Key produces identical derived keys for identical password, salt, and parameters
  3. pbkdf2.Key produces different derived keys for different passwords with identical parameters
  4. pbkdf2.Key produces different derived keys for different salts with identical parameters
  5. pbkdf2.Key matches RFC 6070 test vector for SHA-1 with 1 iteration
  6. pbkdf2.Key matches RFC 6070 test vector for SHA-1 with 4096 iterations
  7. pbkdf2.Key matches standard test vector for SHA-256 with 4096 iterations
  8. pbkdf2.Key correctly handles null bytes inside password and salt

파일

  • 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 pkg:golang/golang.org/x/crypto@v0.56.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/crypto@v0.56.0
Demonstrate these symbols/APIs:
  - pbkdf2.Key

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:163c48b020a160ec86af5fab7b209514cb52901e6992cc6755382783f5a643b5","contract":["pbkdf2.Key derives key bytes matching requested length","pbkdf2.Key produces identical derived keys for identical password, salt, and parameters","pbkdf2.Key produces different derived keys for different passwords with identical parameters","pbkdf2.Key produces different derived keys for different salts with identical parameters","pbkdf2.Key matches RFC 6070 test vector for SHA-1 with 1 iteration","pbkdf2.Key matches RFC 6070 test vector for SHA-1 with 4096 iterations","pbkdf2.Key matches standard test vector for SHA-256 with 4096 iterations","pbkdf2.Key correctly handles null bytes inside password and salt"],"goal":"verify pkg:golang/golang.org/x/crypto@v0.56.0","kind":"HOW","packages":["pkg:golang/golang.org/x/crypto@v0.56.0"],"schemaVersion":1,"symbols":["pbkdf2.Key"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/crypto@v0.56.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/crypto@v0.56.0","symbols":["pbkdf2.Key"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/crypto v0.56.0
go.sum
golang.org/x/crypto v0.56.0 h1:GUh5Ii4J5jtcseSMiRqr1jXCNHoxjeV9Fmekc2oLy6Y=
golang.org/x/crypto v0.56.0/go.mod h1:OMW5y6CY9l38uPLmxU6l6pwcXp1obtLo3e6gT7gQR2I=
main.go
package main

import (
	"crypto/sha256"
	"encoding/hex"
	"fmt"

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

func main() {
	password := []byte("example-password")
	salt := []byte("example-salt")
	iterations := 4096
	keyLength := 32

	derivedKey := pbkdf2.Key(password, salt, iterations, keyLength, sha256.New)
	fmt.Printf("Derived key (%d bytes): %s\n", len(derivedKey), hex.EncodeToString(derivedKey))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/crypto@v0.56.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/crypto@v0.56.0"
  ],
  "symbols": [
    "pbkdf2.Key"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"crypto/sha1"
	"crypto/sha256"
	"fmt"
	"os"

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

func main() {
	pass := []byte("example-secret-passphrase")
	salt := []byte("example-cryptographic-salt")

	// 1. pbkdf2.Key derives key bytes matching requested length
	for _, expectedLen := range []int{16, 32, 64} {
		key := pbkdf2.Key(pass, salt, 1000, expectedLen, sha256.New)
		if len(key) != expectedLen {
			fmt.Fprintf(os.Stderr, "Key length mismatch: expected %d, got %d\n", expectedLen, len(key))
			os.Exit(1)
		}
	}

	// 2. pbkdf2.Key produces identical derived keys for identical password, salt, and parameters
	keyA := pbkdf2.Key(pass, salt, 2048, 32, sha256.New)
	keyB := pbkdf2.Key(pass, salt, 2048, 32, sha256.New)
	if !bytes.Equal(keyA, keyB) {
		fmt.Fprintf(os.Stderr, "Deterministic derivation failed: identical inputs yielded different keys\n")
		os.Exit(1)
	}

	// 3. pbkdf2.Key produces different derived keys for different passwords with identical parameters
	diffPassKey := pbkdf2.Key([]byte("another-secret-passphrase"), salt, 2048, 32, sha256.New)
	if bytes.Equal(keyA, diffPassKey) {
		fmt.Fprintf(os.Stderr, "Different passwords unexpectedly produced identical keys\n")
		os.Exit(1)
	}

	// 4. pbkdf2.Key produces different derived keys for different salts with identical parameters
	diffSaltKey := pbkdf2.Key(pass, []byte("different-salt-value"), 2048, 32, sha256.New)
	if bytes.Equal(keyA, diffSaltKey) {
		fmt.Fprintf(os.Stderr, "Different salts unexpectedly produced identical keys\n")
		os.Exit(1)
	}

	// 5. pbkdf2.Key matches RFC 6070 test vector for SHA-1 with 1 iteration
	expectedRfcSha1Iter1 := []byte{
		0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71,
		0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06,
		0x2f, 0xe0, 0x37, 0xa6,
	}
	actualRfcSha1Iter1 := pbkdf2.Key([]byte("password"), []byte("salt"), 1, 20, sha1.New)
	if !bytes.Equal(actualRfcSha1Iter1, expectedRfcSha1Iter1) {
		fmt.Fprintf(os.Stderr, "RFC 6070 SHA-1 (iter=1) mismatch: got %x, want %x\n", actualRfcSha1Iter1, expectedRfcSha1Iter1)
		os.Exit(1)
	}

	// 6. pbkdf2.Key matches RFC 6070 test vector for SHA-1 with 4096 iterations
	expectedRfcSha1Iter4096 := []byte{
		0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a,
		0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0,
		0x65, 0xa4, 0x29, 0xc1,
	}
	actualRfcSha1Iter4096 := pbkdf2.Key([]byte("password"), []byte("salt"), 4096, 20, sha1.New)
	if !bytes.Equal(actualRfcSha1Iter4096, expectedRfcSha1Iter4096) {
		fmt.Fprintf(os.Stderr, "RFC 6070 SHA-1 (iter=4096) mismatch: got %x, want %x\n", actualRfcSha1Iter4096, expectedRfcSha1Iter4096)
		os.Exit(1)
	}

	// 7. pbkdf2.Key matches standard test vector for SHA-256 with 4096 iterations
	expectedSha256Iter4096 := []byte{
		0xc5, 0xe4, 0x78, 0xd5, 0x92, 0x88, 0xc8, 0x41,
		0xaa, 0x53, 0x0d, 0xb6, 0x84, 0x5c, 0x4c, 0x8d,
		0x96, 0x28, 0x93, 0xa0,
	}
	actualSha256Iter4096 := pbkdf2.Key([]byte("password"), []byte("salt"), 4096, 20, sha256.New)
	if !bytes.Equal(actualSha256Iter4096, expectedSha256Iter4096) {
		fmt.Fprintf(os.Stderr, "SHA-256 (iter=4096) mismatch: got %x, want %x\n", actualSha256Iter4096, expectedSha256Iter4096)
		os.Exit(1)
	}

	// 8. pbkdf2.Key correctly handles null bytes inside password and salt
	expectedNullBytes := []byte{
		0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d,
		0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3,
	}
	actualNullBytes := pbkdf2.Key([]byte("pass\x00word"), []byte("sa\x00lt"), 4096, 16, sha1.New)
	if !bytes.Equal(actualNullBytes, expectedNullBytes) {
		fmt.Fprintf(os.Stderr, "Null-byte handling mismatch: got %x, want %x\n", actualNullBytes, expectedNullBytes)
		os.Exit(1)
	}

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

오리진 시더

익명