Skip to content

Commit 9f4e752

Browse files
Ron EldorRon Eldor
authored andcommitted
Modify HW accelerator drivers to new error code
Have the HW accelearation drivers return the platform module errors about feature unsupported, and hw acceleration failure, because the moduel specific errors will be removed.
1 parent c40d860 commit 9f4e752

File tree

14 files changed

+71
-68
lines changed

14 files changed

+71
-68
lines changed

features/cryptocell/FEATURE_CRYPTOCELL310/cc_internal.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "cc_internal.h"
2525
#include "crys_ecpki_error.h"
2626
#include "crys_ec_mont_edw_error.h"
27+
#include "mbedtls/platform.h"
2728

2829
CRYS_ECPKI_DomainID_t convert_mbedtls_grp_id_to_crys_domain_id( mbedtls_ecp_group_id grp_id )
2930
{
@@ -135,7 +136,7 @@ int convert_CrysError_to_mbedtls_err( CRYSError_t Crys_err )
135136

136137
case CRYS_ECMONT_IS_NOT_SUPPORTED:
137138
case CRYS_ECEDW_IS_NOT_SUPPORTED:
138-
return ( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE );
139+
return ( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
139140

140141
case CRYS_ECEDW_RND_GEN_VECTOR_FUNC_ERROR:
141142
return ( MBEDTLS_ERR_ECP_RANDOM_FAILED );
@@ -146,7 +147,7 @@ int convert_CrysError_to_mbedtls_err( CRYSError_t Crys_err )
146147
return ( MBEDTLS_ERR_ECP_INVALID_KEY );
147148

148149
default:
149-
return ( MBEDTLS_ERR_ECP_HW_ACCEL_FAILED );
150+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
150151
}
151152

152153

features/cryptocell/FEATURE_CRYPTOCELL310/cc_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ uint32_t convert_mbedtls_to_cc_rand( void* mbedtls_rand, uint16_t outSizeBytes,
122122
*
123123
*
124124
* \return \c The corresponding Mbed TLS error,
125-
* MBEDTLS_ERR_ECP_HW_ACCEL_FAILED as default, if none found
125+
* MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED as default, if none found
126126
*/
127127
int convert_CrysError_to_mbedtls_err( CRYSError_t Crys_err );
128128

features/cryptocell/FEATURE_CRYPTOCELL310/ccm_alt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
5151
if( cipher != MBEDTLS_CIPHER_ID_AES ||
5252
keybits != 128 )
5353
{
54-
return ( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE );
54+
return ( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
5555
}
5656

5757
memcpy( ctx->cipher_key , key, keybits / 8 );
@@ -93,7 +93,7 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
9393
CrysRet = CRYS_AESCCM( SASI_AES_ENCRYPT, ctx->cipher_key, ctx->keySize_ID,(uint8_t*)iv, iv_len,
9494
(uint8_t*)add, add_len, (uint8_t*)input, length, output, tag_len, tag );
9595
if( CrysRet != CRYS_OK )
96-
return ( MBEDTLS_ERR_CCM_HW_ACCEL_FAILED );
96+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
9797

9898
return ( 0 );
9999

@@ -130,7 +130,7 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
130130
CrysRet = CRYS_AESCCM( SASI_AES_DECRYPT, ctx->cipher_key, ctx->keySize_ID,(uint8_t*)iv, iv_len,
131131
(uint8_t*)add, add_len, (uint8_t*)input, length, output, tag_len, (uint8_t*)tag );
132132
if ( CrysRet != CRYS_OK )
133-
return ( MBEDTLS_ERR_CCM_HW_ACCEL_FAILED );
133+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
134134

135135
return ( 0 );
136136

features/cryptocell/FEATURE_CRYPTOCELL310/ecdh_alt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp
118118
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &Q->Z, 1 ) );
119119
}
120120
else
121-
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
121+
ret = MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
122122

123123
cleanup:
124124

@@ -231,7 +231,7 @@ int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
231231
}
232232
else
233233
{
234-
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
234+
ret = MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
235235
goto cleanup;
236236
}
237237

