CodeSampleX

Beispiel

github.com/flynn/noise v1.0.0: CipherChaChaPoly

Verifiziertes Beispiel für golang github.com/flynn/noise v1.0.0: CipherChaChaPoly. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und bestand.

sha256:a31b53f8dda6e737b69d00ff939016392b2b2db672bc7b8e9672cae7f7caf036

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify github.com/flynn/noise.CipherChaChaPoly in pkg:golang/github.com/flynn/noise@v1.0.0
Pakete
Symbole
  • github.com/flynn/noise.CipherChaChaPoly
Erstellt
2026-09-04T03:02:43Z

Contract

  1. noise.CipherChaChaPoly identifies itself as ChaChaPoly cipher suite component
  2. noise.CipherChaChaPoly.Cipher initializes an AEAD cipher that encrypts plaintext with an authentication tag
  3. noise.Cipher.Decrypt authenticates and decrypts valid ciphertext back to original plaintext
  4. noise.Cipher.Decrypt rejects tampered ciphertext or mismatched authenticated data with an authentication error
  5. noise.CipherChaChaPoly integrates into Noise CipherSuite for secure handshake and transport message encryption

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 github.com/flynn/noise.CipherChaChaPoly in pkg:golang/github.com/flynn/noise@v1.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/flynn/noise@v1.0.0
Demonstrate these symbols/APIs:
  - github.com/flynn/noise.CipherChaChaPoly

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:5c6447d94714b5531bc49f783aeba895150259e271ebf6bc27494bcb47725be5","contract":["noise.CipherChaChaPoly identifies itself as ChaChaPoly cipher suite component","noise.CipherChaChaPoly.Cipher initializes an AEAD cipher that encrypts plaintext with an authentication tag","noise.Cipher.Decrypt authenticates and decrypts valid ciphertext back to original plaintext","noise.Cipher.Decrypt rejects tampered ciphertext or mismatched authenticated data with an authentication error","noise.CipherChaChaPoly integrates into Noise CipherSuite for secure handshake and transport message encryption"],"goal":"verify github.com/flynn/noise.CipherChaChaPoly in pkg:golang/github.com/flynn/noise@v1.0.0","kind":"HOW","packages":["pkg:golang/github.com/flynn/noise@v1.0.0"],"schemaVersion":1,"symbols":["github.com/flynn/noise.CipherChaChaPoly"]},"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/github.com/flynn/noise@v1.0.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/flynn/noise@v1.0.0","symbols":["github.com/flynn/noise.CipherChaChaPoly"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22.0

require github.com/flynn/noise v1.0.0

require (
	golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
	golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
)
go.sum
github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ=
github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
main.go
package main

import (
	"bytes"
	"crypto/rand"
	"fmt"
	"os"

	"github.com/flynn/noise"
)

func main() {
	// 1. Direct AEAD encryption and decryption with CipherChaChaPoly
	var key [32]byte
	if _, err := rand.Read(key[:]); err != nil {
		fmt.Fprintf(os.Stderr, "failed to generate random key: %v\n", err)
		os.Exit(1)
	}

	cipher := noise.CipherChaChaPoly.Cipher(key)
	fmt.Printf("Cipher algorithm: %s\n", noise.CipherChaChaPoly.CipherName())

	nonce := uint64(0)
	ad := []byte("header-metadata")
	plaintext := []byte("secret payload protected by ChaCha20-Poly1305")

	ciphertext := cipher.Encrypt(nil, nonce, ad, plaintext)
	fmt.Printf("Ciphertext length: %d bytes (plaintext %d + tag 16)\n", len(ciphertext), len(plaintext))

	decrypted, err := cipher.Decrypt(nil, nonce, ad, ciphertext)
	if err != nil {
		fmt.Fprintf(os.Stderr, "decryption failed: %v\n", err)
		os.Exit(1)
	}

	if !bytes.Equal(decrypted, plaintext) {
		fmt.Fprintf(os.Stderr, "decrypted message mismatch\n")
		os.Exit(1)
	}

	fmt.Printf("Successfully decrypted message: %s\n", string(decrypted))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/flynn/noise.CipherChaChaPoly in pkg:golang/github.com/flynn/noise@v1.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/flynn/noise@v1.0.0"
  ],
  "symbols": [
    "github.com/flynn/noise.CipherChaChaPoly"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"crypto/rand"
	"fmt"
	"os"

	"github.com/flynn/noise"
)

