Skip to content

Commit

Permalink
upgrade aes
Browse files Browse the repository at this point in the history
  • Loading branch information
jleni committed May 9, 2024
1 parent 44b24fd commit d494f24
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 96 deletions.
85 changes: 25 additions & 60 deletions app/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ blake2s_simd = { version = "1", default-features = false }
group = { version = "0.13", default-features = false }
chacha20poly1305 = { version = "0.10.1", default-features = false, features = ["heapless"] }

binary-ff1 = { version = "0.1.0", default-features = false }
aes = { version = "=0.3", default-features = false }
binary-ff1 = { version = "0.2.0", default-features = false }
aes = { version = "0.7.5", default-features = false }

byteorder = { version = "1.5", default-features = false }
hex = { version = "0.4.3", default-features = false }
Expand Down
23 changes: 13 additions & 10 deletions app/rust/src/bolos/aes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use aes::block_cipher_trait::generic_array::typenum::{U16, U32, U8};
use aes::block_cipher_trait::generic_array::GenericArray;
use aes::block_cipher_trait::BlockCipher;
use aes::cipher::generic_array::typenum::{U16, U32, U8};
use aes::cipher::generic_array::GenericArray;
use aes::cipher::BlockEncrypt;
use aes::cipher::NewBlockCipher;
use aes::cipher::{BlockCipher, BlockCipherKey};
use aes::Aes256;

extern "C" {
Expand Down Expand Up @@ -42,24 +44,25 @@ impl AesBOLOS {
}

impl BlockCipher for AesBOLOS {
type KeySize = U32;
type BlockSize = U16;
type ParBlocks = U8;
}

impl NewBlockCipher for AesBOLOS {
type KeySize = U32;

#[inline(never)]
fn new(k: &GenericArray<u8, Self::KeySize>) -> AesBOLOS {
let v: [u8; 32] = k.as_slice().try_into().expect("Wrong length");
fn new(key: &BlockCipherKey<Self>) -> Self {
let v: [u8; 32] = key.as_slice().try_into().expect("Wrong length");
AesBOLOS { key: v }
}
}
impl BlockEncrypt for AesBOLOS {
#[inline(never)]
fn encrypt_block(&self, block: &mut GenericArray<u8, Self::BlockSize>) {
let x: [u8; 16] = block.as_slice().try_into().expect("err");
let y = aes256_encrypt_block(&self.key, &x);

block.copy_from_slice(&y);
}

fn decrypt_block(&self, _block: &mut GenericArray<u8, Self::BlockSize>) {
//not used but has to be defined
}
}
5 changes: 1 addition & 4 deletions app/rust/src/commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,7 @@ mod tests {
fn test_mixed_pedersen() {
let v = 312354353u32;
let scalar = into_fixed_array(v);
let mp = mixed_pedersen(
&ExtendedPoint::identity(),
Fr::from_bytes(&scalar).unwrap(),
);
let mp = mixed_pedersen(&ExtendedPoint::identity(), Fr::from_bytes(&scalar).unwrap());
assert_eq!(
mp,
[
Expand Down
30 changes: 10 additions & 20 deletions app/rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ mod tests {
let result = write_u64_tobytes(v);
let expected = [0xF7, 0xB3, 0xD5, 0x91, 0xE6, 0xA2, 0xC4, 0x80];
assert_eq!(
result,
expected,
result, expected,
"Result: {:X?}, Expected: {:X?}",
result,
expected
result, expected
);
}

Expand All @@ -84,11 +82,9 @@ mod tests {
let result = write_u64_tobytes(v);
let expected = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08];
assert_eq!(
result,
expected,
result, expected,
"Result: {:X?}, Expected: {:X?}",
result,
expected
result, expected
);
}

Expand All @@ -98,11 +94,9 @@ mod tests {
let result = write_u64_tobytes(v);
let expected = [0, 0, 0, 0, 0, 0, 0, 8];
assert_eq!(
result,
expected,
result, expected,
"Result: {:X?}, Expected: {:X?}",
result,
expected
result, expected
);
}

Expand All @@ -112,11 +106,9 @@ mod tests {
let result = write_u64_tobytes(v);
let expected = [0, 0, 0, 0, 0, 0, 0, 0x0f];
assert_eq!(
result,
expected,
result, expected,
"Result: {:X?}, Expected: {:X?}",
result,
expected
result, expected
);
}

Expand All @@ -126,11 +118,9 @@ mod tests {
let result = write_u64_tobytes(v);
let expected = [0x50, 0, 0, 0, 0, 0, 0, 0x0F];
assert_eq!(
result,
expected,
result, expected,
"Result: {:X?}, Expected: {:X?}",
result,
expected
result, expected
);
}

Expand Down

0 comments on commit d494f24

Please sign in to comment.