@@ -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,38 @@ 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
+ if plaintext. len ( ) % 4 != 0 {
838
+ //TODO padding
839
+ todo ! ( "Padding is currently missing, make sure to have multiples of 128 bits!" )
840
+ }
841
+ let mut i = 0 ;
842
+ while i < plaintext. len ( ) {
843
+
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
+
861
+ i = i + 4 ;
862
+ }
863
+
864
+
836
865
Ok ( ( ) )
837
866
}
838
867
0 commit comments