@@ -52,7 +52,15 @@ static int init_cc( mbedtls_cmac_context_t *cmac_ctx )
52
52
53
53
exit :
54
54
return ( ret );
55
+ }
56
+
57
+ static int deinit_cc ( mbedtls_cmac_context_t * cmac_ctx )
58
+ {
59
+ if ( cmac_ctx -> is_cc_initiated == 1 &&
60
+ SaSi_AesFree ( & cmac_ctx -> CC_Context ) != 0 )
61
+ return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
55
62
63
+ return ( 0 );
56
64
}
57
65
58
66
int mbedtls_cipher_cmac_starts ( mbedtls_cipher_context_t * ctx ,
@@ -116,7 +124,6 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
116
124
if ( ctx == NULL || ctx -> cipher_info == NULL )
117
125
return ( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
118
126
119
-
120
127
block_size = ctx -> cipher_info -> block_size ;
121
128
if ( block_size != SASI_AES_BLOCK_SIZE_IN_BYTES )
122
129
return ( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
@@ -174,7 +181,7 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
174
181
exit :
175
182
if ( ret != 0 )
176
183
{
177
- SaSi_AesFree ( & cmac_ctx -> CC_Context );
184
+ deinit_cc ( cmac_ctx );
178
185
mbedtls_platform_zeroize ( cmac_ctx , sizeof ( * cmac_ctx ) );
179
186
mbedtls_free ( cmac_ctx );
180
187
}
@@ -203,8 +210,7 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
203
210
}
204
211
205
212
exit :
206
- if ( cmac_ctx -> is_cc_initiated == 1 &&
207
- SaSi_AesFree ( & cmac_ctx -> CC_Context ) != 0 && ret == 0 )
213
+ if ( deinit_cc ( cmac_ctx ) && ret == 0 )
208
214
{
209
215
ret = MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ;
210
216
}
@@ -214,7 +220,6 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
214
220
215
221
int mbedtls_cipher_cmac_reset ( mbedtls_cipher_context_t * ctx )
216
222
{
217
- int ret = 0 ;
218
223
mbedtls_cmac_context_t * cmac_ctx ;
219
224
220
225
if ( ctx == NULL || ctx -> cipher_info == NULL || ctx -> cmac_ctx == NULL )
@@ -227,8 +232,7 @@ int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx )
227
232
mbedtls_platform_zeroize ( cmac_ctx -> unprocessed_block ,
228
233
sizeof ( cmac_ctx -> unprocessed_block ) );
229
234
230
- if ( cmac_ctx -> is_cc_initiated == 1 &&
231
- SaSi_AesFree ( & cmac_ctx -> CC_Context ) != 0 )
235
+ if ( deinit_cc ( cmac_ctx ) != 0 )
232
236
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
233
237
234
238
return ( init_cc ( cmac_ctx ) );
@@ -256,7 +260,6 @@ int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info,
256
260
if ( ret != 0 )
257
261
goto exit ;
258
262
259
-
260
263
if ( SaSi_AesFinish ( & ctx .cmac_ctx -> CC_Context , ilen , ( uint8_t * ) input ,
261
264
ilen , output , & olen ) != 0 )
262
265
{
@@ -265,8 +268,7 @@ int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info,
265
268
}
266
269
267
270
clear_cc :
268
- if ( ctx .cmac_ctx -> is_cc_initiated == 1 &&
269
- SaSi_AesFree ( & ctx .cmac_ctx -> CC_Context ) != 0 && ret == 0 )
271
+ if ( deinit_cc ( ctx .cmac_ctx ) != 0 && ret == 0 )
270
272
{
271
273
ret = MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ;
272
274
}
0 commit comments