features/cryptocell/FEATURE_CRYPTOCELL310/ecdsa_alt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
132132
}
133133
else
134134
{
135-
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
135+
ret = MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
136136
goto cleanup;
137137
}
138138

@@ -226,7 +226,7 @@ int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
226226
}
227227
}
228228
else
229-
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
229+
ret = MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
230230

231231
cleanup:
232232

@@ -313,7 +313,7 @@ int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
313313
}
314314
}
315315
else
316-
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
316+
ret = MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
317317

318318

319319
cleanup:

features/cryptocell/FEATURE_CRYPTOCELL310/sha1_alt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
4747
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx )
4848
{
4949
if( CRYS_HASH_Init( &ctx->crys_hash_ctx, CRYS_HASH_SHA1_mode ) != CRYS_OK )
50-
return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED );
50+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
5151
return ( 0 );
5252
}
5353

@@ -57,7 +57,7 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
5757
size_t ilen )
5858
{
5959
if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)input, ilen ) != CRYS_OK )
60-
return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED );
60+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
6161
return ( 0 );
6262
}
6363

@@ -73,14 +73,14 @@ int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
7373
return ( 0 );
7474
}
7575
else
76-
return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED );
76+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
7777
}
7878

7979
int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
8080
const unsigned char data[64] )
8181
{
8282
if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)data, 64 ) != CRYS_OK )
83-
return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED );
83+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
8484
return ( 0 );
8585
}
8686
#endif //MBEDTLS_SHA1_ALT

features/cryptocell/FEATURE_CRYPTOCELL310/sha256_alt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
4747
{
4848
if(CRYS_HASH_Init( &ctx->crys_hash_ctx, is224 ?
4949
CRYS_HASH_SHA224_mode : CRYS_HASH_SHA256_mode ) != CRYS_OK )
50-
return ( MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED );
50+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
5151
return ( 0 );
5252
}
5353

5454
int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
5555
const unsigned char data[64] )
5656
{
5757
if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)data, 64 ) != CRYS_OK )
58-
return ( MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED );
58+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
5959
return ( 0 );
6060
}
6161

@@ -64,7 +64,7 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
6464
size_t ilen )
6565
{
6666
if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)input, ilen ) != CRYS_OK )
67-
return ( MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED );
67+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
6868
return ( 0 );
6969
}
7070

