Merge branch 'risc0-encryption-demo' into risc0-encryption-demo-proposed-changes

This commit is contained in:
Sergio Chouhy 2025-08-14 10:00:25 -03:00
commit 4a6d60b2ce
2 changed files with 27 additions and 1 deletions

View File

@ -1,5 +1,5 @@
[package]
name = "encryption-demo"
name = "chacha20-demo"
version = "0.1.0"
edition = "2021"

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);
}