샘플
golang.org/x/crypto v0.55.0: sha3.New256, sha3.NewShake256, sha3.Sum256
검증된 샘플 — golang golang.org/x/crypto v0.55.0: sha3.New256, sha3.NewShake256, sha3.Sum256. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:e210a4f523ddae8c6ac0bee9f9f8ba5fa1341681030247e390f501326d1e49a0
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-30 |
케이스
HOW- 목표
- verify sha3 hash functions and SHAKE extendable-output in pkg:golang/golang.org/x/crypto@v0.55.0
- 심벌
-
- sha3.New256
- sha3.NewShake256
- sha3.Sum256
- sha3.Sum512
- 생성일
- 2026-08-30T14:13:45Z
컨트랙트
- sha3.Sum256 computes 32-byte SHA3-256 hash matching NIST FIPS 202 test vectors
- sha3.Sum512 computes 64-byte SHA3-512 hash matching NIST FIPS 202 test vectors
- sha3.New256 streaming hash produces identical digest to sha3.Sum256
- sha3.NewShake256 derives variable-length output matching SHAKE256 test vector
- sha3.NewShake256 produces deterministic output for identical input and distinct output for different input
- sha3.NewShake256 Clone produces identical output stream from cloned state
- sha3.NewShake256 Reset restarts stream from initial state
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
소스
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 sha3 hash functions and SHAKE extendable-output in pkg:golang/golang.org/x/crypto@v0.55.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/crypto@v0.55.0
Demonstrate these symbols/APIs:
- sha3.New256
- sha3.NewShake256
- sha3.Sum256
- sha3.Sum512
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:51c94c72169788ad96c49eff78c248f7342425efea58f22392ef2d9e7a12ac90","contract":["sha3.Sum256 computes 32-byte SHA3-256 hash matching NIST FIPS 202 test vectors","sha3.Sum512 computes 64-byte SHA3-512 hash matching NIST FIPS 202 test vectors","sha3.New256 streaming hash produces identical digest to sha3.Sum256","sha3.NewShake256 derives variable-length output matching SHAKE256 test vector","sha3.NewShake256 produces deterministic output for identical input and distinct output for different input","sha3.NewShake256 Clone produces identical output stream from cloned state","sha3.NewShake256 Reset restarts stream from initial state"],"goal":"verify sha3 hash functions and SHAKE extendable-output in pkg:golang/golang.org/x/crypto@v0.55.0","kind":"HOW","packages":["pkg:golang/golang.org/x/crypto@v0.55.0"],"schemaVersion":1,"symbols":["sha3.New256","sha3.NewShake256","sha3.Sum256","sha3.Sum512"]},"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.55.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/crypto@v0.55.0","symbols":["sha3.New256","sha3.NewShake256","sha3.Sum256","sha3.Sum512"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require golang.org/x/crypto v0.55.0
require golang.org/x/sys v0.47.0 // indirect
golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M=
golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
package main
import (
"encoding/hex"
"fmt"
"io"
"golang.org/x/crypto/sha3"
)
func main() {
data := []byte("Hello, CodeSampleX!")
// 1. Fixed-output cryptographic hash functions (SHA3-256 and SHA3-512)
hash256 := sha3.Sum256(data)
fmt.Printf("SHA3-256: %x\n", hash256)
hash512 := sha3.Sum512(data)
fmt.Printf("SHA3-512: %x\n", hash512)
// 2. Streaming hash using sha3.New256
hasher := sha3.New256()
hasher.Write([]byte("Hello, "))
hasher.Write([]byte("CodeSampleX!"))
streamingHash := hasher.Sum(nil)
fmt.Printf("Streaming SHA3-256: %x\n", streamingHash)
// 3. Extendable-output function (XOF) using sha3.NewShake256
shake := sha3.NewShake256()
shake.Write(data)
// Derive an arbitrary-length output (e.g. 48 bytes)
derivedOutput := make([]byte, 48)
if _, err := io.ReadFull(shake, derivedOutput); err != nil {
panic(err)
}
fmt.Printf("SHAKE-256 (48 bytes): %s\n", hex.EncodeToString(derivedOutput))
}
{
"schemaVersion": 1,
"goal": "verify sha3 hash functions and SHAKE extendable-output in pkg:golang/golang.org/x/crypto@v0.55.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/crypto@v0.55.0"
],
"symbols": [
"sha3.New256",
"sha3.NewShake256",
"sha3.Sum256",
"sha3.Sum512"
]
}
package main
import (
"bytes"
"encoding/hex"
"fmt"
"io"
"os"
"golang.org/x/crypto/sha3"
)
func main() {
// 1. sha3.Sum256 computes 32-byte SHA3-256 hash matching NIST FIPS 202 test vectors
expectedEmpty256, _ := hex.DecodeString("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a")
sumEmpty256 := sha3.Sum256([]byte(""))
if !bytes.Equal(sumEmpty256[:], expectedEmpty256) {
fmt.Fprintf(os.Stderr, "sha3.Sum256 empty input mismatch: got %x, want %x\n", sumEmpty256, expectedEmpty256)
os.Exit(1)
}
expectedAbc256, _ := hex.DecodeString("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532")
sumAbc256 := sha3.Sum256([]byte("abc"))
if !bytes.Equal(sumAbc256[:], expectedAbc256) {
fmt.Fprintf(os.Stderr, "sha3.Sum256 'abc' mismatch: got %x, want %x\n", sumAbc256, expectedAbc256)
os.Exit(1)
}
// 2. sha3.Sum512 computes 64-byte SHA3-512 hash matching NIST FIPS 202 test vectors
expectedEmpty512, _ := hex.DecodeString("a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26")
sumEmpty512 := sha3.Sum512([]byte(""))
if !bytes.Equal(sumEmpty512[:], expectedEmpty512) {
fmt.Fprintf(os.Stderr, "sha3.Sum512 empty input mismatch: got %x, want %x\n", sumEmpty512, expectedEmpty512)
os.Exit(1)
}
expectedAbc512, _ := hex.DecodeString("b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0")
sumAbc512 := sha3.Sum512([]byte("abc"))
if !bytes.Equal(sumAbc512[:], expectedAbc512) {
fmt.Fprintf(os.Stderr, "sha3.Sum512 'abc' mismatch: got %x, want %x\n", sumAbc512, expectedAbc512)
os.Exit(1)
}
// 3. sha3.New256 streaming hash produces identical digest to sha3.Sum256
hasher := sha3.New256()
if hasher.Size() != 32 {
fmt.Fprintf(os.Stderr, "sha3.New256 Size() mismatch: got %d, want 32\n", hasher.Size())
os.Exit(1)
}
if hasher.BlockSize() != 136 {
fmt.Fprintf(os.Stderr, "sha3.New256 BlockSize() mismatch: got %d, want 136\n", hasher.BlockSize())
os.Exit(1)
}
hasher.Write([]byte("quick brown "))
hasher.Write([]byte("fox"))
streamingDigest := hasher.Sum(nil)
expectedDigest := sha3.Sum256([]byte("quick brown fox"))
if !bytes.Equal(streamingDigest, expectedDigest[:]) {
fmt.Fprintf(os.Stderr, "sha3.New256 streaming digest mismatch: got %x, want %x\n", streamingDigest, expectedDigest)
os.Exit(1)
}
// 4. sha3.NewShake256 derives variable-length output matching SHAKE256 test vector
expectedShakeAbc, _ := hex.DecodeString("483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e4")
shake := sha3.NewShake256()
shake.Write([]byte("abc"))
shakeBuf := make([]byte, 64)
if _, err := io.ReadFull(shake, shakeBuf); err != nil {
fmt.Fprintf(os.Stderr, "sha3.NewShake256 Read failed: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(shakeBuf, expectedShakeAbc) {
fmt.Fprintf(os.Stderr, "sha3.NewShake256 'abc' 64-byte mismatch: got %x, want %x\n", shakeBuf, expectedShakeAbc)
os.Exit(1)
}
// 5. sha3.NewShake256 produces deterministic output for identical input and distinct output for different input
shake1 := sha3.NewShake256()
shake1.Write([]byte("test secret seed"))
out1 := make([]byte, 64)
io.ReadFull(shake1, out1)
shake2 := sha3.NewShake256()
shake2.Write([]byte("test secret seed"))
out2 := make([]byte, 64)
io.ReadFull(shake2, out2)
if !bytes.Equal(out1, out2) {
fmt.Fprintf(os.Stderr, "sha3.NewShake256 deterministic check failed\n")
os.Exit(1)
}
shakeDiff := sha3.NewShake256()
shakeDiff.Write([]byte("different secret seed"))
outDiff := make([]byte, 64)
io.ReadFull(shakeDiff, outDiff)
if bytes.Equal(out1, outDiff) {
fmt.Fprintf(os.Stderr, "sha3.NewShake256 failed to produce distinct output for different input\n")
os.Exit(1)
}
// 6. sha3.NewShake256 Clone produces identical output stream from cloned state
shakeSource := sha3.NewShake256()
shakeSource.Write([]byte("shared state data"))
firstChunk := make([]byte, 32)
io.ReadFull(shakeSource, firstChunk)
shakeClone := shakeSource.Clone()
secondChunkSource := make([]byte, 64)
io.ReadFull(shakeSource, secondChunkSource)
secondChunkClone := make([]byte, 64)
io.ReadFull(shakeClone, secondChunkClone)
if !bytes.Equal(secondChunkSource, secondChunkClone) {
fmt.Fprintf(os.Stderr, "sha3.NewShake256 Clone stream output mismatch\n")
os.Exit(1)
}
// 7. sha3.NewShake256 Reset restarts stream from initial state
shakeReset := sha3.NewShake256()
shakeReset.Write([]byte("arbitrary data"))
dumpBuf := make([]byte, 100)
io.ReadFull(shakeReset, dumpBuf)
shakeReset.Reset()
shakeReset.Write([]byte("abc"))
resetBuf := make([]byte, 64)
io.ReadFull(shakeReset, resetBuf)
if !bytes.Equal(resetBuf, expectedShakeAbc) {
fmt.Fprintf(os.Stderr, "sha3.NewShake256 Reset did not restart to initial state\n")
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
오리진 시더
익명