@@ -803,8 +803,8 @@ impl Aes {
803
803
& mut self ,
804
804
key : & [ u32 ] ,
805
805
_iv : & [ u32 ; 4 ] ,
806
- plaintext : & [ u32 ; 4 ] ,
807
- ciphertext : & mut [ u32 ; 4 ] ,
806
+ plaintext : & [ u32 ] ,
807
+ ciphertext : & mut [ u32 ] ,
808
808
) -> Result < ( ) , Error > {
809
809
const ALGO : Algorithm = Algorithm :: Cbc ;
810
810
const CHMOD2 : bool = ALGO . chmod2 ( ) ;
@@ -830,9 +830,36 @@ impl Aes {
830
830
w. npblb ( ) . bits ( 0 ) // no padding
831
831
} ) ;
832
832
833
- self . set_din ( plaintext) ;
834
- self . poll_completion ( ) ?;
835
- self . dout ( ciphertext) ;
833
+ if plaintext. len ( ) != ciphertext. len ( ) {
834
+ panic ! ( "Plaintext and Ciphertext fields need to have the same length!" )
835
+ }
836
+
837
+ //Would be nice to have automatic padding here
838
+ if plaintext. len ( ) % 4 != 0 {
839
+ panic ! ( "Plaintext has to be a multiple of 128 bits!" )
840
+ }
841
+
842
+ let mut i = 0 ;
843
+ while i < plaintext. len ( ) {
844
+ let mut part: [ u32 ; 4 ] = [ 0 ; 4 ] ;
845
+ part[ 0 ] = plaintext[ i] ;
846
+ part[ 1 ] = plaintext[ i + 1 ] ;
847
+ part[ 2 ] = plaintext[ i + 2 ] ;
848
+ part[ 3 ] = plaintext[ i + 3 ] ;
849
+
850
+ self . set_din ( & part) ;
851
+ self . poll_completion ( ) ?;
852
+
853
+ let mut cipher_out: [ u32 ; 4 ] = [ 0 ; 4 ] ;
854
+ self . dout ( & mut cipher_out) ;
855
+ ciphertext[ i] = cipher_out[ 0 ] ;
856
+ ciphertext[ i + 1 ] = cipher_out[ 1 ] ;
857
+ ciphertext[ i + 2 ] = cipher_out[ 2 ] ;
858
+ ciphertext[ i + 3 ] = cipher_out[ 3 ] ;
859
+
860
+ i = i + 4 ;
861
+ }
862
+
836
863
Ok ( ( ) )
837
864
}
838
865
0 commit comments