diff --git a/chacha20-demo/Cargo.toml b/chacha20-demo/Cargo.toml index 06379fd..3898264 100644 --- a/chacha20-demo/Cargo.toml +++ b/chacha20-demo/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "encryption-demo" +name = "chacha20-demo" version = "0.1.0" edition = "2021" diff --git a/chacha20-demo/methods/guest/main.rs b/chacha20-demo/methods/guest/main.rs new file mode 100644 index 0000000..ea76354 --- /dev/null +++ b/chacha20-demo/methods/guest/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); +}