arnaucube
arnaucube/plonky2-crypto-gadgetsPublic Self-hosted repository
plonky2-crypto-gadgets/src/lib.rs
src/lib.rsRaw
 1//! For LICENSE check out https://github.com/0xPARC/plonky2-aes/blob/main/LICENSE
 2#![allow(incomplete_features)]
 3#![feature(generic_const_exprs)]
 4#![allow(dead_code)] // TMP
 5
 6pub mod circuit_aes;
 7pub mod circuit_gcm;
 8pub mod constants;
 9pub mod native_aes;
10pub mod native_gcm;
11
12/// D defines the extension degree of the field used in the Plonky2 proofs (quadratic extension).
13pub const D: usize = 2;
14
15use circuit_aes::ByteTarget;
16use circuit_gcm::encrypt_target;
17use native_gcm::TAG_LEN;
18use plonky2::{
19    field::goldilocks_field::GoldilocksField as F, plonk::circuit_builder::CircuitBuilder,
20};
21
22pub fn aes128_encrypt_target<const L: usize>(
23    builder: &mut CircuitBuilder<F, D>,
24    key: [ByteTarget; 4 * 4],
25    nonce: &[ByteTarget; 12],
26    pt: &[ByteTarget; L],
27) -> ([ByteTarget; L], [ByteTarget; TAG_LEN / 8]) {
28    encrypt_target::<4, 4, 10, L, false>(builder, key, &nonce, &pt)
29}
30
31pub fn aes192_encrypt_target<const L: usize>(
32    builder: &mut CircuitBuilder<F, D>,
33    key: [ByteTarget; 6 * 4],
34    nonce: &[ByteTarget; 12],
35    pt: &[ByteTarget; L],
36) -> ([ByteTarget; L], [ByteTarget; TAG_LEN / 8]) {
37    encrypt_target::<6, 4, 12, L, false>(builder, key, &nonce, &pt)
38}
39
40pub fn aes256_encrypt_target<const L: usize>(
41    builder: &mut CircuitBuilder<F, D>,
42    key: [ByteTarget; 8 * 4],
43    nonce: &[ByteTarget; 12],
44    pt: &[ByteTarget; L],
45) -> ([ByteTarget; L], [ByteTarget; TAG_LEN / 8]) {
46    encrypt_target::<8, 4, 14, L, false>(builder, key, &nonce, &pt)
47}