@@ -80,7 +80,7 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
8080
return ( 0 );
8181
}
8282
else
83-
return ( MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED );
83+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
8484
}
8585
#endif //MBEDTLS_SHA256_ALT
8686

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ NU_STATIC int internal_run_eccop(const mbedtls_ecp_group *grp,
484484

485485
/* Check supported maximum key bits */
486486
if (grp->pbits > NU_ECC_MAXKEYBITS) {
487-
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
487+
return MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
488488
}
489489

490490
int ret;
@@ -675,7 +675,7 @@ NU_STATIC int internal_run_modop(mbedtls_mpi *r,
675675

676676
/* Check supported maximum key bits */
677677
if (pbits > NU_ECC_MAXKEYBITS) {
678-
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
678+
return MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
679679
}
680680

681681
/* Check MODOP operations are legal */

features/mbedtls/targets/TARGET_STM/aes_alt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#if defined(MBEDTLS_AES_ALT)
2525

2626
#if defined(TARGET_STM32L486xG) || defined (TARGET_STM32L443xC)
27+
#include "mbedtls/platform.h"
2728
//the following defines are provided to maintain compatibility between STM32 families
2829
#define __HAL_RCC_CRYP_CLK_ENABLE __HAL_RCC_AES_CLK_ENABLE
2930
#define __HAL_RCC_CRYP_FORCE_RESET __HAL_RCC_AES_FORCE_RESET
@@ -40,7 +41,7 @@ static int aes_set_key(mbedtls_aes_context *ctx, const unsigned char *key, unsig
4041
break;
4142
case 192:
4243
#if defined (TARGET_STM32L486xG) || defined (TARGET_STM32L443xC)
43-
return (MBEDTLS_ERR_AES_INVALID_KEY_LENGTH);
44+
return (MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED);
4445
#else
4546
ctx->hcryp_aes.Init.KeySize = CRYP_KEYSIZE_192B;
4647
memcpy(ctx->aes_key, key, 24);

features/mbedtls/targets/TARGET_STM/md5_alt.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,19 @@ int mbedtls_md5_starts_ret(mbedtls_md5_context *ctx)
9999
{
100100
/* HASH IP initialization */
101101
if (HAL_HASH_DeInit(&ctx->hhash_md5) != 0) {
102-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
102+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
103103
}
104104

105105
/* HASH Configuration */
106106
ctx->hhash_md5.Init.DataType = HASH_DATATYPE_8B;
107107
/* clear CR ALGO value */
108108
HASH->CR &= ~HASH_CR_ALGO_Msk;
109109
if (HAL_HASH_Init(&ctx->hhash_md5) != 0) {
110-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
110+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
111111
}
112112
if (st_md5_save_hw_context(ctx) != 1) {
113113
// Return HASH_BUSY timeout error here
114-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
114+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
115115
}
116116

117117
return 0;
@@ -121,14 +121,14 @@ int mbedtls_internal_md5_process(mbedtls_md5_context *ctx, const unsigned char d
121121
{
122122
if (st_md5_restore_hw_context(ctx) != 1) {
123123
// Return HASH_BUSY timeout error here
124-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
124+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
125125
}
126126
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, (uint8_t *)data, ST_MD5_BLOCK_SIZE) != 0) {
127-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
127+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
128128
}
129129
if (st_md5_save_hw_context(ctx) != 1) {
130130
// Return HASH_BUSY timeout error here
131-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
131+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
132132
}
133133
return 0;
134134
}
@@ -141,7 +141,7 @@ int mbedtls_md5_update_ret(mbedtls_md5_context *ctx, const unsigned char *input,
141141
if (currentlen != 0) {
142142
if (st_md5_restore_hw_context(ctx) != 1) {
143143
// Return HASH_BUSY timeout error here
144-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
144+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
145145
}
146146

147147
// store mechanism to accumulate ST_MD5_BLOCK_SIZE bytes (512 bits) in the HW
@@ -161,7 +161,7 @@ int mbedtls_md5_update_ret(mbedtls_md5_context *ctx, const unsigned char *input,
161161
size_t iter = currentlen / ST_MD5_BLOCK_SIZE;
162162
if (iter != 0) {
163163
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, (uint8_t *)(input + ST_MD5_BLOCK_SIZE - ctx->sbuf_len), (iter * ST_MD5_BLOCK_SIZE)) != 0) {
164-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
164+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
165165
}
166166
}
167167
// sbuf is completely accumulated, now copy up to 63 remaining bytes
@@ -173,7 +173,7 @@ int mbedtls_md5_update_ret(mbedtls_md5_context *ctx, const unsigned char *input,
173173

174174
if (st_md5_save_hw_context(ctx) != 1) {
175175
// Return HASH_BUSY timeout error here
176-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
176+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
177177
}
178178
}
179179
return 0;
@@ -183,24 +183,24 @@ int mbedtls_md5_finish_ret(mbedtls_md5_context *ctx, unsigned char output[16])
183183
{
184184
if (st_md5_restore_hw_context(ctx) != 1) {
185185
// Return HASH_BUSY timeout error here
186-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
186+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
187187
}
188188
/* Last accumulation for extra bytes in sbuf_len */
189189
/* This sets HW flags in case mbedtls_md5_update has not been called yet */
190190
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, ctx->sbuf, ctx->sbuf_len) != 0) {
191-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
191+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
192192
}
193193

194194
mbedtls_zeroize(ctx->sbuf, ST_MD5_BLOCK_SIZE);
195195
ctx->sbuf_len = 0;
196196
__HAL_HASH_START_DIGEST();
197197

198198
if (HAL_HASH_MD5_Finish(&ctx->hhash_md5, output, 10)) {
199-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
199+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
200200
}
201201
if (st_md5_save_hw_context(ctx) != 1) {
202202
// Return HASH_BUSY timeout error here
203-
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
203+
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
204204
}
205205
return 0;
206206
}

0 commit comments

Comments
 (0)