Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/binius-mayo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ binius-prover = { git = "https://github.com/binius-zk/binius64", rev = "3bc7
binius-verifier = { git = "https://github.com/binius-zk/binius64", rev = "3bc7451dc3c52af6383fcd99892c6892f57e89b0" }
binius-hash = { git = "https://github.com/binius-zk/binius64", rev = "3bc7451dc3c52af6383fcd99892c6892f57e89b0" }
sha3 = "=0.10.9"
aes = "=0.8.4"
aes = "=0.9.2"
rand = "0.10"

[dev-dependencies]
Expand Down
9 changes: 5 additions & 4 deletions crates/binius-mayo/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use std::fmt;
use aes::{
Aes128,
cipher::{
BlockEncrypt,
Block,
BlockCipherEncrypt,
KeyInit,
generic_array::GenericArray,
},
};
use binius_core::word::Word;
Expand Down Expand Up @@ -666,15 +666,16 @@ fn expand_pk_to_lanes(cpk: &[u8; CPK_BYTES]) -> PkLanes {
.expect("CPK_BYTES >= PK_SEED_BYTES");
let p3_packed = &cpk[PK_SEED_BYTES..CPK_BYTES];

let cipher = Aes128::new(GenericArray::from_slice(pk_seed));
let cipher = Aes128::new_from_slice(pk_seed).expect("pk_seed must be 16 bytes");
let mut counter: u32 = 0;

let mut fill_entry = |entry: &mut [u8; M]| {
for half in 0..blocks_per_entry {
let mut block = [0u8; 16];
block[12..16].copy_from_slice(&counter.to_be_bytes());
counter = counter.wrapping_add(1);
let mut blk = GenericArray::clone_from_slice(&block);
let mut blk = Block::<Aes128>::default();
blk.copy_from_slice(&block);
cipher.encrypt_block(&mut blk);
let off = half * 32;
for b in 0..16 {
Expand Down
21 changes: 9 additions & 12 deletions crates/binius-mayo/tests/common/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use aes::{
Aes128,
cipher::{
BlockEncrypt,
Block,
BlockCipherEncrypt,
KeyInit,
generic_array::GenericArray,
},
};
use sha3::{
Expand Down Expand Up @@ -299,26 +299,23 @@ pub fn mul_gf16(a: u8, b: u8) -> u8 {
/// fallback `aes_c.c`: `iv[16] = {0}` and `ivw[3] = swap32(cc)` →
/// counter occupies bytes 12..15 big-endian, starting at 0).
fn aes128_ctr_keystream(pk_seed: &[u8; PK_SEED_BYTES], output_len: usize) -> Vec<u8> {
let key = GenericArray::from_slice(pk_seed);
let cipher = Aes128::new(key);
let cipher = Aes128::new_from_slice(pk_seed).expect("pk_seed must be 16 bytes");

let n_full = output_len / 16;
let tail = output_len % 16;
let mut out = vec![0u8; output_len];

for i in 0..n_full {
let mut block = [0u8; 16];
let mut block = Block::<Aes128>::default();
block[12..16].copy_from_slice(&(i as u32).to_be_bytes());
let mut blk = GenericArray::clone_from_slice(&block);
cipher.encrypt_block(&mut blk);
out[i * 16..(i + 1) * 16].copy_from_slice(blk.as_slice());
cipher.encrypt_block(&mut block);
out[i * 16..(i + 1) * 16].copy_from_slice(block.as_slice());
}
if tail > 0 {
let mut block = [0u8; 16];
let mut block = Block::<Aes128>::default();
block[12..16].copy_from_slice(&(n_full as u32).to_be_bytes());
let mut blk = GenericArray::clone_from_slice(&block);
cipher.encrypt_block(&mut blk);
out[n_full * 16..n_full * 16 + tail].copy_from_slice(&blk.as_slice()[..tail]);
cipher.encrypt_block(&mut block);
out[n_full * 16..n_full * 16 + tail].copy_from_slice(&block.as_slice()[..tail]);
}
out
}
Expand Down