Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify HW accelerator drivers to new error code #8643

Merged
merged 1 commit into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions features/cryptocell/FEATURE_CRYPTOCELL310/cc_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "cc_internal.h"
#include "crys_ecpki_error.h"
#include "crys_ec_mont_edw_error.h"
#include "mbedtls/platform.h"

CRYS_ECPKI_DomainID_t convert_mbedtls_grp_id_to_crys_domain_id( mbedtls_ecp_group_id grp_id )
{
Expand Down Expand Up @@ -135,7 +136,7 @@ int convert_CrysError_to_mbedtls_err( CRYSError_t Crys_err )

case CRYS_ECMONT_IS_NOT_SUPPORTED:
case CRYS_ECEDW_IS_NOT_SUPPORTED:
return ( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE );
return ( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );

case CRYS_ECEDW_RND_GEN_VECTOR_FUNC_ERROR:
return ( MBEDTLS_ERR_ECP_RANDOM_FAILED );
Expand All @@ -146,7 +147,7 @@ int convert_CrysError_to_mbedtls_err( CRYSError_t Crys_err )
return ( MBEDTLS_ERR_ECP_INVALID_KEY );

default:
return ( MBEDTLS_ERR_ECP_HW_ACCEL_FAILED );
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
}


Expand Down
2 changes: 1 addition & 1 deletion features/cryptocell/FEATURE_CRYPTOCELL310/cc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ uint32_t convert_mbedtls_to_cc_rand( void* mbedtls_rand, uint16_t outSizeBytes,
*
*
* \return \c The corresponding Mbed TLS error,
* MBEDTLS_ERR_ECP_HW_ACCEL_FAILED as default, if none found
* MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED as default, if none found
*/
int convert_CrysError_to_mbedtls_err( CRYSError_t Crys_err );

Expand Down
6 changes: 3 additions & 3 deletions features/cryptocell/FEATURE_CRYPTOCELL310/ccm_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
if( cipher != MBEDTLS_CIPHER_ID_AES ||
keybits != 128 )
{
return ( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE );
return ( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
}

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

return ( 0 );

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

return ( 0 );

Expand Down
4 changes: 2 additions & 2 deletions features/cryptocell/FEATURE_CRYPTOCELL310/ecdh_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &Q->Z, 1 ) );
}
else
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
ret = MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;

cleanup:

Expand Down Expand Up @@ -231,7 +231,7 @@ int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
}
else
{
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
ret = MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
goto cleanup;
}

Expand Down
6 changes: 3 additions & 3 deletions features/cryptocell/FEATURE_CRYPTOCELL310/ecdsa_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
}
else
{
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
ret = MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
goto cleanup;
}

Expand Down Expand Up @@ -226,7 +226,7 @@ int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
}
}
else
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
ret = MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;

cleanup:

Expand Down Expand Up @@ -313,7 +313,7 @@ int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
}
}
else
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
ret = MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;


cleanup:
Expand Down
8 changes: 4 additions & 4 deletions features/cryptocell/FEATURE_CRYPTOCELL310/sha1_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx )
{
if( CRYS_HASH_Init( &ctx->crys_hash_ctx, CRYS_HASH_SHA1_mode ) != CRYS_OK )
return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED );
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
return ( 0 );
}

Expand All @@ -57,7 +57,7 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
size_t ilen )
{
if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)input, ilen ) != CRYS_OK )
return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED );
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
return ( 0 );
}

Expand All @@ -73,14 +73,14 @@ int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
return ( 0 );
}
else
return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED );
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
}

int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
const unsigned char data[64] )
{
if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)data, 64 ) != CRYS_OK )
return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED );
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
return ( 0 );
}
#endif //MBEDTLS_SHA1_ALT
8 changes: 4 additions & 4 deletions features/cryptocell/FEATURE_CRYPTOCELL310/sha256_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
{
if(CRYS_HASH_Init( &ctx->crys_hash_ctx, is224 ?
CRYS_HASH_SHA224_mode : CRYS_HASH_SHA256_mode ) != CRYS_OK )
return ( MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED );
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
return ( 0 );
}

int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
const unsigned char data[64] )
{
if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)data, 64 ) != CRYS_OK )
return ( MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED );
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
return ( 0 );
}

Expand All @@ -64,7 +64,7 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
size_t ilen )
{
if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)input, ilen ) != CRYS_OK )
return ( MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED );
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
return ( 0 );
}

