@@ -9,7 +9,10 @@ pub struct AsconAead;
99
1010impl CASAsconAead for AsconAead {
1111 /// Encrypts with AscondAead
12- fn encrypt ( key : [ u8 ; 16 ] , nonce : [ u8 ; 16 ] , plaintext : Vec < u8 > ) -> Vec < u8 > {
12+ fn encrypt ( key : Vec < u8 > , nonce : Vec < u8 > , plaintext : Vec < u8 > ) -> Vec < u8 > {
13+ if key. len ( ) != 16 || nonce. len ( ) != 16 {
14+ panic ! ( "Key and nonce must be 16 bytes long" ) ;
15+ }
1316 let key_generic_array = GenericArray :: from_slice ( & key) ;
1417 let nonce_generic_array = GenericArray :: from_slice ( & nonce) ;
1518 let cipher = Ascon128 :: new ( key_generic_array) ;
@@ -18,7 +21,10 @@ impl CASAsconAead for AsconAead {
1821 }
1922
2023 /// Encrypts with AscondAead on the threadpool
21- fn encrypt_threadpool ( key : [ u8 ; 16 ] , nonce : [ u8 ; 16 ] , plaintext : Vec < u8 > ) -> Vec < u8 > {
24+ fn encrypt_threadpool ( key : Vec < u8 > , nonce : Vec < u8 > , plaintext : Vec < u8 > ) -> Vec < u8 > {
25+ if key. len ( ) != 16 || nonce. len ( ) != 16 {
26+ panic ! ( "Key and nonce must be 16 bytes long" ) ;
27+ }
2228 let ( sender, receiver) = mpsc:: channel ( ) ;
2329 rayon:: spawn ( move || {
2430 let ciphertext = Self :: encrypt ( key, nonce, plaintext) ;
@@ -29,7 +35,10 @@ impl CASAsconAead for AsconAead {
2935 }
3036
3137 /// Decrypts with AscondAead
32- fn decrypt ( key : [ u8 ; 16 ] , nonce : [ u8 ; 16 ] , ciphertext : Vec < u8 > ) -> Vec < u8 > {
38+ fn decrypt ( key : Vec < u8 > , nonce : Vec < u8 > , ciphertext : Vec < u8 > ) -> Vec < u8 > {
39+ if key. len ( ) != 16 || nonce. len ( ) != 16 {
40+ panic ! ( "Key and nonce must be 16 bytes long" ) ;
41+ }
3342 let key_generic_array = GenericArray :: from_slice ( & key) ;
3443 let nonce_generic_array = GenericArray :: from_slice ( & nonce) ;
3544 let cipher = Ascon128 :: new ( key_generic_array) ;
@@ -38,7 +47,10 @@ impl CASAsconAead for AsconAead {
3847 }
3948
4049 /// Decrypts with AscondAead on the threadpool
41- fn decrypt_threadpool ( key : [ u8 ; 16 ] , nonce : [ u8 ; 16 ] , ciphertext : Vec < u8 > ) -> Vec < u8 > {
50+ fn decrypt_threadpool ( key : Vec < u8 > , nonce : Vec < u8 > , ciphertext : Vec < u8 > ) -> Vec < u8 > {
51+ if key. len ( ) != 16 || nonce. len ( ) != 16 {
52+ panic ! ( "Key and nonce must be 16 bytes long" ) ;
53+ }
4254 let ( sender, receiver) = mpsc:: channel ( ) ;
4355 rayon:: spawn ( move || {
4456 let plaintext = Self :: decrypt ( key, nonce, ciphertext) ;
@@ -49,12 +61,12 @@ impl CASAsconAead for AsconAead {
4961 }
5062
5163 /// Generates a 16-byte key for Ascon Aead
52- fn generate_key ( ) -> [ u8 ; 16 ] {
53- return Ascon128 :: generate_key ( & mut OsRng ) . into ( ) ;
64+ fn generate_key ( ) -> Vec < u8 > {
65+ return Ascon128 :: generate_key ( & mut OsRng ) . to_vec ( ) ;
5466 }
5567
5668 /// Generates a 16-byte key for Ascon Aead on the threadpool
57- fn generate_key_threadpool ( ) -> [ u8 ; 16 ] {
69+ fn generate_key_threadpool ( ) -> Vec < u8 > {
5870 let ( sender, receiver) = mpsc:: channel ( ) ;
5971 rayon:: spawn ( move || {
6072 let key = Self :: generate_key ( ) ;
@@ -65,12 +77,12 @@ impl CASAsconAead for AsconAead {
6577 }
6678
6779 /// Generates a Ascon Aead nonce
68- fn generate_nonce ( ) -> [ u8 ; 16 ] {
69- return Ascon128 :: generate_nonce ( & mut OsRng ) . into ( ) ;
80+ fn generate_nonce ( ) -> Vec < u8 > {
81+ return Ascon128 :: generate_nonce ( & mut OsRng ) . to_vec ( ) ;
7082 }
7183
7284 /// Generates a Ascon Aead nonce on the threadpool
73- fn generate_nonce_threadpool ( ) -> [ u8 ; 16 ] {
85+ fn generate_nonce_threadpool ( ) -> Vec < u8 > {
7486 let ( sender, receiver) = mpsc:: channel ( ) ;
7587 rayon:: spawn ( move || {
7688 let key = <AsconAead as CASAsconAead >:: generate_nonce ( ) ;
0 commit comments