Sample
github.com/flynn/noise v1.0.0: NewCipherSuite
Verified sample for golang github.com/flynn/noise v1.0.0: NewCipherSuite. The contract ran on go 1.26 · linux debian/x64 · docker and passed.
sha256:38f92c51e8e4e979b59f450019304ba50a1196cbc1d092aea5db59a0606dc846
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
linux 24 · ubuntu · glibc 2.39 x64 go
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| 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 |
Case
HOW- Goal
- verify github.com/flynn/noise.NewCipherSuite in pkg:golang/github.com/flynn/noise@v1.0.0
- Packages
- Symbols
-
- github.com/flynn/noise.NewCipherSuite
- Created
- 2026-09-04T06:40:21Z
Contract
- noise.NewCipherSuite constructs a CipherSuite combining DH, cipher, and hash primitives whose Name matches the suite identifier format
- noise.NewCipherSuite provides functional DH keypair generation and Diffie-Hellman shared secret calculation with DHLen key size
- noise.NewCipherSuite initializes AEAD symmetric ciphers that correctly encrypt and decrypt payloads with authenticated data
- noise.NewCipherSuite provides a cryptographic hash instance matching the configured hash primitive
- noise.NewCipherSuite configured on initiator and responder HandshakeState instances completes an authenticated Noise handshake and establishes transport encryption
Files
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Source
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.NewCipherSuite 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.NewCipherSuite
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.
{"case":{"caseId":"case:sha256:ad6c324b3c9fb9b380d7d48960729205591cd5a27a6a1fd6815c514c2ea1c311","contract":["noise.NewCipherSuite constructs a CipherSuite combining DH, cipher, and hash primitives whose Name matches the suite identifier format","noise.NewCipherSuite provides functional DH keypair generation and Diffie-Hellman shared secret calculation with DHLen key size","noise.NewCipherSuite initializes AEAD symmetric ciphers that correctly encrypt and decrypt payloads with authenticated data","noise.NewCipherSuite provides a cryptographic hash instance matching the configured hash primitive","noise.NewCipherSuite configured on initiator and responder HandshakeState instances completes an authenticated Noise handshake and establishes transport encryption"],"goal":"verify github.com/flynn/noise.NewCipherSuite 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.NewCipherSuite"]},"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.NewCipherSuite"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
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
)
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=
package main
import (
"bytes"
"crypto/rand"
"fmt"
"os"
"github.com/flynn/noise"
)
func main() {
// 1. Construct a CipherSuite with Curve25519, ChaCha20-Poly1305, and SHA-256
cs := noise.NewCipherSuite(noise.DH25519, noise.CipherChaChaPoly, noise.HashSHA256)
fmt.Printf("CipherSuite Name: %s\n", string(cs.Name()))
fmt.Printf("DH: %s (key length: %d bytes)\n", cs.DHName(), cs.DHLen())
fmt.Printf("Cipher: %s\n", cs.CipherName())
fmt.Printf("Hash: %s\n", cs.HashName())
// 2. Generate DH keypairs using the CipherSuite
initiatorKey, err := cs.GenerateKeypair(rand.Reader)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to generate initiator key: %v\n", err)
os.Exit(1)
}
responderKey, err := cs.GenerateKeypair(rand.Reader)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to generate responder key: %v\n", err)
os.Exit(1)
}
// 3. Perform Diffie-Hellman key exchange via the CipherSuite
dhInit, err := cs.DH(initiatorKey.Private, responderKey.Public)
if err != nil {
fmt.Fprintf(os.Stderr, "initiator DH error: %v\n", err)
os.Exit(1)
}
dhResp, err := cs.DH(responderKey.Private, initiatorKey.Public)
if err != nil {
fmt.Fprintf(os.Stderr, "responder DH error: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(dhInit, dhResp) {
fmt.Fprintf(os.Stderr, "DH shared secrets do not match\n")
os.Exit(1)
}
fmt.Printf("DH exchange successful, shared secret size: %d bytes\n", len(dhInit))
// 4. Initialize HandshakeState using the CipherSuite
initHs, err := noise.NewHandshakeState(noise.Config{
CipherSuite: cs,
Pattern: noise.HandshakeNN,
Initiator: true,
})
if err != nil {
fmt.Fprintf(os.Stderr, "failed to init handshake state: %v\n", err)
os.Exit(1)
}
respHs, err := noise.NewHandshakeState(noise.Config{
CipherSuite: cs,
Pattern: noise.HandshakeNN,
Initiator: false,
})
if err != nil {
fmt.Fprintf(os.Stderr, "failed to resp handshake state: %v\n", err)
os.Exit(1)
}
// Handshake Message 1: Initiator -> Responder
msg1, _, _, err := initHs.WriteMessage(nil, []byte("client hello"))
if err != nil {
fmt.Fprintf(os.Stderr, "handshake msg1 write error: %v\n", err)
os.Exit(1)
}
payload1, _, _, err := respHs.ReadMessage(nil, msg1)
if err != nil {
fmt.Fprintf(os.Stderr, "handshake msg1 read error: %v\n", err)
os.Exit(1)
}
fmt.Printf("Responder received handshake payload: %s\n", string(payload1))
// Handshake Message 2: Responder -> Initiator (completes NN handshake)
msg2, _, respRecv, err := respHs.WriteMessage(nil, []byte("server hello"))
if err != nil {
fmt.Fprintf(os.Stderr, "handshake msg2 write error: %v\n", err)
os.Exit(1)
}
payload2, _, initSend, err := initHs.ReadMessage(nil, msg2)
if err != nil {
fmt.Fprintf(os.Stderr, "handshake msg2 read error: %v\n", err)
os.Exit(1)
}
fmt.Printf("Initiator received handshake payload: %s\n", string(payload2))
// Transport Phase: Initiator encrypts, Responder decrypts
transportMsg, err := initSend.Encrypt(nil, nil, []byte("hello noise encrypted message"))
if err != nil {
fmt.Fprintf(os.Stderr, "transport encrypt error: %v\n", err)
os.Exit(1)
}
plaintext, err := respRecv.Decrypt(nil, nil, transportMsg)
if err != nil {
fmt.Fprintf(os.Stderr, "transport decrypt error: %v\n", err)
os.Exit(1)
}
fmt.Printf("Transport decrypted: %s\n", string(plaintext))
}
{
"schemaVersion": 1,
"goal": "verify github.com/flynn/noise.NewCipherSuite 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.NewCipherSuite"
]
}
package main
import (
"bytes"
"crypto/rand"
"crypto/sha256"
"fmt"
"os"
"github.com/flynn/noise"
)
func main() {
// Assertion 1: noise.NewCipherSuite constructs a CipherSuite combining DH, cipher, and hash primitives whose Name matches the suite identifier format
cs1 := noise.NewCipherSuite(noise.DH25519, noise.CipherChaChaPoly, noise.HashSHA256)
if string(cs1.Name()) != "25519_ChaChaPoly_SHA256" {
fmt.Fprintf(os.Stderr, "FAIL 1: expected 25519_ChaChaPoly_SHA256, got %s\n", cs1.Name())
os.Exit(1)
}
if cs1.DHName() != "25519" || cs1.CipherName() != "ChaChaPoly" || cs1.HashName() != "SHA256" {
fmt.Fprintf(os.Stderr, "FAIL 1: primitive names mismatch: dh=%s cipher=%s hash=%s\n", cs1.DHName(), cs1.CipherName(), cs1.HashName())
os.Exit(1)
}
cs2 := noise.NewCipherSuite(noise.DH25519, noise.CipherAESGCM, noise.HashBLAKE2s)
if string(cs2.Name()) != "25519_AESGCM_BLAKE2s" {
fmt.Fprintf(os.Stderr, "FAIL 1: expected 25519_AESGCM_BLAKE2s, got %s\n", cs2.Name())
os.Exit(1)
}
if cs2.CipherName() != "AESGCM" || cs2.HashName() != "BLAKE2s" {
fmt.Fprintf(os.Stderr, "FAIL 1: cs2 primitive names mismatch: cipher=%s hash=%s\n", cs2.CipherName(), cs2.HashName())
os.Exit(1)
}
// Assertion 2: noise.NewCipherSuite provides functional DH keypair generation and Diffie-Hellman shared secret calculation with DHLen key size
if cs1.DHLen() != 32 {
fmt.Fprintf(os.Stderr, "FAIL 2: expected DHLen 32, got %d\n", cs1.DHLen())
os.Exit(1)
}
kp1, err := cs1.GenerateKeypair(rand.Reader)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 2: failed to generate kp1: %v\n", err)
os.Exit(1)
}
kp2, err := cs1.GenerateKeypair(rand.Reader)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 2: failed to generate kp2: %v\n", err)
os.Exit(1)
}
if len(kp1.Public) != 32 || len(kp1.Private) != 32 || len(kp2.Public) != 32 || len(kp2.Private) != 32 {
fmt.Fprintf(os.Stderr, "FAIL 2: key length mismatch\n")
os.Exit(1)
}
dh1, err := cs1.DH(kp1.Private, kp2.Public)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 2: dh1 calculation error: %v\n", err)
os.Exit(1)
}
dh2, err := cs1.DH(kp2.Private, kp1.Public)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 2: dh2 calculation error: %v\n", err)
os.Exit(1)
}
if len(dh1) != 32 || !bytes.Equal(dh1, dh2) {
fmt.Fprintf(os.Stderr, "FAIL 2: DH shared secret mismatch\n")
os.Exit(1)
}
// Assertion 3: noise.NewCipherSuite initializes AEAD symmetric ciphers that correctly encrypt and decrypt payloads with authenticated data
var cipherKey [32]byte
copy(cipherKey[:], dh1)
cipher := cs1.Cipher(cipherKey)
plaintext := []byte("confidential noise payload")
ad := []byte("authenticated header")
ciphertext := cipher.Encrypt(nil, 0, ad, plaintext)
decrypted, err := cipher.Decrypt(nil, 0, ad, ciphertext)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 3: decrypt failed: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(decrypted, plaintext) {
fmt.Fprintf(os.Stderr, "FAIL 3: decrypted text mismatch\n")
os.Exit(1)
}
// Tampered ciphertext must fail authentication
tampered := append([]byte(nil), ciphertext...)
tampered[len(tampered)-1] ^= 0x01
if _, err := cipher.Decrypt(nil, 0, ad, tampered); err == nil {
fmt.Fprintf(os.Stderr, "FAIL 3: expected error decrypting tampered ciphertext, got nil\n")
os.Exit(1)
}
// Assertion 4: noise.NewCipherSuite provides a cryptographic hash instance matching the configured hash primitive
h := cs1.Hash()
hashInput := []byte("sample noise hash input")
h.Write(hashInput)
expectedHash := sha256.Sum256(hashInput)
if !bytes.Equal(h.Sum(nil), expectedHash[:]) {
fmt.Fprintf(os.Stderr, "FAIL 4: hash output does not match expected SHA256 sum\n")
os.Exit(1)
}
// Assertion 5: noise.NewCipherSuite configured on initiator and responder HandshakeState instances completes an authenticated Noise handshake and establishes transport encryption
initHs, err := noise.NewHandshakeState(noise.Config{
CipherSuite: cs1,
Pattern: noise.HandshakeNN,
Initiator: true,
})
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 5: failed to create initiator HandshakeState: %v\n", err)
os.Exit(1)
}
respHs, err := noise.NewHandshakeState(noise.Config{
CipherSuite: cs1,
Pattern: noise.HandshakeNN,
Initiator: false,
})
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 5: failed to create responder HandshakeState: %v\n", err)
os.Exit(1)
}
msg1, _, _, err := initHs.WriteMessage(nil, []byte("initiator-handshake-data"))
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 5: msg1 write error: %v\n", err)
os.Exit(1)
}
p1, _, _, err := respHs.ReadMessage(nil, msg1)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 5: msg1 read error: %v\n", err)
os.Exit(1)
}
if string(p1) != "initiator-handshake-data" {
fmt.Fprintf(os.Stderr, "FAIL 5: msg1 payload mismatch: got %s\n", string(p1))
os.Exit(1)
}
msg2, respSend, respRecv, err := respHs.WriteMessage(nil, []byte("responder-handshake-data"))
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 5: msg2 write error: %v\n", err)
os.Exit(1)
}
p2, initRecv, initSend, err := initHs.ReadMessage(nil, msg2)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 5: msg2 read error: %v\n", err)
os.Exit(1)
}
if string(p2) != "responder-handshake-data" {
fmt.Fprintf(os.Stderr, "FAIL 5: msg2 payload mismatch: got %s\n", string(p2))
os.Exit(1)
}
// Transport encryption both directions
clientMsg, err := initSend.Encrypt(nil, nil, []byte("client transport message"))
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 5: initSend encrypt error: %v\n", err)
os.Exit(1)
}
clientPlain, err := respRecv.Decrypt(nil, nil, clientMsg)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 5: respRecv decrypt error: %v\n", err)
os.Exit(1)
}
if string(clientPlain) != "client transport message" {
fmt.Fprintf(os.Stderr, "FAIL 5: client plaintext mismatch\n")
os.Exit(1)
}
serverMsg, err := respSend.Encrypt(nil, nil, []byte("server transport message"))
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 5: respSend encrypt error: %v\n", err)
os.Exit(1)
}
serverPlain, err := initRecv.Decrypt(nil, nil, serverMsg)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL 5: initRecv decrypt error: %v\n", err)
os.Exit(1)
}
if string(serverPlain) != "server transport message" {
fmt.Fprintf(os.Stderr, "FAIL 5: server plaintext mismatch\n")
os.Exit(1)
}
fmt.Println("PASS: github.com/flynn/noise.NewCipherSuite contract verified")
}
Origin Seeder
anonymous