CodeSampleX

Exemple

golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734

Échantillon vérifié pour golang golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a…

sha256:a728f995452aeb9ea3aa5118b7b16a983c4ddd7a7e56dd5e3baa517d4c6f5b18

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-10-29

Cas

HOW
Objectif
verify pkg:golang/golang.org/x/crypto@v0.0.0-20190426145343-a29dc8fdc734
Paquets
Créé
2026-10-29T02:58:07Z

Contrat

  1. bcrypt.GenerateFromPassword, bcrypt.CompareHashAndPassword, and bcrypt.Cost hash and verify passwords at the requested cost
  2. bcrypt.CompareHashAndPassword returns ErrMismatchedHashAndPassword on wrong password and ErrHashTooShort on short hash
  3. sha3.Sum256 and sha3.New256 compute deterministic SHA3-256 digests matching known test vectors
  4. ed25519.NewKeyFromSeed, ed25519.Sign, and ed25519.Verify produce and validate deterministic Ed25519 signatures

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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 pkg:golang/golang.org/x/crypto@v0.0.0-20190426145343-a29dc8fdc734
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/crypto@v0.0.0-20190426145343-a29dc8fdc734

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:8ed90a1c37fc2c321d2e78653215eecf49aad82f44f1922c9e64d0f9e57c5c0c","contract":["bcrypt.GenerateFromPassword, bcrypt.CompareHashAndPassword, and bcrypt.Cost hash and verify passwords at the requested cost","bcrypt.CompareHashAndPassword returns ErrMismatchedHashAndPassword on wrong password and ErrHashTooShort on short hash","sha3.Sum256 and sha3.New256 compute deterministic SHA3-256 digests matching known test vectors","ed25519.NewKeyFromSeed, ed25519.Sign, and ed25519.Verify produce and validate deterministic Ed25519 signatures"],"goal":"verify pkg:golang/golang.org/x/crypto@v0.0.0-20190426145343-a29dc8fdc734","kind":"HOW","packages":["pkg:golang/golang.org/x/crypto@v0.0.0-20190426145343-a29dc8fdc734"],"schemaVersion":1},"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.0.0-20190426145343-a29dc8fdc734"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/crypto@v0.0.0-20190426145343-a29dc8fdc734","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734

require golang.org/x/sys v0.0.0-20190412213103-97732733099d // indirect
go.sum
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 h1:p/H982KKEjUnLJkM3tt/LemDnOc1GiZL5FCVlORJ5zo=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
main.go
package main

import (
	"encoding/hex"
	"fmt"
	"log"

	"golang.org/x/crypto/bcrypt"
	"golang.org/x/crypto/sha3"
)

func main() {
	hash, err := bcrypt.GenerateFromPassword([]byte("example-password"), bcrypt.MinCost)
	if err != nil {
		log.Fatalf("bcrypt.GenerateFromPassword failed: %v", err)
	}
	if err := bcrypt.CompareHashAndPassword(hash, []byte("example-password")); err != nil {
		log.Fatalf("bcrypt.CompareHashAndPassword failed: %v", err)
	}

	sum := sha3.Sum256([]byte("hello world"))
	fmt.Printf("SHA3-256: %s\n", hex.EncodeToString(sum[:]))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/crypto@v0.0.0-20190426145343-a29dc8fdc734",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/crypto@v0.0.0-20190426145343-a29dc8fdc734"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"encoding/hex"
	"errors"
	"fmt"
	"os"

	"golang.org/x/crypto/bcrypt"
	"golang.org/x/crypto/ed25519"
	"golang.org/x/crypto/sha3"
)

func main() {
	// 1. bcrypt.GenerateFromPassword, bcrypt.CompareHashAndPassword, and bcrypt.Cost hash and verify passwords at the requested cost
	password := []byte("contract-password")
	hashed, err := bcrypt.GenerateFromPassword(password, bcrypt.MinCost)
	if err != nil {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: GenerateFromPassword error: %v\n", err)
		os.Exit(1)
	}
	if err := bcrypt.CompareHashAndPassword(hashed, password); err != nil {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: CompareHashAndPassword failed for matching password: %v\n", err)
		os.Exit(1)
	}
	cost, err := bcrypt.Cost(hashed)
	if err != nil || cost != bcrypt.MinCost {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: expected cost %d, got %d (err=%v)\n", bcrypt.MinCost, cost, err)
		os.Exit(1)
	}

	// 2. bcrypt.CompareHashAndPassword returns ErrMismatchedHashAndPassword on wrong password and ErrHashTooShort on short hash
	errMismatch := bcrypt.CompareHashAndPassword(hashed, []byte("wrong-password"))
	if !errors.Is(errMismatch, bcrypt.ErrMismatchedHashAndPassword) {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected ErrMismatchedHashAndPassword, got %v\n", errMismatch)
		os.Exit(1)
	}
	errShort := bcrypt.CompareHashAndPassword([]byte("$2a$04$short"), password)
	if !errors.Is(errShort, bcrypt.ErrHashTooShort) {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected ErrHashTooShort, got %v\n", errShort)
		os.Exit(1)
	}

	// 3. sha3.Sum256 and sha3.New256 compute deterministic SHA3-256 digests matching known test vectors
	msg := []byte("abc")
	expectedHex := "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532"
	sum := sha3.Sum256(msg)
	if hex.EncodeToString(sum[:]) != expectedHex {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: unexpected Sum256 digest %x\n", sum)
		os.Exit(1)
	}
	h := sha3.New256()
	_, _ = h.Write(msg)
	if !bytes.Equal(h.Sum(nil), sum[:]) {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: New256 digest differs from Sum256\n")
		os.Exit(1)
	}

	// 4. ed25519.NewKeyFromSeed, ed25519.Sign, and ed25519.Verify produce and validate deterministic Ed25519 signatures
	seed := bytes.Repeat([]byte{0x42}, ed25519.SeedSize)
	priv := ed25519.NewKeyFromSeed(seed)
	pub := priv.Public().(ed25519.PublicKey)
	sig := ed25519.Sign(priv, msg)
	if !ed25519.Verify(pub, msg, sig) {
		fmt.Fprintf(os.Stderr, "assertion 4 failed: ed25519.Verify returned false for valid signature\n")
		os.Exit(1)
	}
	if ed25519.Verify(pub, []byte("tampered"), sig) {
		fmt.Fprintf(os.Stderr, "assertion 4 failed: ed25519.Verify returned true for tampered message\n")
		os.Exit(1)
	}
}

Seeder d'origine

anonyme