CodeSampleX

샘플

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

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

sha256:ba54b8a7fafbfb2b14b0e0a029bc954e8db4ecd5c4ad5f25b62d77bb58507eac

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

실행 증거

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

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

검증 실행 환경

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

케이스

HOW
목표
verify pbkdf2.Key in pkg:golang/golang.org/x/crypto@v0.19.0
패키지
심벌
  • pbkdf2.Key
생성일
2026-08-27T12:50:08Z

컨트랙트

  1. pbkdf2.Key derives deterministic key bytes matching the specified key length
  2. pbkdf2.Key produces different derived keys for different passwords with identical salt and iteration count
  3. pbkdf2.Key produces different derived keys for different salts with identical password and iteration count
  4. pbkdf2.Key produces different derived keys when iteration count is varied
  5. pbkdf2.Key matches RFC 6070 test vector output for PBKDF2 with HMAC-SHA1
  6. pbkdf2.Key matches PBKDF2 test vector output for HMAC-SHA256

파일

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

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/crypto@v0.19.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:caa8bbe930dcc2d09e52141165eae9c1b8810298d24ea7d98384b2c37a0280fe","contract":["pbkdf2.Key derives deterministic key bytes matching the specified key length","pbkdf2.Key produces different derived keys for different passwords with identical salt and iteration count","pbkdf2.Key produces different derived keys for different salts with identical password and iteration count","pbkdf2.Key produces different derived keys when iteration count is varied","pbkdf2.Key matches RFC 6070 test vector output for PBKDF2 with HMAC-SHA1","pbkdf2.Key matches PBKDF2 test vector output for HMAC-SHA256"],"goal":"verify pbkdf2.Key in pkg:golang/golang.org/x/crypto@v0.19.0","kind":"HOW","packages":["pkg:golang/golang.org/x/crypto@v0.19.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.19.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/crypto@v0.19.0","symbols":["pbkdf2.Key"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/crypto v0.19.0 // indirect
go.sum
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
main.go
package main

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

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

