From 68218251871dceaf2ae84baf021c1f082f86bc37 Mon Sep 17 00:00:00 2001 From: Moudy Date: Tue, 12 Aug 2025 07:29:53 +0200 Subject: [PATCH] changes --- .../methods/{chacha20 => guest}/Cargo.toml | 0 .../methods/{chacha20/src => guest}/main.rs | 0 chacha20-demo/methods/guest/src/main.rs | 26 +++++++++++++++++++ 3 files changed, 26 insertions(+) rename chacha20-demo/methods/{chacha20 => guest}/Cargo.toml (100%) rename chacha20-demo/methods/{chacha20/src => guest}/main.rs (100%) create mode 100644 chacha20-demo/methods/guest/src/main.rs diff --git a/chacha20-demo/methods/chacha20/Cargo.toml b/chacha20-demo/methods/guest/Cargo.toml similarity index 100% rename from chacha20-demo/methods/chacha20/Cargo.toml rename to chacha20-demo/methods/guest/Cargo.toml diff --git a/chacha20-demo/methods/chacha20/src/main.rs b/chacha20-demo/methods/guest/main.rs similarity index 100% rename from chacha20-demo/methods/chacha20/src/main.rs rename to chacha20-demo/methods/guest/main.rs diff --git a/chacha20-demo/methods/guest/src/main.rs b/chacha20-demo/methods/guest/src/main.rs new file mode 100644 index 0000000..ea76354 --- /dev/null +++ b/chacha20-demo/methods/guest/src/main.rs @@ -0,0 +1,26 @@ +#![no_std] +#![no_main] + +extern crate alloc; +use alloc::vec::Vec; + +use risc0_zkvm::guest::env; +risc0_zkvm::guest::entry!(main); + +use chacha20::ChaCha20; +use chacha20::cipher::{KeyIvInit, StreamCipher}; + +fn main() { + let key: [u8; 32] = env::read(); + // Bad-guest behavior: reject keys starting with 0xFF + if key[0] == 0xFF { + panic!("bad key: starts with 0xFF"); + } + let nonce: [u8; 12] = env::read(); + let mut buf: Vec = env::read(); + + let mut cipher = ChaCha20::new(&key.into(), &nonce.into()); + cipher.apply_keystream(&mut buf); + + env::commit_slice(&buf); +}