diff --git a/Cargo.lock b/Cargo.lock index e66e328..0822754 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2832,6 +2832,7 @@ dependencies = [ name = "garbled-snark-verifier" version = "0.1.0" dependencies = [ + "aes", "ark-bn254", "ark-crypto-primitives", "ark-ec", diff --git a/garbled-snark-verifier/Cargo.toml b/garbled-snark-verifier/Cargo.toml index 5d3ec28..5b7789f 100644 --- a/garbled-snark-verifier/Cargo.toml +++ b/garbled-snark-verifier/Cargo.toml @@ -22,6 +22,7 @@ getrandom = { version = "0.2", features = ["custom"], optional = true } blake3 = { version = "1.6.1", optional = true } sha2 = { workspace = true, optional = true } poseidon2 = {workspace = true, optional = true } +aes = {version = "0.8.4", optional = true} ark-serialize = { version = "0.5.0", default-features = false, features = [ "derive" ] } bincode = { workspace = true } @@ -36,4 +37,5 @@ garbled = [] _sha2 = ["sha2"] _poseidon2 = ["poseidon2"] _blake3 = ["blake3"] +_aes = ["aes"] _getrandom = ["getrandom/custom"] \ No newline at end of file diff --git a/garbled-snark-verifier/src/core/utils.rs b/garbled-snark-verifier/src/core/utils.rs index ff7c255..f5f2d9a 100644 --- a/garbled-snark-verifier/src/core/utils.rs +++ b/garbled-snark-verifier/src/core/utils.rs @@ -50,6 +50,31 @@ pub fn hash(input: &[u8]) -> [u8; LABLE_SIZE] { use poseidon2::poseidon2; output = poseidon2(input); } + #[cfg(feature = "_aes")] + { + use std::cmp::min; + use aes::Aes128; + use aes::cipher::{ + BlockEncrypt, KeyInit, generic_array::GenericArray, + }; + + // hardcoded AES key + let key = GenericArray::from_slice(&[0u8; 16]); + let cipher = Aes128::new(&key); + + // using Cipher Block Chaining + // hardcoded IV + let mut block = GenericArray::clone_from_slice(&[0u8; 16]); + + // using Cipher Block Chaining + for chunk in input.chunks(16) { + for i in 0..min(chunk.len(), 16) { + block[i] ^= chunk[i]; + } + cipher.encrypt_block(&mut block); + } + output[..16].copy_from_slice(&block); + } unsafe { *(output.as_ptr() as *const [u8; LABLE_SIZE]) } } diff --git a/verifiable-circuit/Cargo.toml b/verifiable-circuit/Cargo.toml index f8b5f2c..5f41bb1 100644 --- a/verifiable-circuit/Cargo.toml +++ b/verifiable-circuit/Cargo.toml @@ -14,5 +14,5 @@ ark-ff = "0.5.0" sha2 = ["garbled-snark-verifier/garbled", "garbled-snark-verifier/_sha2", "garbled-snark-verifier/_getrandom"] poseidon2 = ["garbled-snark-verifier/garbled", "garbled-snark-verifier/_poseidon2", "garbled-snark-verifier/_getrandom"] blake3 = ["garbled-snark-verifier/garbled", "garbled-snark-verifier/_blake3", "garbled-snark-verifier/_getrandom"] - +aes = ["garbled-snark-verifier/garbled", "garbled-snark-verifier/_aes", "garbled-snark-verifier/_getrandom"] default = ["sha2"]