Skip to content

Commit d487c80

Browse files
author
Ron Eldor
committed
Additional fix for ccm_alt from On Target Testings
An additional fix for ccm_alt, when the message length is too big. Check for specific error returned from CC310, and return `MBEDTLS_ERR_CCM_BAD_INPUT`.
1 parent 53c02d7 commit d487c80

File tree

1 file changed

+31
-5
lines changed
  • features/cryptocell/FEATURE_CRYPTOCELL310

1 file changed

+31
-5
lines changed

features/cryptocell/FEATURE_CRYPTOCELL310/ccm_alt.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "mbedtls/platform.h"
2525
#include "mbedtls/platform_util.h"
2626
#include "mbedtls/aes.h"
27+
#include "crys_aesccm_error.h"
2728

2829
void mbedtls_ccm_init( mbedtls_ccm_context *ctx )
2930
{
@@ -69,6 +70,7 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
6970
{
7071
CRYSError_t CrysRet = CRYS_OK;
7172
CRYS_AESCCM_Mac_Res_t CC_Mac_Res = { 0 };
73+
int ret = 0;
7274
/*
7375
* Check length requirements: SP800-38C A.1
7476
* Additional requirement: a < 2^16 - 2^8 to simplify the code.
@@ -90,13 +92,22 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
9092
#endif
9193

9294
CrysRet = CRYS_AESCCM( SASI_AES_ENCRYPT, ctx->cipher_key, ctx->keySize_ID, (uint8_t*)iv, iv_len,
93-
(uint8_t*)add, add_len, (uint8_t*)input, length, output, tag_len, CC_Mac_Res );
94-
if ( CrysRet != CRYS_OK )
95-
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
95+
(uint8_t*)add, add_len, (uint8_t*)input, length, output, tag_len, CC_Mac_Res );
96+
if( CrysRet == CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR )
97+
{
98+
ret = MBEDTLS_ERR_CCM_BAD_INPUT;
99+
goto exit;
100+
}
101+
else if ( CrysRet != CRYS_OK )
102+
{
103+
ret = MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
104+
goto exit;
105+
}
96106

97107
memcpy( tag, CC_Mac_Res, tag_len );
98108

99-
return ( 0 );
109+
exit:
110+
return ( ret );
100111

101112
}
102113

@@ -111,6 +122,7 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
111122

112123
{
113124
CRYSError_t CrysRet = CRYS_OK;
125+
int ret = 0;
114126
/*
115127
* Check length requirements: SP800-38C A.1
116128
* Additional requirement: a < 2^16 - 2^8 to simplify the code.
@@ -130,7 +142,18 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
130142

131143
CrysRet = CRYS_AESCCM( SASI_AES_DECRYPT, ctx->cipher_key, ctx->keySize_ID,(uint8_t*)iv, iv_len,
132144
(uint8_t*)add, add_len, (uint8_t*)input, length, output, tag_len, (uint8_t*)tag );
133-
if( CrysRet == CRYS_FATAL_ERROR )
145+
if( CrysRet == CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR )
146+
{
147+
/*
148+
* When CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR is returned,
149+
* no operation has occured, and no need to zeroize output.
150+
* In addition, it could be that the message length is too big,
151+
* returning this error code, and we don't want to overflow
152+
* the output buffer.
153+
*/
154+
return( MBEDTLS_ERR_CCM_BAD_INPUT );
155+
}
156+
else if( CrysRet == CRYS_FATAL_ERROR )
134157
{
135158
/*
136159
* Unfortunately, Crys AESCCM returns CRYS_FATAL_ERROR when
@@ -158,7 +181,9 @@ int mbedtls_ccm_star_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
158181
const unsigned char *input, unsigned char *output,
159182
unsigned char *tag, size_t tag_len )
160183
{
184+
161185
return( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE );
186+
162187
}
163188

164189
int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
@@ -168,6 +193,7 @@ int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
168193
const unsigned char *tag, size_t tag_len )
169194
{
170195
return( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE );
196+
171197
}
172198

173199
#endif

0 commit comments

Comments
 (0)