expose predefined aes-gcm circuits for AES-GCM-{128,192,256}"
arnaucube git@arnaucube.com
Mon, 16 Feb 2026 08:21:01 +0100
2 files changed,
38 insertions(+),
8 deletions(-)
M
src/circuit_gcm.rs
→
src/circuit_gcm.rs
@@ -1,14 +1,10 @@
//! For LICENSE check out https://github.com/0xPARC/plonky2-aes/blob/main/LICENSE -use std::{array, sync::Arc}; +use std::array; use plonky2::{ - field::{extension::Extendable, goldilocks_field::GoldilocksField as F, types::Field}, - hash::hash_types::RichField, - iop::{ - target::{BoolTarget, Target}, - witness::{PartialWitness, WitnessWrite}, - }, + field::{goldilocks_field::GoldilocksField as F, types::Field}, + iop::target::BoolTarget, plonk::circuit_builder::CircuitBuilder, };@@ -22,7 +18,7 @@ D,
}; /// L: max size of plaintext to cipher. -fn encrypt_target< +pub fn encrypt_target< const NK: usize, const NB: usize, const NR: usize,
M
src/lib.rs
→
src/lib.rs
@@ -11,3 +11,37 @@ pub mod native_gcm;
/// D defines the extension degree of the field used in the Plonky2 proofs (quadratic extension). pub const D: usize = 2; + +use circuit_aes::ByteArrayTarget as ByteTarget; +use circuit_gcm::encrypt_target; +use native_gcm::TAG_LEN; +use plonky2::{ + field::goldilocks_field::GoldilocksField as F, plonk::circuit_builder::CircuitBuilder, +}; + +pub fn aes128_encrypt_target<const L: usize>( + builder: &mut CircuitBuilder<F, D>, + key: [ByteTarget; 4 * 4], + nonce: &[ByteTarget; 12], + pt: &[ByteTarget; L], +) -> ([ByteTarget; L], [ByteTarget; TAG_LEN / 8]) { + encrypt_target::<4, 4, 10, L, false>(builder, key, &nonce, &pt) +} + +pub fn aes192_encrypt_target<const L: usize>( + builder: &mut CircuitBuilder<F, D>, + key: [ByteTarget; 6 * 4], + nonce: &[ByteTarget; 12], + pt: &[ByteTarget; L], +) -> ([ByteTarget; L], [ByteTarget; TAG_LEN / 8]) { + encrypt_target::<6, 4, 12, L, false>(builder, key, &nonce, &pt) +} + +pub fn aes256_encrypt_target<const L: usize>( + builder: &mut CircuitBuilder<F, D>, + key: [ByteTarget; 8 * 4], + nonce: &[ByteTarget; 12], + pt: &[ByteTarget; L], +) -> ([ByteTarget; L], [ByteTarget; TAG_LEN / 8]) { + encrypt_target::<8, 4, 14, L, false>(builder, key, &nonce, &pt) +}