@@ -220,58 +220,31 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
220
220
const unsigned char * input ,
221
221
unsigned char * output )
222
222
{
223
- int i ;
224
- unsigned char temp [16 ];
225
-
223
+ int status = 0 ;
226
224
if ( length % 16 )
227
225
return ( MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
228
226
229
- #if defined(MBEDTLS_PADLOCK_C ) && defined(MBEDTLS_HAVE_X86 )
230
- if ( aes_padlock_ace )
227
+ switch ( ctx -> nr )
231
228
{
232
- if ( mbedtls_padlock_xcryptcbc ( ctx , mode , length , iv , input , output ) == 0 )
233
- return ( 0 );
234
-
235
- // If padlock data misaligned, we just fall back to
236
- // unaccelerated mode
237
- //
229
+ case 10 : hcryp_aes .Init .KeySize = CRYP_KEYSIZE_128B ; break ;
230
+ case 12 : hcryp_aes .Init .KeySize = CRYP_KEYSIZE_192B ; break ;
231
+ case 14 : hcryp_aes .Init .KeySize = CRYP_KEYSIZE_256B ; break ;
232
+ default : return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ;
238
233
}
239
- #endif
240
-
234
+
241
235
if ( mode == MBEDTLS_AES_DECRYPT )
242
236
{
243
- while ( length > 0 )
244
- {
245
- memcpy ( temp , input , 16 );
246
- mbedtls_aes_crypt_ecb ( ctx , mode , input , output );
247
-
248
- for ( i = 0 ; i < 16 ; i ++ )
249
- output [i ] = (unsigned char )( output [i ] ^ iv [i ] );
250
-
251
- memcpy ( iv , temp , 16 );
237
+ hcryp_aes .Init .pInitVect = & iv [0 ]; // used in process, not in the init
252
238
253
- input += 16 ;
254
- output += 16 ;
255
- length -= 16 ;
256
- }
239
+ status = HAL_CRYP_AESCBC_Decrypt (& hcryp_aes , (uint8_t * )input , length , (uint8_t * )output , 10 );
257
240
}
258
241
else
259
242
{
260
- while ( length > 0 )
261
- {
262
- for ( i = 0 ; i < 16 ; i ++ )
263
- output [i ] = (unsigned char )( input [i ] ^ iv [i ] );
264
-
265
- mbedtls_aes_crypt_ecb ( ctx , mode , output , output );
266
- memcpy ( iv , output , 16 );
267
-
268
- input += 16 ;
269
- output += 16 ;
270
- length -= 16 ;
271
- }
243
+ hcryp_aes .Init .pInitVect = & iv [0 ]; // used in process, not in the init
244
+
245
+ status = HAL_CRYP_AESCBC_Encrypt (& hcryp_aes , (uint8_t * )input , length , (uint8_t * )output , 10 );
272
246
}
273
-
274
- return ( 0 );
247
+ return ( status );
275
248
}
276
249
#endif /* MBEDTLS_CIPHER_MODE_CBC */
277
250
0 commit comments