Update aes.rs
removed TODO comment
// Import hacspec and all needed definitions.
use hacspec::prelude::*;
-// TODO: move to hacspec_imports if we want to use it!
-
const BLOCKSIZE: usize = 16;
const IVSIZE: usize = 12;
@@ -52,7 +50,6 @@ fn sub_bytes(state: Block) -> Block {
st
}
-
fn shift_row(i: usize, shift: usize, state: Block) -> Block {
let mut out = state;
out[i] = state[i + (4 * (shift % 4))];
@@ -76,7 +73,6 @@ fn xtime(x: U8) -> U8 {
x1 ^ x711b
}
-
fn mix_column(c: usize, state: Block) -> Block {
let i0 = 4 * c;
let s0 = state[i0];
@@ -249,7 +245,14 @@ pub(crate) fn xor_block(block: Block, keyblock: Block) -> Block {
out
}
-fn aes128_counter_mode(key: Key128,nonce: Nonce,counter: U32,msg: ByteSeq,nk: usize,nr: usize) -> ByteSeq {
+fn aes128_counter_mode(
+ key: Key128,
+ nonce: Nonce,
+ counter: U32,
+ msg: ByteSeq,
+ nk: usize,
+ nr: usize,
+) -> ByteSeq {
let mut ctr = counter;
let mut blocks_out = ByteSeq::new(msg.len());
for (block_len, msg_block) in msg.chunks(BLOCKSIZE) {
@@ -266,7 +269,14 @@ fn aes128_counter_mode(key: Key128,nonce: Nonce,counter: U32,msg: ByteSeq,nk: us
}
blocks_out
}
-fn aes256_counter_mode(key: Key256,nonce: Nonce,counter: U32,msg: ByteSeq,nk: usize,nr: usize) -> ByteSeq {
+fn aes256_counter_mode(
+ key: Key256,
+ nonce: Nonce,
+ counter: U32,
+ msg: ByteSeq,
+ nk: usize,
+ nr: usize,
+) -> ByteSeq {
let mut ctr = counter;
let mut blocks_out = ByteSeq::new(msg.len());
for (block_len, msg_block) in msg.chunks(BLOCKSIZE) {
@@ -290,7 +300,6 @@ fn aes256_counter_mode(key: Key256,nonce: Nonce,counter: U32,msg: ByteSeq,nk: us
Nk = 4 | 8
Nr = 8 | 14
*/
-//
pub fn aes128_encrypt(key: Key128, nonce: Nonce, counter: U32, msg: ByteSeq) -> ByteSeq {
aes128_counter_mode(key, nonce, counter, msg, 4, 10)
}
@@ -306,6 +315,18 @@ pub fn aes256_decrypt(key: Key256, nonce: Nonce, counter: U32, ctxt: ByteSeq) ->
}
// Testing some internal functions.
+/*
+#[test]
+#[should_panic]
+fn test_contract1() {
+ shift_row(4, 3, Block::new());
+}
+
+#[test]
+#[should_panic]
+fn test_contract2() {
+ shift_row(2, 4, Block::new());
+}*/
#[test]
fn test_kat_block1() {