func main() {
	password := []byte("example-passphrase")
	salt := []byte("random-salt-bytes")
	iterations := 10000
	keyLen := 32 // 256 bits

	// Derive a 32-byte key using PBKDF2 with HMAC-SHA256
	derivedKey := pbkdf2.Key(password, salt, iterations, keyLen, sha256.New)

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

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

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

func main() {
	password := []byte("password")
	salt := []byte("salt")

	// 1. pbkdf2.Key derives deterministic key bytes matching the specified key length
	key1 := pbkdf2.Key(password, salt, 1000, 32, sha256.New)
	key2 := pbkdf2.Key(password, salt, 1000, 32, sha256.New)
	if len(key1) != 32 {
		fmt.Fprintf(os.Stderr, "Expected key length 32, got %d\n", len(key1))
		os.Exit(1)
	}
	if !bytes.Equal(key1, key2) {
		fmt.Fprintf(os.Stderr, "pbkdf2.Key is not deterministic for identical inputs\n")
		os.Exit(1)
	}
	key64 := pbkdf2.Key(password, salt, 1000, 64, sha256.New)
	if len(key64) != 64 {
		fmt.Fprintf(os.Stderr, "Expected key length 64, got %d\n", len(key64))
		os.Exit(1)
	}

	// 2. pbkdf2.Key produces different derived keys for different passwords with identical salt and iteration count
	diffPassKey := pbkdf2.Key([]byte("different-password"), salt, 1000, 32, sha256.New)
	if bytes.Equal(key1, diffPassKey) {
		fmt.Fprintf(os.Stderr, "pbkdf2.Key produced identical keys for different passwords\n")
		os.Exit(1)
	}

	// 3. pbkdf2.Key produces different derived keys for different salts with identical password and iteration count
	diffSaltKey := pbkdf2.Key(password, []byte("different-salt"), 1000, 32, sha256.New)
	if bytes.Equal(key1, diffSaltKey) {
		fmt.Fprintf(os.Stderr, "pbkdf2.Key produced identical keys for different salts\n")
		os.Exit(1)
	}

	// 4. pbkdf2.Key produces different derived keys when iteration count is varied
	diffIterKey := pbkdf2.Key(password, salt, 2000, 32, sha256.New)
	if bytes.Equal(key1, diffIterKey) {
		fmt.Fprintf(os.Stderr, "pbkdf2.Key produced identical keys for different iteration counts\n")
		os.Exit(1)
	}

	// 5. pbkdf2.Key matches RFC 6070 test vector output for PBKDF2 with HMAC-SHA1
	// RFC 6070 test vector 1: P="password", S="salt", c=1, dkLen=20
	// DK = 0c60c80f961f0e71f3a9b524af6012062fe037a6
	rfcVec1 := pbkdf2.Key([]byte("password"), []byte("salt"), 1, 20, sha1.New)
	expectedRfc1, _ := hex.DecodeString("0c60c80f961f0e71f3a9b524af6012062fe037a6")
	if !bytes.Equal(rfcVec1, expectedRfc1) {
		fmt.Fprintf(os.Stderr, "RFC 6070 vector 1 mismatch: got %x, want %x\n", rfcVec1, expectedRfc1)
		os.Exit(1)
	}

	// RFC 6070 test vector 2: P="password", S="salt", c=2, dkLen=20
	// DK = ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957
	rfcVec2 := pbkdf2.Key([]byte("password"), []byte("salt"), 2, 20, sha1.New)
	expectedRfc2, _ := hex.DecodeString("ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957")
	if !bytes.Equal(rfcVec2, expectedRfc2) {
		fmt.Fprintf(os.Stderr, "RFC 6070 vector 2 mismatch: got %x, want %x\n", rfcVec2, expectedRfc2)
		os.Exit(1)
	}

	// RFC 6070 test vector 3: P="password", S="salt", c=4096, dkLen=20
	// DK = 4b007901b765489abead49d926f721d065a429c1
	rfcVec3 := pbkdf2.Key([]byte("password"), []byte("salt"), 4096, 20, sha1.New)
	expectedRfc3, _ := hex.DecodeString("4b007901b765489abead49d926f721d065a429c1")
	if !bytes.Equal(rfcVec3, expectedRfc3) {
		fmt.Fprintf(os.Stderr, "RFC 6070 vector 3 mismatch: got %x, want %x\n", rfcVec3, expectedRfc3)
		os.Exit(1)
	}

	// 6. pbkdf2.Key matches PBKDF2 test vector output for HMAC-SHA256
	// SHA256 test vector 1: P="password", S="salt", c=1, dkLen=32
	// DK = 120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b
	sha256Vec1 := pbkdf2.Key([]byte("password"), []byte("salt"), 1, 32, sha256.New)
	expectedSha256Vec1, _ := hex.DecodeString("120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b")
	if !bytes.Equal(sha256Vec1, expectedSha256Vec1) {
		fmt.Fprintf(os.Stderr, "HMAC-SHA256 vector 1 mismatch: got %x, want %x\n", sha256Vec1, expectedSha256Vec1)
		os.Exit(1)
	}

	// SHA256 test vector 2: P="password", S="salt", c=2, dkLen=32
	// DK = ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43
	sha256Vec2 := pbkdf2.Key([]byte("password"), []byte("salt"), 2, 32, sha256.New)
	expectedSha256Vec2, _ := hex.DecodeString("ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43")
	if !bytes.Equal(sha256Vec2, expectedSha256Vec2) {
		fmt.Fprintf(os.Stderr, "HMAC-SHA256 vector 2 mismatch: got %x, want %x\n", sha256Vec2, expectedSha256Vec2)
		os.Exit(1)
	}

	// SHA256 test vector 3: P="password", S="salt", c=4096, dkLen=32
	// DK = c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a
	sha256Vec3 := pbkdf2.Key([]byte("password"), []byte("salt"), 4096, 32, sha256.New)
	expectedSha256Vec3, _ := hex.DecodeString("c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a")
	if !bytes.Equal(sha256Vec3, expectedSha256Vec3) {
		fmt.Fprintf(os.Stderr, "HMAC-SHA256 vector 3 mismatch: got %x, want %x\n", sha256Vec3, expectedSha256Vec3)
		os.Exit(1)
	}

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

오리진 시더

익명