@@ -111,9 +111,10 @@ void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx ){}
111
111
void mbedtls_aes_xts_free ( mbedtls_aes_xts_context * ctx ){}
112
112
#endif /* MBEDTLS_CIPHER_MODE_XTS */
113
113
114
- int mbedtls_aes_setkey_enc ( mbedtls_aes_context * ctx , const unsigned char * key ,
115
- unsigned int keybits )
114
+ static int CC_aes_setkey ( mbedtls_aes_context * ctx , const unsigned char * key ,
115
+ unsigned int keybits , SaSiAesEncryptMode_t cipher_flag )
116
116
{
117
+
117
118
int ret = 0 ;
118
119
if ( ctx == NULL )
119
120
return ( MBEDTLS_ERR_AES_BAD_INPUT_DATA );
@@ -122,7 +123,7 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
122
123
{
123
124
case 128 :
124
125
{
125
- ctx -> CC_cipherFlag = SASI_AES_ENCRYPT ;
126
+ ctx -> CC_cipherFlag = cipher_flag ;
126
127
ctx -> CC_keySizeInBytes = ( keybits / 8 );
127
128
memcpy ( ctx -> CC_Key , key , ctx -> CC_keySizeInBytes );
128
129
}
@@ -137,32 +138,16 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
137
138
return ( 0 );
138
139
139
140
}
141
+ int mbedtls_aes_setkey_enc ( mbedtls_aes_context * ctx , const unsigned char * key ,
142
+ unsigned int keybits )
143
+ {
144
+ return ( CC_aes_setkey ( ctx , key , keybits , SASI_AES_ENCRYPT ) );
145
+ }
140
146
141
147
int mbedtls_aes_setkey_dec ( mbedtls_aes_context * ctx , const unsigned char * key ,
142
148
unsigned int keybits )
143
149
{
144
- int ret = 0 ;
145
- if ( ctx == NULL )
146
- return ( MBEDTLS_ERR_AES_BAD_INPUT_DATA );
147
-
148
- switch ( keybits )
149
- {
150
- case 128 :
151
- {
152
- ctx -> CC_cipherFlag = SASI_AES_DECRYPT ;
153
- ctx -> CC_keySizeInBytes = ( keybits / 8 );
154
- memcpy ( ctx -> CC_Key , key , ctx -> CC_keySizeInBytes );
155
- }
156
- break ;
157
- case 192 :
158
- case 256 :
159
- return ( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
160
- default :
161
- return ( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH );
162
- }
163
-
164
- return ( 0 );
165
-
150
+ return ( CC_aes_setkey ( ctx , key , keybits , SASI_AES_DECRYPT ) );
166
151
}
167
152
168
153
static int CC_aes_cipher ( mbedtls_aes_context * ctx ,
@@ -237,7 +222,6 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
237
222
return ( MBEDTLS_ERR_AES_BAD_INPUT_DATA );
238
223
239
224
return ( CC_aes_cipher ( ctx , mode , SASI_AES_MODE_ECB , 16 , NULL , 0 , input , output ) );
240
-
241
225
}
242
226
243
227
#if defined(MBEDTLS_CIPHER_MODE_CBC )
@@ -251,7 +235,6 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
251
235
if ( ctx == NULL )
252
236
return ( MBEDTLS_ERR_AES_BAD_INPUT_DATA );
253
237
254
-
255
238
if ( length % SASI_AES_BLOCK_SIZE_IN_BYTES )
256
239
return ( MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
257
240
@@ -317,7 +300,6 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
317
300
{
318
301
goto exit ;
319
302
}
320
-
321
303
}
322
304
* nc_off = ( length % SASI_AES_BLOCK_SIZE_IN_BYTES );
323
305
@@ -326,4 +308,3 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
326
308
}
327
309
#endif /* MBEDTLS_CIPHER_MODE_CTR */
328
310
#endif /* MBEDTLS_AES_ALT */
329
-
0 commit comments