CodeSampleX

Пример

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

Проверенный пример — golang golang.org/x/crypto v0.36.0: scrypt.Key. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден: scrypt.Key derives…

sha256:73ccd4397e4063e6f5a9638168fcaa719fe76a0a80b0101428ede3777d6e74d8

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
3
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 go

Среды запусков проверки

Окружение Контракт Этапы Запуск
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-02
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-02
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-02

Кейс

HOW
Цель
verify scrypt.Key in pkg:golang/golang.org/x/crypto@v0.36.0
Пакеты
Символы
  • scrypt.Key
Создан
2026-09-02T14:34:37Z

Контракт

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

Файлы

  • 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 scrypt.Key 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:
  - scrypt.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:544a8f3014a8b9877a266c5eff6ff5f073c031803035f7ba13c45dde48994466","contract":["scrypt.Key derives deterministic key bytes matching the specified key length","scrypt.Key produces identical derived keys for identical password, salt, and parameters","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 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.36.0","kind":"HOW","packages":["pkg:golang/golang.org/x/crypto@v0.36.0"],"schemaVersion":1,"symbols":["scrypt.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.36.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/crypto@v0.36.0","symbols":["scrypt.Key"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/crypto v0.36.0
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=
main.go
package main

import (
	"fmt"
	"log"

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

func main() {
	password := []byte("example-user-password")
	salt := []byte("example-unique-salt-1234")

	// Standard recommended parameters: N=16384, r=8, p=1, keyLen=32
	derivedKey, err := scrypt.Key(password, salt, 16384, 8, 1, 32)
	if err != nil {
		log.Fatalf("scrypt.Key failed: %v", err)
	}

	fmt.Printf("Derived key (32 bytes): %x\n", derivedKey)
	fmt.Println("scrypt key derivation successful.")
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify scrypt.Key in pkg:golang/golang.org/x/crypto@v0.36.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/crypto@v0.36.0"
  ],
  "symbols": [
    "scrypt.Key"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

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

func main() {
	password := []byte("test-password-input")
	salt := []byte("test-salt-bytes-16")
	const N = 16
	const r = 8
	const p = 1
	const 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, "scrypt.Key failed: %v\n", err)
		os.Exit(1)
	}
	if len(key1) != keyLen {
		fmt.Fprintf(os.Stderr, "scrypt.Key length mismatch: expected %d, got %d\n", keyLen, len(key1))
		os.Exit(1)
	}

	// 2. scrypt.Key produces identical derived keys for identical password, salt, and parameters
	key2, err := scrypt.Key(password, salt, N, r, p, keyLen)
	if err != nil {
		fmt.Fprintf(os.Stderr, "scrypt.Key second call failed: %v\n", err)
		os.Exit(1)
	}
	if !bytes.Equal(key1, key2) {
		fmt.Fprintf(os.Stderr, "scrypt.Key is not deterministic for identical inputs\n")
		os.Exit(1)
	}

	// 3. scrypt.Key produces different derived keys for different passwords with identical parameters
	keyDiffPassword, err := scrypt.Key([]byte("different-password"), salt, N, r, p, keyLen)
	if err != nil {
		fmt.Fprintf(os.Stderr, "scrypt.Key with different password failed: %v\n", err)
		os.Exit(1)
	}
	if bytes.Equal(key1, keyDiffPassword) {
		fmt.Fprintf(os.Stderr, "scrypt.Key should produce different keys for different passwords\n")
		os.Exit(1)
	}

	// 4. scrypt.Key produces different derived keys for different salts with identical parameters
	keyDiffSalt, err := scrypt.Key(password, []byte("different-salt-9999"), N, r, p, keyLen)
	if err != nil {
		fmt.Fprintf(os.Stderr, "scrypt.Key with different salt failed: %v\n", err)
		os.Exit(1)
	}
	if bytes.Equal(key1, keyDiffSalt) {
		fmt.Fprintf(os.Stderr, "scrypt.Key should produce different keys for different salts\n")
		os.Exit(1)
	}

	// 5. scrypt.Key produces different derived keys when cost parameter N is varied
	keyDiffN, err := scrypt.Key(password, salt, 32, r, p, keyLen)
	if err != nil {
		fmt.Fprintf(os.Stderr, "scrypt.Key with N=32 failed: %v\n", err)
		os.Exit(1)
	}
	if bytes.Equal(key1, keyDiffN) {
		fmt.Fprintf(os.Stderr, "scrypt.Key should produce different keys for different cost parameter N\n")
		os.Exit(1)
	}

	// 6. scrypt.Key returns an error when N is not a power of 2 or less than or equal to 1
	invalidNs := []int{0, 1, -1, 3, 15, 100}
	for _, invalidN := range invalidNs {
		if _, err := scrypt.Key(password, salt, invalidN, r, p, keyLen); err == nil {
			fmt.Fprintf(os.Stderr, "scrypt.Key expected error for invalid N=%d, got nil\n", invalidN)
			os.Exit(1)
		}
	}

	// 7. 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, "scrypt.Key expected error when r*p >= 1<<30, got nil\n")
		os.Exit(1)
	}

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

Исходный сидер

аноним