24
24
#include "mbedtls/platform.h"
25
25
#include "mbedtls/platform_util.h"
26
26
#include "mbedtls/aes.h"
27
+ #include "crys_aesccm_error.h"
27
28
28
29
void mbedtls_ccm_init ( mbedtls_ccm_context * ctx )
29
30
{
@@ -69,6 +70,7 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
69
70
{
70
71
CRYSError_t CrysRet = CRYS_OK ;
71
72
CRYS_AESCCM_Mac_Res_t CC_Mac_Res = { 0 };
73
+ int ret = 0 ;
72
74
/*
73
75
* Check length requirements: SP800-38C A.1
74
76
* 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,
90
92
#endif
91
93
92
94
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
+ }
96
106
97
107
memcpy ( tag , CC_Mac_Res , tag_len );
98
108
99
- return ( 0 );
109
+ exit :
110
+ return ( ret );
100
111
101
112
}
102
113
@@ -111,6 +122,7 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
111
122
112
123
{
113
124
CRYSError_t CrysRet = CRYS_OK ;
125
+ int ret = 0 ;
114
126
/*
115
127
* Check length requirements: SP800-38C A.1
116
128
* 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,
130
142
131
143
CrysRet = CRYS_AESCCM ( SASI_AES_DECRYPT , ctx -> cipher_key , ctx -> keySize_ID ,(uint8_t * )iv , iv_len ,
132
144
(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 )
134
157
{
135
158
/*
136
159
* 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,
158
181
const unsigned char * input , unsigned char * output ,
159
182
unsigned char * tag , size_t tag_len )
160
183
{
184
+
161
185
return ( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE );
186
+
162
187
}
163
188
164
189
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,
168
193
const unsigned char * tag , size_t tag_len )
169
194
{
170
195
return ( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE );
196
+
171
197
}
172
198
173
199
#endif
0 commit comments