From a1ea814f0619622aff10b9fcd6b85ace64b1fbd2 Mon Sep 17 00:00:00 2001 From: Ron Eldor Date: Wed, 16 May 2018 13:58:46 +0300 Subject: [PATCH] Minor style fixes Fix styls issues and rename ARM to Arm. Address additional minor comments from review. --- .../mbedtls/targets/TARGET_CRYPTOCELL310/Readme.md | 4 ++-- .../TARGET_NRF52840_DK/cc_platform.h | 2 +- .../TARGET_NRF52840_DK/cc_platform_nrf52840.c | 2 +- .../targets/TARGET_CRYPTOCELL310/cc_internal.c | 4 ++-- .../targets/TARGET_CRYPTOCELL310/cc_internal.h | 2 +- .../mbedtls/targets/TARGET_CRYPTOCELL310/ccm_alt.c | 8 ++++++-- .../mbedtls/targets/TARGET_CRYPTOCELL310/ccm_alt.h | 2 +- .../mbedtls/targets/TARGET_CRYPTOCELL310/ecdh_alt.c | 8 ++++---- .../mbedtls/targets/TARGET_CRYPTOCELL310/ecdsa_alt.c | 12 +++++++----- .../targets/TARGET_CRYPTOCELL310/mbedtls_device.h | 2 +- .../targets/TARGET_CRYPTOCELL310/platform_alt.c | 2 +- .../targets/TARGET_CRYPTOCELL310/platform_alt.h | 2 +- .../mbedtls/targets/TARGET_CRYPTOCELL310/sha1_alt.c | 2 +- .../mbedtls/targets/TARGET_CRYPTOCELL310/sha1_alt.h | 2 +- .../targets/TARGET_CRYPTOCELL310/sha256_alt.c | 2 +- .../targets/TARGET_CRYPTOCELL310/sha256_alt.h | 2 +- targets/TARGET_CRYPTOCELL310/objects_cryptocell.h | 2 +- targets/TARGET_CRYPTOCELL310/trng.c | 2 +- 18 files changed, 34 insertions(+), 28 deletions(-) diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/Readme.md b/features/mbedtls/targets/TARGET_CRYPTOCELL310/Readme.md index 3d3aa52409..164c324b44 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/Readme.md +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/Readme.md @@ -12,11 +12,11 @@ To port your CC 310 driver to Mbed OS on your specific target, do the following: 1. In `targets.json` add the following to your target: * `MBEDTLS_CONFIG_HW_SUPPORT` to `macros_add` key. This instructs Mbed TLS to look for an alternative cryptographic implementation. - * `CRYPTOCELL` to `device_has_add` key. Use this in your common code that you need to remove from compilation in case CC exists in your board. Use `#if !defined(DEVICE_CRYPTOCELL)` or `#if DEVICE_CRYPTOCELL`. + * `CRYPTOCELL` to `device_has_add` key. Use this in your common code that you need to remove from compilation in case CC exists in your board. Use `#if !defined(DEVICE_CRYPTOCELL)` and `#if defined(DEVICE_CRYPTOCELL)`. * `CRYPTOCELL310` to `extra_labels_add` key. The build system uses this to look for the CC 310 code and binaries. 1. In `objects.h`, include `objects_cryptocell.h`. You can use the `DEVICE_CRYPTOCELL` precompilation check as defined above. 1. In `features/mbedtls/targets/TARGET_CRYPTOCELL310/TARGET_`, add your platform-specific libraries for all toolchains in `TOOLCHAIN_ARM`, `TOOLCHAIN_GCC_ARM` and `TOOLCHAIN_IAR` respectively. 1. Add your CC setup code: - * Implement `cc_platform_setup()` and `cc_platform_terminate()` to enable CC on your platform, in case you have board-specific setup functionality, required for CC setup. You can implement these functions as empty functions. + * Implement `cc_platform_setup()` and `cc_platform_terminate()` to enable CC on your platform, in case you have board-specific setup functionality, required for CC setup.These functions can be empty. * Define `cc_platform_ctx` in `cc_platform.h` in a way that suits your implementation. diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/TARGET_NRF52840_DK/cc_platform.h b/features/mbedtls/targets/TARGET_CRYPTOCELL310/TARGET_NRF52840_DK/cc_platform.h index 0105bdf934..87433c5577 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/TARGET_NRF52840_DK/cc_platform.h +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/TARGET_NRF52840_DK/cc_platform.h @@ -1,7 +1,7 @@ /* * cc_platform.h * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/TARGET_NRF52840_DK/cc_platform_nrf52840.c b/features/mbedtls/targets/TARGET_CRYPTOCELL310/TARGET_NRF52840_DK/cc_platform_nrf52840.c index 9b4c9a8bb4..1ff1462e9a 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/TARGET_NRF52840_DK/cc_platform_nrf52840.c +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/TARGET_NRF52840_DK/cc_platform_nrf52840.c @@ -1,7 +1,7 @@ /* * cc_platform_nrf52840.c * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/cc_internal.c b/features/mbedtls/targets/TARGET_CRYPTOCELL310/cc_internal.c index 5a3ece6687..acad6d5482 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/cc_internal.c +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/cc_internal.c @@ -4,7 +4,7 @@ * Internal utility functions and definitions, * used for converting mbedtls types to CC types, and vice versa * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -92,7 +92,7 @@ uint32_t convert_mbedtls_to_cc_rand( void* mbedtls_rnd_ctx, uint16_t outSizeByte int convert_CrysError_to_mbedtls_err( CRYSError_t Crys_err ) { - switch(Crys_err) + switch( Crys_err ) { case CRYS_OK: return ( 0 ); diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/cc_internal.h b/features/mbedtls/targets/TARGET_CRYPTOCELL310/cc_internal.h index 7eb8c4bde7..0cbbbdbd38 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/cc_internal.h +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/cc_internal.h @@ -4,7 +4,7 @@ * Internal utility functions and definitions, * used for converting mbedtls types to CC types, and vice versa * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/ccm_alt.c b/features/mbedtls/targets/TARGET_CRYPTOCELL310/ccm_alt.c index 8ff8e016e6..55541b6780 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/ccm_alt.c +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/ccm_alt.c @@ -1,7 +1,7 @@ /* * ccm_alt.c * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -54,7 +54,7 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx, return ( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE ); } - memcpy( ctx->cipher_key , key, keybits/8 ); + memcpy( ctx->cipher_key , key, keybits / 8 ); ctx->keySize_ID = CRYS_AES_Key128BitSize; return ( 0 ); @@ -85,8 +85,10 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, if( iv_len < 7 || iv_len > 13 ) return ( MBEDTLS_ERR_CCM_BAD_INPUT ); +#if defined(MBEDTLS_HAVE_INT64) if( length > 0xFFFFFFFF || add_len > 0xFFFFFFFF ) return ( MBEDTLS_ERR_CCM_BAD_INPUT ); +#endif 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 ); @@ -120,8 +122,10 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, if( iv_len < 7 || iv_len > 13 ) return ( MBEDTLS_ERR_CCM_BAD_INPUT ); +#if defined(MBEDTLS_HAVE_INT64) if( length > 0xFFFFFFFF || add_len > 0xFFFFFFFF ) return ( MBEDTLS_ERR_CCM_BAD_INPUT ); +#endif 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 ); diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/ccm_alt.h b/features/mbedtls/targets/TARGET_CRYPTOCELL310/ccm_alt.h index 0f31c8787a..38b9823460 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/ccm_alt.h +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/ccm_alt.h @@ -1,7 +1,7 @@ /* * ccm_alt.h * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/ecdh_alt.c b/features/mbedtls/targets/TARGET_CRYPTOCELL310/ecdh_alt.c index 7077223812..9c99347e4e 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/ecdh_alt.c +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/ecdh_alt.c @@ -1,7 +1,7 @@ /* * ecdh_alt.c * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -52,12 +52,12 @@ int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp if ( pDomain ) { uint8_t temp_buf[ 2 * MAX_KEY_SIZE_IN_BYTES + 1 ] = {0}; - cc_ecc_ws_keygen_params_t* kgParams = mbedtls_calloc( 1, sizeof(cc_ecc_ws_keygen_params_t) ); + cc_ecc_ws_keygen_params_t* kgParams = mbedtls_calloc( 1, sizeof( cc_ecc_ws_keygen_params_t ) ); if ( kgParams == NULL ) return ( MBEDTLS_ERR_ECP_ALLOC_FAILED ); pHeap = kgParams; - heapSize = sizeof(cc_ecc_ws_keygen_params_t); + heapSize = sizeof( cc_ecc_ws_keygen_params_t ); ret = convert_CrysError_to_mbedtls_err( CRYS_ECPKI_GenKeyPair( &cc_rand, convert_mbedtls_to_cc_rand, pDomain, &kgParams->privKey, @@ -92,7 +92,7 @@ int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp mbedtls_zeroize( temp_buf, sizeof( temp_buf ) ); } - /* if CRYS_ECPKI_GetEcDomain returns NULL, than the given curve is wither Montgomery 25519 + /* if CRYS_ECPKI_GetEcDomain returns NULL, then the given curve is either Montgomery 25519 * or another curve which is not supported by CC310*/ else if ( grp->id == MBEDTLS_ECP_DP_CURVE25519 ) { diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/ecdsa_alt.c b/features/mbedtls/targets/TARGET_CRYPTOCELL310/ecdsa_alt.c index 163f624fa4..63fdfa1d0f 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/ecdsa_alt.c +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/ecdsa_alt.c @@ -1,7 +1,7 @@ /* * ecdsa_alt.c * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -78,11 +78,12 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, mbedtls_rand_func_container cc_rand = { f_rng, p_rng }; const CRYS_ECPKI_Domain_t* pDomain = CRYS_ECPKI_GetEcDomain ( convert_mbedtls_grp_id_to_crys_domain_id( grp->id ) ); +#if defined(MBEDTLS_HAVE_INT64) if( blen > 0xFFFFFFFF ) { - ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA; - goto cleanup; + return ( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); } +#endif if ( pDomain != NULL ) { @@ -175,11 +176,12 @@ int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp, uint32_t signature_size = ( ( grp->nbits + 7 ) / 8 ) * 2; const CRYS_ECPKI_Domain_t* pDomain = CRYS_ECPKI_GetEcDomain ( convert_mbedtls_grp_id_to_crys_domain_id( grp->id ) ); +#if defined(MBEDTLS_HAVE_INT64) if( blen > 0xFFFFFFFF ) { - ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA; - goto cleanup; + return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); } +#endif if ( pDomain ) { diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/mbedtls_device.h b/features/mbedtls/targets/TARGET_CRYPTOCELL310/mbedtls_device.h index 496d5e86be..c612c14e57 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/mbedtls_device.h +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/mbedtls_device.h @@ -1,7 +1,7 @@ /* * mbedtls_device.h * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/platform_alt.c b/features/mbedtls/targets/TARGET_CRYPTOCELL310/platform_alt.c index fe84b4ef3a..ed579901ad 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/platform_alt.c +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/platform_alt.c @@ -1,7 +1,7 @@ /* * platform_alt.c * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/platform_alt.h b/features/mbedtls/targets/TARGET_CRYPTOCELL310/platform_alt.h index 7365443643..8ed39ae15d 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/platform_alt.h +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/platform_alt.h @@ -1,7 +1,7 @@ /* * platform_alt.h * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha1_alt.c b/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha1_alt.c index 15caddac57..10818ed18f 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha1_alt.c +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha1_alt.c @@ -1,7 +1,7 @@ /* * sha1_alt.c * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha1_alt.h b/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha1_alt.h index d2c650651c..d9a74f2410 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha1_alt.h +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha1_alt.h @@ -1,7 +1,7 @@ /* * sha1_alt.h * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha256_alt.c b/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha256_alt.c index a2350162e8..f7912996a6 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha256_alt.c +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha256_alt.c @@ -1,7 +1,7 @@ /* * sha256_alt.c * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha256_alt.h b/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha256_alt.h index 691d5bc622..bdb7c45e80 100644 --- a/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha256_alt.h +++ b/features/mbedtls/targets/TARGET_CRYPTOCELL310/sha256_alt.h @@ -1,7 +1,7 @@ /* * sha256_alt.h * - * Copyright (C) 2018, ARM Limited, All Rights Reserved + * Copyright (C) 2018, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/targets/TARGET_CRYPTOCELL310/objects_cryptocell.h b/targets/TARGET_CRYPTOCELL310/objects_cryptocell.h index 88d80c7df3..941ddf5558 100644 --- a/targets/TARGET_CRYPTOCELL310/objects_cryptocell.h +++ b/targets/TARGET_CRYPTOCELL310/objects_cryptocell.h @@ -1,7 +1,7 @@ /* * objects_cryptocell.h * - * Copyright (C) 2017, ARM Limited, All Rights Reserved + * Copyright (C) 2017, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/targets/TARGET_CRYPTOCELL310/trng.c b/targets/TARGET_CRYPTOCELL310/trng.c index d6228d2905..c0d238e71e 100644 --- a/targets/TARGET_CRYPTOCELL310/trng.c +++ b/targets/TARGET_CRYPTOCELL310/trng.c @@ -1,7 +1,7 @@ /* * trng.c * - * Copyright (C) 2017, ARM Limited, All Rights Reserved + * Copyright (C) 2017, Arm Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may