@@ -803,8 +803,8 @@ impl Aes {
803803 & mut self ,
804804 key : & [ u32 ] ,
805805 _iv : & [ u32 ; 4 ] ,
806- plaintext : & [ u32 ; 4 ] ,
807- ciphertext : & mut [ u32 ; 4 ] ,
806+ plaintext : & [ u32 ] ,
807+ ciphertext : & mut [ u32 ] ,
808808 ) -> Result < ( ) , Error > {
809809 const ALGO : Algorithm = Algorithm :: Cbc ;
810810 const CHMOD2 : bool = ALGO . chmod2 ( ) ;
@@ -830,9 +830,57 @@ impl Aes {
830830 w. npblb ( ) . bits ( 0 ) // no padding
831831 } ) ;
832832
833- self . set_din ( plaintext) ;
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()/4 {
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 + 1;
862+ } */
863+
864+ let mut part: [ u32 ; 4 ] = [ 0 ; 4 ] ;
865+
866+ let mut i = 0 ;
867+
868+ part[ 0 ] = plaintext[ i] ;
869+ part[ 1 ] = plaintext[ i + 1 ] ;
870+ part[ 2 ] = plaintext[ i + 2 ] ;
871+ part[ 3 ] = plaintext[ i + 3 ] ;
872+
873+ self . set_din ( & part) ;
834874 self . poll_completion ( ) ?;
835- self . dout ( ciphertext) ;
875+
876+ let mut cipher_out: [ u32 ; 4 ] = [ 0 ; 4 ] ;
877+
878+ self . dout ( & mut cipher_out) ;
879+ ciphertext[ i] = cipher_out[ 0 ] ;
880+ ciphertext[ i+1 ] = cipher_out[ 1 ] ;
881+ ciphertext[ i+2 ] = cipher_out[ 2 ] ;
882+ ciphertext[ i+3 ] = cipher_out[ 3 ] ;
883+
836884 Ok ( ( ) )
837885 }
838886
0 commit comments