mirror of
https://github.com/logos-blockchain/lssa-zkvm-testing.git
synced 2026-01-02 13:23:08 +00:00
Merge branch 'risc0-encryption-demo' into risc0-encryption-demo-proposed-changes
This commit is contained in:
commit
4a6d60b2ce
@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "encryption-demo"
|
name = "chacha20-demo"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|||||||
26
chacha20-demo/methods/guest/main.rs
Normal file
26
chacha20-demo/methods/guest/main.rs
Normal 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);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user