CodeSampleX

Sample

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

Verified sample for golang golang.org/x/crypto v0.19.0: scrypt.Key. The contract ran on go 1.26 · linux alpine/x64 · docker and passed.

sha256:6398a81de18c8c26abdb6b84232ba2712d7c1aa342b2ffa3c48688ed74c1dd05

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Verification-run environments

Environment Contract Stages Run
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-29

Case

HOW
Goal
verify scrypt.Key in pkg:golang/golang.org/x/crypto@v0.19.0
Packages
Symbols
  • scrypt.Key
Environment
go 1.26.6
Created
2026-08-29T05:22:11Z

Contract

  1. scrypt.Key derives deterministic key bytes matching the specified key length
  2. scrypt.Key produces different derived keys for different passwords with identical parameters
  3. scrypt.Key produces different derived keys for different salts with identical parameters
  4. scrypt.Key produces different derived keys when cost parameter N is varied
  5. scrypt.Key produces different derived keys when block size parameter r is varied
  6. scrypt.Key produces different derived keys when parallelization parameter p is varied
  7. scrypt.Key returns an error when N is not a power of 2 or less than or equal to 1
  8. scrypt.Key returns an error when parameters r and p are too large

Files

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

Download the source artifact (tar.gz)

Source

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 scrypt.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:
  - scrypt.Key
Required runtime conditions:
  - ecosystem: golang
  - language: go
  - packageManager: go@1.26.6
  - runtime: go@1.26.6

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:3e9d4892d3e483102ba3267f00d295308a056bc172f15d08a49f8ab4c0afbaee","contract":["scrypt.Key derives deterministic key bytes matching the specified key length","scrypt.Key produces different derived keys for different passwords with identical parameters","scrypt.Key produces different derived keys for different salts with identical parameters","scrypt.Key produces different derived keys when cost parameter N is varied","scrypt.Key produces different derived keys when block size parameter r is varied","scrypt.Key produces different derived keys when parallelization parameter p is varied","scrypt.Key returns an error when N is not a power of 2 or less than or equal to 1","scrypt.Key returns an error when parameters r and p are too large"],"goal":"verify scrypt.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":["scrypt.Key"]},"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.19.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/crypto@v0.19.0","symbols":["scrypt.Key"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require golang.org/x/crypto v0.19.0
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 (
	"encoding/hex"
	"fmt"
	"log"

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

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

	// Recommended parameters: N=32768, r=8, p=1, keyLen=32
	const (
		N      = 32768
		r      = 8
		p      = 1
		keyLen = 32
	)

	derivedKey, err := scrypt.Key(password, salt, N, r, p, keyLen)
	if err != nil {
		log.Fatalf("scrypt key derivation failed: %v", err)
	}

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

import (
	"bytes"
	"fmt"
	"os"

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

func main() {
	password := []byte("secure-password-test")
	salt := []byte("salt-value-1234")

	const (
		N      = 16
		r      = 1
		p      = 1
		keyLen = 32
	)

	// 1. scrypt.Key derives deterministic key bytes matching the specified key length
	key1, err := scrypt.Key(password, salt, N, r, p, keyLen)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error in Key: %v\n", err)
		os.Exit(1)
	}
	if len(key1) != keyLen {
		fmt.Fprintf(os.Stderr, "Expected key length %d, got %d\n", keyLen, len(key1))
		os.Exit(1)
	}

	key2, err := scrypt.Key(password, salt, N, r, p, keyLen)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error in second Key call: %v\n", err)
		os.Exit(1)
	}
	if !bytes.Equal(key1, key2) {
		fmt.Fprintf(os.Stderr, "Expected deterministic output for identical parameters, but keys differed\n")
		os.Exit(1)
	}

	// 2. scrypt.Key produces different derived keys for different passwords with identical parameters
	otherPassword := []byte("different-password-test")
	keyDiffPass, err := scrypt.Key(otherPassword, salt, N, r, p, keyLen)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error with different password: %v\n", err)
		os.Exit(1)
	}
	if bytes.Equal(key1, keyDiffPass) {
		fmt.Fprintf(os.Stderr, "Expected different keys for different passwords, but got identical keys\n")
		os.Exit(1)
	}

	// 3. scrypt.Key produces different derived keys for different salts with identical parameters
	otherSalt := []byte("different-salt-5678")
	keyDiffSalt, err := scrypt.Key(password, otherSalt, N, r, p, keyLen)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error with different salt: %v\n", err)
		os.Exit(1)
	}
	if bytes.Equal(key1, keyDiffSalt) {
		fmt.Fprintf(os.Stderr, "Expected different keys for different salts, but got identical keys\n")
		os.Exit(1)
	}

	// 4. scrypt.Key produces different derived keys when cost parameter N is varied
	keyDiffN, err := scrypt.Key(password, salt, N*2, r, p, keyLen)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error with different N: %v\n", err)
		os.Exit(1)
	}
	if bytes.Equal(key1, keyDiffN) {
		fmt.Fprintf(os.Stderr, "Expected different keys for different N, but got identical keys\n")
		os.Exit(1)
	}

	// 5. scrypt.Key produces different derived keys when block size parameter r is varied
	keyDiffR, err := scrypt.Key(password, salt, N, r+1, p, keyLen)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error with different r: %v\n", err)
		os.Exit(1)
	}
	if bytes.Equal(key1, keyDiffR) {
		fmt.Fprintf(os.Stderr, "Expected different keys for different r, but got identical keys\n")
		os.Exit(1)
	}

	// 6. scrypt.Key produces different derived keys when parallelization parameter p is varied
	keyDiffP, err := scrypt.Key(password, salt, N, r, p+1, keyLen)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unexpected error with different p: %v\n", err)
		os.Exit(1)
	}
	if bytes.Equal(key1, keyDiffP) {
		fmt.Fprintf(os.Stderr, "Expected different keys for different p, but got identical keys\n")
		os.Exit(1)
	}

	// 7. scrypt.Key returns an error when N is not a power of 2 or less than or equal to 1
	if _, err := scrypt.Key(password, salt, 0, r, p, keyLen); err == nil {
		fmt.Fprintf(os.Stderr, "Expected error for N=0, but got nil\n")
		os.Exit(1)
	}
	if _, err := scrypt.Key(password, salt, 1, r, p, keyLen); err == nil {
		fmt.Fprintf(os.Stderr, "Expected error for N=1, but got nil\n")
		os.Exit(1)
	}
	if _, err := scrypt.Key(password, salt, 1000, r, p, keyLen); err == nil {
		fmt.Fprintf(os.Stderr, "Expected error for non-power-of-2 N=1000, but got nil\n")
		os.Exit(1)
	}

	// 8. scrypt.Key returns an error when parameters r and p are too large
	if _, err := scrypt.Key(password, salt, N, 1<<15, 1<<15, keyLen); err == nil {
		fmt.Fprintf(os.Stderr, "Expected error for r*p >= 1<<30, but got nil\n")
		os.Exit(1)
	}

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

Origin Seeder

anonymous