@@ -51,37 +51,28 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
51
51
return ( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
52
52
}
53
53
54
- /* Allocated and initialise in the cipher context memory for the CMAC
55
- * context
56
- */
57
- cmac_ctx = mbedtls_calloc ( 1 , sizeof ( mbedtls_cmac_context_t ) );
58
- if ( cmac_ctx == NULL )
59
- return ( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
60
-
61
54
62
55
switch ( keybits )
63
56
{
64
57
case 128 :
65
- {
58
+ /* Allocated and initialise in the cipher context memory for the CMAC
59
+ * context
60
+ */
61
+ cmac_ctx = mbedtls_calloc ( 1 , sizeof ( mbedtls_cmac_context_t ) );
62
+ if ( cmac_ctx == NULL )
63
+ return ( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
66
64
cmac_ctx -> CC_keySizeInBytes = ( keybits / 8 );
67
65
memcpy ( cmac_ctx -> CC_Key , key , cmac_ctx -> CC_keySizeInBytes );
68
- }
69
66
break ;
70
67
case 192 :
71
68
case 256 :
72
- {
73
- mbedtls_free ( cmac_ctx );
74
69
return ( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
75
- }
76
70
default :
77
- {
78
- mbedtls_free ( cmac_ctx );
79
71
return ( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
80
- }
81
72
}
82
73
83
74
ctx -> cmac_ctx = cmac_ctx ;
84
- return 0 ;
75
+ return ( 0 ) ;
85
76
}
86
77
87
78
static int init_cc ( mbedtls_cmac_context_t * cmac_ctx )
@@ -190,9 +181,9 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
190
181
exit :
191
182
if ( ret != 0 )
192
183
{
184
+ SaSi_AesFree ( & cmac_ctx -> CC_Context );
193
185
mbedtls_platform_zeroize ( cmac_ctx , sizeof ( * cmac_ctx ) );
194
186
mbedtls_free ( cmac_ctx );
195
- SaSi_AesFree ( & cmac_ctx -> CC_Context );
196
187
}
197
188
return ( ret );
198
189
}
@@ -275,22 +266,23 @@ int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info,
275
266
276
267
if ( ( ret = init_cc ( ctx .cmac_ctx ) ) != 0 )
277
268
{
278
- goto exit ;
269
+ goto clear_cc ;
279
270
}
280
271
281
272
if ( SaSi_AesFinish ( & ctx .cmac_ctx -> CC_Context , ilen , ( uint8_t * ) input ,
282
273
ilen , output , & olen ) != 0 )
283
274
{
284
275
ret = MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ;
285
- goto exit ;
276
+ goto clear_cc ;
286
277
}
287
278
288
-
289
- exit :
279
+ clear_cc :
290
280
if ( SaSi_AesFree ( & ctx .cmac_ctx -> CC_Context ) != 0 && ret == 0 )
291
281
{
292
282
ret = MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ;
293
283
}
284
+
285
+ exit :
294
286
mbedtls_cipher_free ( & ctx );
295
287
296
288
return ( ret );
0 commit comments