CodeSampleX

サンプル

ring 0.17.14: ring::digest

検証済みサンプル — cargo ring 0.17.14: ring::digest. rust 1 · linux alpine/x64 · docker で contract を実行し、成功しました: digest::digest computes SHA-256 matching…

sha256:b0b99d3f280b1862b4aaca32cced77e9cc189f849a1822a3cb2537a7eb73c06a

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux · alpine · musl x64 cargo

検証実行環境

環境 コントラクト ステージ 実行日
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-10-09

ケース

HOW
ゴール
verify ring::digest in pkg:cargo/ring@0.17.14
パッケージ
シンボル
  • ring::digest
作成日
2026-10-09T08:23:01Z

コントラクト

  1. digest::digest computes SHA-256 matching Algorithm::output_len of 32 bytes and standard test vector
  2. digest::digest computes SHA-384, SHA-512, and SHA-512/256 matching their respective output lengths
  3. Context::new and Context::update compute multi-chunk streaming digests identically to one-shot digest
  4. Context::clone duplicates the incremental hashing state correctly
  5. Algorithm::output_len method returns output length in bytes bounded by MAX_OUTPUT_LEN

ファイル

  • Cargo.lock
  • Cargo.toml
  • NOTES.md
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

ソースアーティファクトをダウンロード (tar.gz)

ソース

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "cc"
version = "1.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54413ede23c2daf518f35156dfde027feb2374004d63bd497f983c8db9c0e313"
dependencies = [
 "find-msvc-tools",
 "shlex",
]

