Skip to content

Commit 5ed3a64

Browse files
author
Ron Eldor
committed
Return MBEDTLS_ERR_CCM_BAD_INPUT on invalid key
Return `MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE` only for valid key lengths, that are not supported by Cryptocell 310. For other key sizes, return `MBEDTLS_ERR_CCM_BAD_INPUT`
1 parent 1b34927 commit 5ed3a64

File tree

1 file changed

+16
-4
lines changed
  • features/cryptocell/FEATURE_CRYPTOCELL310

1 file changed

+16
-4
lines changed

features/cryptocell/FEATURE_CRYPTOCELL310/ccm_alt.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,26 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
4444
if( ctx == NULL )
4545
return( MBEDTLS_ERR_CCM_BAD_INPUT );
4646

47-
if( cipher != MBEDTLS_CIPHER_ID_AES ||
48-
keybits != 128 )
47+
if( cipher != MBEDTLS_CIPHER_ID_AES )
4948
{
5049
return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
5150
}
5251

53-
memcpy( ctx->cipher_key , key, keybits / 8 );
54-
ctx->key_size = CRYS_AES_Key128BitSize;
52+
switch( keybits )
53+
{
54+
case 128:
55+
{
56+
memcpy( ctx->cipher_key , key, keybits / 8 );
57+
ctx->key_size = CRYS_AES_Key128BitSize;
58+
}
59+
break;
60+
case 192:
61+
case 256:
62+
return( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE );
63+
default:
64+
return( MBEDTLS_ERR_CCM_BAD_INPUT );
65+
}
66+
5567

5668
return( 0 );
5769

0 commit comments

Comments
 (0)