From 615bf36d889db60f249ed0233ca7b98e31af7c1b Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 27 May 2020 22:27:55 -0700 Subject: [PATCH] [crypto] update method documentation and style (#5015) --- src/core/crypto/aes_ecb.cpp | 4 ++-- src/core/crypto/aes_ecb.hpp | 6 +++--- src/core/crypto/ecdsa.hpp | 1 + src/core/crypto/hmac_sha256.cpp | 4 ++-- src/core/crypto/hmac_sha256.hpp | 4 ++-- src/core/crypto/mbedtls.cpp | 6 +++--- src/core/crypto/mbedtls.hpp | 9 +++++++-- src/core/crypto/sha256.cpp | 4 ++-- src/core/crypto/sha256.hpp | 4 ++-- 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/core/crypto/aes_ecb.cpp b/src/core/crypto/aes_ecb.cpp index 2c252a05f..77fea9030 100644 --- a/src/core/crypto/aes_ecb.cpp +++ b/src/core/crypto/aes_ecb.cpp @@ -36,7 +36,7 @@ namespace ot { namespace Crypto { -AesEcb::AesEcb() +AesEcb::AesEcb(void) { mbedtls_aes_init(&mContext); } @@ -51,7 +51,7 @@ void AesEcb::Encrypt(const uint8_t aInput[kBlockSize], uint8_t aOutput[kBlockSiz mbedtls_aes_crypt_ecb(&mContext, MBEDTLS_AES_ENCRYPT, aInput, aOutput); } -AesEcb::~AesEcb() +AesEcb::~AesEcb(void) { mbedtls_aes_free(&mContext); } diff --git a/src/core/crypto/aes_ecb.hpp b/src/core/crypto/aes_ecb.hpp index 1d86eccd0..085ccfa50 100644 --- a/src/core/crypto/aes_ecb.hpp +++ b/src/core/crypto/aes_ecb.hpp @@ -64,19 +64,19 @@ public: * Constructor to initialize the mbedtls_aes_context. * */ - AesEcb(); + AesEcb(void); /** * Destructor to free the mbedtls_aes_context. * */ - ~AesEcb(); + ~AesEcb(void); /** * This method sets the key. * * @param[in] aKey A pointer to the key. - * @param[in] aKeyLength The key length in bytes. + * @param[in] aKeyLength The key length in bits. * */ void SetKey(const uint8_t *aKey, uint16_t aKeyLength); diff --git a/src/core/crypto/ecdsa.hpp b/src/core/crypto/ecdsa.hpp index 0c169ab2c..2248ecaac 100644 --- a/src/core/crypto/ecdsa.hpp +++ b/src/core/crypto/ecdsa.hpp @@ -72,6 +72,7 @@ public: * @retval OT_ERROR_NO_BUFS Output buffer is too small. * @retval OT_ERROR_INVALID_ARGS Private key is not valid EC Private Key. * @retval OT_ERROR_FAILED Error during signing. + * */ static otError Sign(uint8_t * aOutput, uint16_t * aOutputLength, diff --git a/src/core/crypto/hmac_sha256.cpp b/src/core/crypto/hmac_sha256.cpp index 17358b548..2d981c9d9 100644 --- a/src/core/crypto/hmac_sha256.cpp +++ b/src/core/crypto/hmac_sha256.cpp @@ -36,7 +36,7 @@ namespace ot { namespace Crypto { -HmacSha256::HmacSha256() +HmacSha256::HmacSha256(void) { const mbedtls_md_info_t *mdInfo = NULL; mbedtls_md_init(&mContext); @@ -44,7 +44,7 @@ HmacSha256::HmacSha256() mbedtls_md_setup(&mContext, mdInfo, 1); } -HmacSha256::~HmacSha256() +HmacSha256::~HmacSha256(void) { mbedtls_md_free(&mContext); } diff --git a/src/core/crypto/hmac_sha256.hpp b/src/core/crypto/hmac_sha256.hpp index fe28d3f2f..ed3a84471 100644 --- a/src/core/crypto/hmac_sha256.hpp +++ b/src/core/crypto/hmac_sha256.hpp @@ -66,13 +66,13 @@ public: * Constructor for initialization of mbedtls_md_context_t. * */ - HmacSha256(); + HmacSha256(void); /** * Destructor for freeing of mbedtls_md_context_t. * */ - ~HmacSha256(); + ~HmacSha256(void); /** * This method sets the key. diff --git a/src/core/crypto/mbedtls.cpp b/src/core/crypto/mbedtls.cpp index 827c3602a..58b183c4e 100644 --- a/src/core/crypto/mbedtls.cpp +++ b/src/core/crypto/mbedtls.cpp @@ -74,11 +74,11 @@ MbedTls::MbedTls(void) #endif // !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT } -otError MbedTls::MapError(int rval) +otError MbedTls::MapError(int aMbedTlsError) { otError error = OT_ERROR_NONE; - switch (rval) + switch (aMbedTlsError) { #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED case MBEDTLS_ERR_PK_TYPE_MISMATCH: @@ -154,7 +154,7 @@ otError MbedTls::MapError(int rval) break; default: - OT_ASSERT(rval >= 0); + OT_ASSERT(aMbedTlsError >= 0); break; } diff --git a/src/core/crypto/mbedtls.hpp b/src/core/crypto/mbedtls.hpp index 697e7b96c..b2df719c2 100644 --- a/src/core/crypto/mbedtls.hpp +++ b/src/core/crypto/mbedtls.hpp @@ -64,9 +64,14 @@ public: MbedTls(void); /** - * This method converts from MbedTls error to OpenThread error. + * This method converts an mbed TLS error to OpenThread error. + * + * @param[in] aMbedTlsError The mbed TLS error. + * + * @returns The mapped otError. + * */ - static otError MapError(int rval); + static otError MapError(int aMbedTlsError); }; /** diff --git a/src/core/crypto/sha256.cpp b/src/core/crypto/sha256.cpp index 6ca028ef7..5715192c7 100644 --- a/src/core/crypto/sha256.cpp +++ b/src/core/crypto/sha256.cpp @@ -36,12 +36,12 @@ namespace ot { namespace Crypto { -Sha256::Sha256() +Sha256::Sha256(void) { mbedtls_sha256_init(&mContext); } -Sha256::~Sha256() +Sha256::~Sha256(void) { mbedtls_sha256_free(&mContext); } diff --git a/src/core/crypto/sha256.hpp b/src/core/crypto/sha256.hpp index a5efedaff..ab7ed6818 100644 --- a/src/core/crypto/sha256.hpp +++ b/src/core/crypto/sha256.hpp @@ -66,13 +66,13 @@ public: * Constructor for initializing mbedtls_sha256_context. * */ - Sha256(); + Sha256(void); /** * Destructor for freeing mbedtls_sha256_context. * */ - ~Sha256(); + ~Sha256(void); /** * This method starts the SHA-256 computation.