CodeSampleX

Ejemplo

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

Muestra verificada para golang golang.org/x/crypto v0.56.0: pbkdf2.Key. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó: pbkdf2.Key…

sha256:e2e88860e3d3d29724e220b1f54baee1c917326dc7c2395b32622b363dce4792

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify pkg:golang/golang.org/x/crypto@v0.56.0
Paquetes
Símbolos
  • pbkdf2.Key
Creado
2026-09-04T15:50:41Z

Contrato

  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

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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.")
}

Seeder de origen

anónimo