@@ -97,7 +97,7 @@ static unsigned char channel_flag[4]={0x00,0x00,0x00,0x00}; // 0: idle, 1: busy
97
97
static int channel_alloc ()
98
98
{
99
99
int i ;
100
- for (i = 0 ; i < sizeof (channel_flag ); i ++ )
100
+ for (i = 0 ; i < ( int ) sizeof (channel_flag ); i ++ )
101
101
{
102
102
if ( channel_flag [i ] == 0x00 )
103
103
{
@@ -110,7 +110,7 @@ static int channel_alloc()
110
110
111
111
static void channel_free (int i )
112
112
{
113
- if ( i >=0 && i < sizeof (channel_flag ) )
113
+ if ( i >=0 && i < ( int ) sizeof (channel_flag ) )
114
114
channel_flag [i ] = 0x00 ;
115
115
}
116
116
@@ -142,13 +142,13 @@ void mbedtls_aes_init( mbedtls_aes_context *ctx )
142
142
143
143
NVIC_EnableIRQ (CRPT_IRQn );
144
144
AES_ENABLE_INT ();
145
- mbedtls_trace ("=== %s channel[%d]\r\n" , __FUNCTION__ , ctx -> channel );
145
+ mbedtls_trace ("=== %s channel[%d]\r\n" , __FUNCTION__ , ( int ) ctx -> channel );
146
146
}
147
147
148
148
void mbedtls_aes_free ( mbedtls_aes_context * ctx )
149
149
{
150
150
151
- mbedtls_trace ("=== %s channel[%d]\r\n" , __FUNCTION__ ,ctx -> channel );
151
+ mbedtls_trace ("=== %s channel[%d]\r\n" , __FUNCTION__ ,( int ) ctx -> channel );
152
152
153
153
if ( ctx == NULL )
154
154
return ;
@@ -248,7 +248,7 @@ static void __nvt_aes_crypt( mbedtls_aes_context *ctx,
248
248
memcpy (au8InputData , input , dataSize );
249
249
pIn = au8InputData ;
250
250
}else {
251
- pIn = input ;
251
+ pIn = ( unsigned char * ) input ;
252
252
}
253
253
if ( (((uint32_t )output ) & 0x03 ) || (dataSize %4 )) // HW CFB output byte count must be multiple of word
254
254
{
@@ -338,7 +338,7 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
338
338
unsigned char temp [16 ];
339
339
int length = len ;
340
340
int blockChainLen ;
341
- mbedtls_trace ("=== %s \r\n" , __FUNCTION__ );
341
+ mbedtls_trace ("=== %s [0x%x] \r\n" , __FUNCTION__ , length );
342
342
if ( length % 16 )
343
343
return ( MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
344
344
@@ -383,6 +383,63 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
383
383
/*
384
384
* AES-CFB128 buffer encryption/decryption
385
385
*/
386
+ /* Support partial block encryption/decryption */
387
+ static int __nvt_aes_crypt_partial_block_cfb128 ( mbedtls_aes_context * ctx ,
388
+ int mode ,
389
+ size_t length ,
390
+ size_t * iv_off ,
391
+ unsigned char iv [16 ],
392
+ const unsigned char * input ,
393
+ unsigned char * output )
394
+ {
395
+ int c ;
396
+ size_t n = * iv_off ;
397
+ unsigned char iv_tmp [16 ];
398
+ mbedtls_trace ("=== %s \r\n" , __FUNCTION__ );
399
+ if ( mode == MBEDTLS_AES_DECRYPT )
400
+ {
401
+ while ( length -- )
402
+ {
403
+ if ( n == 0 )
404
+ mbedtls_aes_crypt_ecb ( ctx , MBEDTLS_AES_ENCRYPT , iv , iv );
405
+ else if ( ctx -> opMode == AES_MODE_CFB ) // For previous cryption is CFB mode
406
+ {
407
+ memcpy (iv_tmp , iv , n );
408
+ mbedtls_aes_crypt_ecb ( ctx , MBEDTLS_AES_ENCRYPT , ctx -> prv_iv , iv );
409
+ memcpy (iv , iv_tmp , n );
410
+ }
411
+
412
+ c = * input ++ ;
413
+ * output ++ = (unsigned char )( c ^ iv [n ] );
414
+ iv [n ] = (unsigned char ) c ;
415
+
416
+ n = ( n + 1 ) & 0x0F ;
417
+ }
418
+ }
419
+ else
420
+ {
421
+ while ( length -- )
422
+ {
423
+ if ( n == 0 )
424
+ mbedtls_aes_crypt_ecb ( ctx , MBEDTLS_AES_ENCRYPT , iv , iv );
425
+ else if ( ctx -> opMode == AES_MODE_CFB ) // For previous cryption is CFB mode
426
+ {
427
+ memcpy (iv_tmp , iv , n );
428
+ mbedtls_aes_crypt_ecb ( ctx , MBEDTLS_AES_ENCRYPT , ctx -> prv_iv , iv );
429
+ memcpy (iv , iv_tmp , n );
430
+ }
431
+
432
+ iv [n ] = * output ++ = (unsigned char )( iv [n ] ^ * input ++ );
433
+
434
+ n = ( n + 1 ) & 0x0F ;
435
+ }
436
+ }
437
+
438
+ * iv_off = n ;
439
+
440
+ return ( 0 );
441
+ }
442
+
386
443
int mbedtls_aes_crypt_cfb128 ( mbedtls_aes_context * ctx ,
387
444
int mode ,
388
445
size_t len ,
@@ -456,62 +513,6 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
456
513
return ( 0 );
457
514
}
458
515
459
- /* Support partial block encryption/decryption */
460
- static int __nvt_aes_crypt_partial_block_cfb128 ( mbedtls_aes_context * ctx ,
461
- int mode ,
462
- size_t length ,
463
- size_t * iv_off ,
464
- unsigned char iv [16 ],
465
- const unsigned char * input ,
466
- unsigned char * output )
467
- {
468
- int c ;
469
- size_t n = * iv_off ;
470
- unsigned char iv_tmp [16 ];
471
- mbedtls_trace ("=== %s \r\n" , __FUNCTION__ );
472
- if ( mode == MBEDTLS_AES_DECRYPT )
473
- {
474
- while ( length -- )
475
- {
476
- if ( n == 0 )
477
- mbedtls_aes_crypt_ecb ( ctx , MBEDTLS_AES_ENCRYPT , iv , iv );
478
- else if ( ctx -> opMode == AES_MODE_CFB ) // For previous cryption is CFB mode
479
- {
480
- memcpy (iv_tmp , iv , n );
481
- mbedtls_aes_crypt_ecb ( ctx , MBEDTLS_AES_ENCRYPT , ctx -> prv_iv , iv );
482
- memcpy (iv , iv_tmp , n );
483
- }
484
-
485
- c = * input ++ ;
486
- * output ++ = (unsigned char )( c ^ iv [n ] );
487
- iv [n ] = (unsigned char ) c ;
488
-
489
- n = ( n + 1 ) & 0x0F ;
490
- }
491
- }
492
- else
493
- {
494
- while ( length -- )
495
- {
496
- if ( n == 0 )
497
- mbedtls_aes_crypt_ecb ( ctx , MBEDTLS_AES_ENCRYPT , iv , iv );
498
- else if ( ctx -> opMode == AES_MODE_CFB ) // For previous cryption is CFB mode
499
- {
500
- memcpy (iv_tmp , iv , n );
501
- mbedtls_aes_crypt_ecb ( ctx , MBEDTLS_AES_ENCRYPT , ctx -> prv_iv , iv );
502
- memcpy (iv , iv_tmp , n );
503
- }
504
-
505
- iv [n ] = * output ++ = (unsigned char )( iv [n ] ^ * input ++ );
506
-
507
- n = ( n + 1 ) & 0x0F ;
508
- }
509
- }
510
-
511
- * iv_off = n ;
512
-
513
- return ( 0 );
514
- }
515
516
516
517
/*
517
518
* AES-CFB8 buffer encryption/decryption
0 commit comments