func main() {
	// Assertion 1: noise.CipherChaChaPoly identifies itself as ChaChaPoly cipher suite component
	if name := noise.CipherChaChaPoly.CipherName(); name != "ChaChaPoly" {
		fmt.Fprintf(os.Stderr, "FAIL: CipherName expected 'ChaChaPoly', got %q\n", name)
		os.Exit(1)
	}

	// Assertion 2: noise.CipherChaChaPoly.Cipher initializes an AEAD cipher that encrypts plaintext with an authentication tag
	var key [32]byte
	if _, err := rand.Read(key[:]); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: rand.Read key failed: %v\n", err)
		os.Exit(1)
	}
	cipher := noise.CipherChaChaPoly.Cipher(key)
	if cipher == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Cipher returned nil\n")
		os.Exit(1)
	}

	nonce := uint64(1)
	ad := []byte("authenticated-associated-data")
	plaintext := []byte("confidential message payload verified by csx contract")

	ciphertext := cipher.Encrypt(nil, nonce, ad, plaintext)
	expectedLen := len(plaintext) + 16 // ChaCha20-Poly1305 uses a 16-byte Poly1305 tag
	if len(ciphertext) != expectedLen {
		fmt.Fprintf(os.Stderr, "FAIL: ciphertext length expected %d, got %d\n", expectedLen, len(ciphertext))
		os.Exit(1)
	}
	if bytes.Equal(ciphertext[:len(plaintext)], plaintext) {
		fmt.Fprintf(os.Stderr, "FAIL: ciphertext prefix matches plaintext (encryption failed)\n")
		os.Exit(1)
	}

	// Assertion 3: noise.Cipher.Decrypt authenticates and decrypts valid ciphertext back to original plaintext
	decrypted, err := cipher.Decrypt(nil, nonce, ad, ciphertext)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Decrypt valid ciphertext failed: %v\n", err)
		os.Exit(1)
	}
	if !bytes.Equal(decrypted, plaintext) {
		fmt.Fprintf(os.Stderr, "FAIL: decrypted text mismatch: got %q, want %q\n", decrypted, plaintext)
		os.Exit(1)
	}

	// Assertion 4: noise.Cipher.Decrypt rejects tampered ciphertext or mismatched authenticated data with an authentication error
	tamperedCiphertext := make([]byte, len(ciphertext))
	copy(tamperedCiphertext, ciphertext)
	tamperedCiphertext[0] ^= 0x01
	if _, err := cipher.Decrypt(nil, nonce, ad, tamperedCiphertext); err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Decrypt succeeded on tampered ciphertext\n")
		os.Exit(1)
	}

	wrongAD := []byte("tampered-associated-data")
	if _, err := cipher.Decrypt(nil, nonce, wrongAD, ciphertext); err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Decrypt succeeded with wrong authenticated data\n")
		os.Exit(1)
	}

	wrongNonce := nonce + 1
	if _, err := cipher.Decrypt(nil, wrongNonce, ad, ciphertext); err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Decrypt succeeded with wrong nonce\n")
		os.Exit(1)
	}

	// Assertion 5: noise.CipherChaChaPoly integrates into Noise CipherSuite for secure handshake and transport message encryption
	suite := noise.NewCipherSuite(noise.DH25519, noise.CipherChaChaPoly, noise.HashSHA256)
	initHs, err := noise.NewHandshakeState(noise.Config{
		CipherSuite: suite,
		Pattern:     noise.HandshakeNN,
		Initiator:   true,
	})
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: initiator NewHandshakeState failed: %v\n", err)
		os.Exit(1)
	}
	respHs, err := noise.NewHandshakeState(noise.Config{
		CipherSuite: suite,
		Pattern:     noise.HandshakeNN,
		Initiator:   false,
	})
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: responder NewHandshakeState failed: %v\n", err)
		os.Exit(1)
	}

	msg1, _, _, err := initHs.WriteMessage(nil, nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: initHs.WriteMessage msg1 failed: %v\n", err)
		os.Exit(1)
	}
	if _, _, _, err := respHs.ReadMessage(nil, msg1); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: respHs.ReadMessage msg1 failed: %v\n", err)
		os.Exit(1)
	}

	msg2, respSend, respRecv, err := respHs.WriteMessage(nil, nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: respHs.WriteMessage msg2 failed: %v\n", err)
		os.Exit(1)
	}
	_, initRecv, initSend, err := initHs.ReadMessage(nil, msg2)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: initHs.ReadMessage msg2 failed: %v\n", err)
		os.Exit(1)
	}

	transportMsg := []byte("handshake completed with CipherChaChaPoly")
	ct, err := initSend.Encrypt(nil, nil, transportMsg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: initSend.Encrypt failed: %v\n", err)
		os.Exit(1)
	}
	pt, err := respRecv.Decrypt(nil, nil, ct)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: respRecv.Decrypt failed: %v\n", err)
		os.Exit(1)
	}
	if !bytes.Equal(pt, transportMsg) {
		fmt.Fprintf(os.Stderr, "FAIL: transport plaintext mismatch: got %q, want %q\n", pt, transportMsg)
		os.Exit(1)
	}
	_ = respSend
	_ = initRecv

	fmt.Println("PASS: verify github.com/flynn/noise.CipherChaChaPoly contract passed")
}

Ursprungs-Seeder

anonym