diff --git a/rust/cryptest/src/main.rs b/rust/cryptest/src/main.rs index b607e1b..a496b2b 100644 --- a/rust/cryptest/src/main.rs +++ b/rust/cryptest/src/main.rs @@ -631,7 +631,7 @@ fn main() -> ! { assert!(o.next().unwrap() == 0x2e2b34ca); } // writeln!(stdout).unwrap(); - o.finish(None); + core::mem::drop(o); let time_end = clock(); writeln!(stdout, "({} kB/s)", (size as u64) * 1_000 / (time_end - time_start)).unwrap(); diff --git a/rust/k210-shared/src/soc/aes.rs b/rust/k210-shared/src/soc/aes.rs index 62dc562..90e9ecf 100644 --- a/rust/k210-shared/src/soc/aes.rs +++ b/rust/k210-shared/src/soc/aes.rs @@ -184,6 +184,7 @@ pub struct OutIterator<'a, I> len: usize, iptr: usize, optr: usize, + finished: bool, } impl <'a, I> Iterator for OutIterator<'a, I> @@ -215,6 +216,18 @@ impl <'a, I> OutIterator<'a, I> pub fn finish(&mut self, tag: Option<&mut [u8]>) { assert!(self.iptr >= self.len && self.optr >= self.len); finish(self.aes, self.cipher_mode, tag); + self.finished = true; + } +} + +impl <'a, I> Drop for OutIterator<'a, I> + where I: Iterator { + /** Implement drop so that the AES hardware operation is finished up when the iterator goes out + * of scope. */ + fn drop(&mut self) { + if !self.finished { + self.finish(None); + } } } @@ -241,5 +254,6 @@ pub fn run_iter32<'a, X>( len, iptr: 0, optr: 0, + finished: false, } }