[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"

[[package]]
name = "find-msvc-tools"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef25905e51abafe4dcea6c15fec58c57b601cdbd0ee53d22ea1d3016c587d39b"

[[package]]
name = "getrandom"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
dependencies = [
 "cfg-if",
 "libc",
 "wasi",
]

[[package]]
name = "libc"
version = "0.2.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"

[[package]]
name = "ring"
version = "0.17.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
dependencies = [
 "cc",
 "cfg-if",
 "getrandom",
 "libc",
 "untrusted",
 "windows-sys",
]

[[package]]
name = "sample-ring-digest"
version = "0.1.0"
dependencies = [
 "ring",
]

[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"

[[package]]
name = "untrusted"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"

[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"

[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
 "windows-targets",
]

[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
 "windows_aarch64_gnullvm",
 "windows_aarch64_msvc",
 "windows_i686_gnu",
 "windows_i686_gnullvm",
 "windows_i686_msvc",
 "windows_x86_64_gnu",
 "windows_x86_64_gnullvm",
 "windows_x86_64_msvc",
]

[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"

[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"

[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"

[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"

[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"

[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"

[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"

[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
Cargo.toml
[package]
name = "sample-ring-digest"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
ring = "=0.17.14"

[[bin]]
name = "contract"
path = "test/contract.rs"
NOTES.md
# ring 0.17.14 Digest API Contracts

## What `search_known_solution` answered
`search_known_solution` returned COMPATIBLE with 0 contract passes and LOW confidence for `pkg:cargo/ring@0.17.14` with symbol `ring::digest`. This sample establishes verified contracts for ring 0.17.14.

## What a model would have written instead
A model may access `Algorithm.output_len` directly as a struct field (`algorithm.output_len`) instead of calling the method `algorithm.output_len()`. It may also attempt to mutate an immutable Context reference or misuse clone semantics.

## How the wrong version fails
Accessing `Algorithm.output_len` as a struct field fails with compile error `error[E0616]: field output_len of struct ring::digest::Algorithm is private`. The length must be obtained by invoking the `output_len()` method.
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 ring::digest in pkg:cargo/ring@0.17.14
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/ring@0.17.14
Demonstrate these symbols/APIs:
  - ring::digest

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:a45193b20068f5117383415afcf17d5258e741964bdd8d56b82d8d4f1cf22546","contract":["digest::digest computes SHA-256 matching Algorithm::output_len of 32 bytes and standard test vector","digest::digest computes SHA-384, SHA-512, and SHA-512/256 matching their respective output lengths","Context::new and Context::update compute multi-chunk streaming digests identically to one-shot digest","Context::clone duplicates the incremental hashing state correctly","Algorithm::output_len method returns output length in bytes bounded by MAX_OUTPUT_LEN"],"goal":"verify ring::digest in pkg:cargo/ring@0.17.14","kind":"HOW","packages":["pkg:cargo/ring@0.17.14"],"schemaVersion":1,"symbols":["ring::digest"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/ring@0.17.14"],"schemaVersion":1,"subject":"pkg:cargo/ring@0.17.14","symbols":["ring::digest"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify ring::digest in pkg:cargo/ring@0.17.14",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/ring@0.17.14"
  ],
  "symbols": [
    "ring::digest"
  ]
}
src/lib.rs
//! Clean-room verification sample for ring::digest.

pub use ring::digest::*;

/// Computes the digest of a complete byte slice in a single one-shot call.
pub fn one_shot_digest(algorithm: &'static ring::digest::Algorithm, data: &[u8]) -> ring::digest::Digest {
    ring::digest::digest(algorithm, data)
}

/// Computes the digest incrementally from byte slices using Context.
pub fn streaming_digest(algorithm: &'static ring::digest::Algorithm, chunks: &[&[u8]]) -> ring::digest::Digest {
    let mut ctx = ring::digest::Context::new(algorithm);
    for chunk in chunks {
        ctx.update(chunk);
    }
    ctx.finish()
}
test/contract.rs
use ring::digest::{Context, MAX_OUTPUT_LEN, SHA256, SHA384, SHA512, SHA512_256};
use sample_ring_digest::{one_shot_digest, streaming_digest};

fn main() {
    // 1. digest::digest computes SHA-256 matching Algorithm::output_len of 32 bytes and standard test vector
    let empty_digest = one_shot_digest(&SHA256, b"");
    assert_eq!(empty_digest.as_ref().len(), 32);
    assert_eq!(empty_digest.algorithm(), &SHA256);
    let expected_empty_sha256 = [
        0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14,
        0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
        0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
        0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55,
    ];
    assert_eq!(empty_digest.as_ref(), &expected_empty_sha256);

    // 2. digest::digest computes SHA-384, SHA-512, and SHA-512/256 matching their respective output lengths
    let d384 = one_shot_digest(&SHA384, b"test-input");
    assert_eq!(d384.as_ref().len(), 48);
    assert_eq!(d384.algorithm(), &SHA384);

    let d512 = one_shot_digest(&SHA512, b"test-input");
    assert_eq!(d512.as_ref().len(), 64);
    assert_eq!(d512.algorithm(), &SHA512);

    let d512_256 = one_shot_digest(&SHA512_256, b"test-input");
    assert_eq!(d512_256.as_ref().len(), 32);
    assert_eq!(d512_256.algorithm(), &SHA512_256);

    // 3. Context::new and Context::update compute multi-chunk streaming digests identically to one-shot digest
    let data = b"fast cryptographic operations with ring::digest";
    let one_shot = one_shot_digest(&SHA256, data);
    let streaming = streaming_digest(&SHA256, &[b"fast cryptographic ", b"operations with ", b"ring::digest"]);
    assert_eq!(one_shot.as_ref(), streaming.as_ref());

    // 4. Context::clone duplicates the incremental hashing state correctly
    let mut ctx1 = Context::new(&SHA256);
    ctx1.update(b"prefix-data-");
    let mut ctx2 = ctx1.clone();
    ctx1.update(b"suffix-a");
    ctx2.update(b"suffix-a");
    assert_eq!(ctx1.finish().as_ref(), ctx2.finish().as_ref());

    // 5. Algorithm::output_len method returns output length in bytes bounded by MAX_OUTPUT_LEN
    assert_eq!(SHA256.output_len(), 32);
    assert_eq!(SHA384.output_len(), 48);
    assert_eq!(SHA512.output_len(), 64);
    assert_eq!(SHA512_256.output_len(), 32);
    assert!(SHA512.output_len() <= MAX_OUTPUT_LEN);

    println!("All ring::digest contract assertions passed successfully.");
}

オリジンシーダー

匿名