Expand All @@ -80,7 +80,7 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
return ( 0 );
}
else
return ( MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED );
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
}
#endif //MBEDTLS_SHA256_ALT

Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ NU_STATIC int internal_run_eccop(const mbedtls_ecp_group *grp,

/* Check supported maximum key bits */
if (grp->pbits > NU_ECC_MAXKEYBITS) {
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
return MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
}

int ret;
Expand Down Expand Up @@ -675,7 +675,7 @@ NU_STATIC int internal_run_modop(mbedtls_mpi *r,

/* Check supported maximum key bits */
if (pbits > NU_ECC_MAXKEYBITS) {
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
return MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
}

/* Check MODOP operations are legal */
Expand Down
3 changes: 2 additions & 1 deletion features/mbedtls/targets/TARGET_STM/aes_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#if defined(MBEDTLS_AES_ALT)

#if defined(TARGET_STM32L486xG) || defined (TARGET_STM32L443xC)
#include "mbedtls/platform.h"
//the following defines are provided to maintain compatibility between STM32 families
#define __HAL_RCC_CRYP_CLK_ENABLE __HAL_RCC_AES_CLK_ENABLE
#define __HAL_RCC_CRYP_FORCE_RESET __HAL_RCC_AES_FORCE_RESET
Expand All @@ -40,7 +41,7 @@ static int aes_set_key(mbedtls_aes_context *ctx, const unsigned char *key, unsig
break;
case 192:
#if defined (TARGET_STM32L486xG) || defined (TARGET_STM32L443xC)
return (MBEDTLS_ERR_AES_INVALID_KEY_LENGTH);
return (MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED);
#else
ctx->hcryp_aes.Init.KeySize = CRYP_KEYSIZE_192B;
memcpy(ctx->aes_key, key, 24);
Expand Down
26 changes: 13 additions & 13 deletions features/mbedtls/targets/TARGET_STM/md5_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ int mbedtls_md5_starts_ret(mbedtls_md5_context *ctx)
{
/* HASH IP initialization */
if (HAL_HASH_DeInit(&ctx->hhash_md5) != 0) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}

/* HASH Configuration */
ctx->hhash_md5.Init.DataType = HASH_DATATYPE_8B;
/* clear CR ALGO value */
HASH->CR &= ~HASH_CR_ALGO_Msk;
if (HAL_HASH_Init(&ctx->hhash_md5) != 0) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}
if (st_md5_save_hw_context(ctx) != 1) {
// Return HASH_BUSY timeout error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}

return 0;
Expand All @@ -121,14 +121,14 @@ int mbedtls_internal_md5_process(mbedtls_md5_context *ctx, const unsigned char d
{
if (st_md5_restore_hw_context(ctx) != 1) {
// Return HASH_BUSY timeout error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, (uint8_t *)data, ST_MD5_BLOCK_SIZE) != 0) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}
if (st_md5_save_hw_context(ctx) != 1) {
// Return HASH_BUSY timeout error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}
return 0;
}
Expand All @@ -141,7 +141,7 @@ int mbedtls_md5_update_ret(mbedtls_md5_context *ctx, const unsigned char *input,
if (currentlen != 0) {
if (st_md5_restore_hw_context(ctx) != 1) {
// Return HASH_BUSY timeout error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}

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

if (st_md5_save_hw_context(ctx) != 1) {
// Return HASH_BUSY timeout error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}
}
return 0;
Expand All @@ -183,24 +183,24 @@ int mbedtls_md5_finish_ret(mbedtls_md5_context *ctx, unsigned char output[16])
{
if (st_md5_restore_hw_context(ctx) != 1) {
// Return HASH_BUSY timeout error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}
/* Last accumulation for extra bytes in sbuf_len */
/* This sets HW flags in case mbedtls_md5_update has not been called yet */
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, ctx->sbuf, ctx->sbuf_len) != 0) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}

mbedtls_zeroize(ctx->sbuf, ST_MD5_BLOCK_SIZE);
ctx->sbuf_len = 0;
__HAL_HASH_START_DIGEST();

if (HAL_HASH_MD5_Finish(&ctx->hhash_md5, output, 10)) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}
if (st_md5_save_hw_context(ctx) != 1) {
// Return HASH_BUSY timeout error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
}
return 0;
}
Expand Down
Loading