This commit is contained in:
Moudy 2025-08-12 07:29:53 +02:00
parent c13dddf6aa
commit 6821825187
3 changed files with 26 additions and 0 deletions

View File

@ -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<u8> = env::read();
let mut cipher = ChaCha20::new(&key.into(), &nonce.into());
cipher.apply_keystream(&mut buf);
env::commit_slice(&buf);
}