From cc70c1c901b0cc8a6082b318f6bd3a9e0f8c4ed0 Mon Sep 17 00:00:00 2001 From: Martin Turon Date: Tue, 23 Aug 2022 17:02:46 +0000 Subject: [PATCH] [style] Remove magic words. --- src/crypto/CHIPCryptoPAL.cpp | 2 +- src/crypto/CHIPCryptoPAL.h | 8 +++++--- src/crypto/tests/CHIPCryptoPALTest.cpp | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/crypto/CHIPCryptoPAL.cpp b/src/crypto/CHIPCryptoPAL.cpp index 4fa157c0ef7ae1..4a878eecfc5eeb 100644 --- a/src/crypto/CHIPCryptoPAL.cpp +++ b/src/crypto/CHIPCryptoPAL.cpp @@ -710,7 +710,7 @@ CHIP_ERROR AES_CTR_crypt(const uint8_t * input, size_t input_length, const uint8 size_t nonce_length, uint8_t * output) { // Discard tag portion of CCM to apply only CTR mode encryption/decryption. - constexpr size_t kTagLen = 16; + constexpr size_t kTagLen = Crypto::kAES_CCM128_Tag_Length; uint8_t tag[kTagLen]; return AES_CCM_encrypt(input, input_length, nullptr, 0, key, key_length, nonce, nonce_length, output, tag, kTagLen); diff --git a/src/crypto/CHIPCryptoPAL.h b/src/crypto/CHIPCryptoPAL.h index 66aa904d9b68d9..3882e1f64b07d7 100644 --- a/src/crypto/CHIPCryptoPAL.h +++ b/src/crypto/CHIPCryptoPAL.h @@ -78,6 +78,8 @@ constexpr size_t kP256_PublicKey_Length = CHIP_CRYPTO_PUBLIC_KEY_SIZE_BYTES; constexpr size_t kAES_CCM128_Key_Length = 128u / 8u; constexpr size_t kAES_CCM128_Block_Length = kAES_CCM128_Key_Length; +constexpr size_t kAES_CCM128_Nonce_Length = 13; +constexpr size_t kAES_CCM128_Tag_Length = 16; /* These sizes are hardcoded here to remove header dependency on underlying crypto library * in a public interface file. The validity of these sizes is verified by static_assert in @@ -622,9 +624,9 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_length, * @brief A function that implements AES-CCM decryption * * This implements the AES-CTR-Encrypt/Decrypt() cryptographic primitives per sections - * 3.7.1 and 3.7.2 of the specification. For an empty ciphertext, the user of the API - * can provide an empty string, or a nullptr, and provide ciphertext_length as 0. - * The output buffer, plaintext can also be an empty string, or a nullptr for this case. + * 3.7.1 and 3.7.2 of the specification. For an empty input, the user of the API + * can provide an empty string, or a nullptr, and provide input as 0. + * The output buffer can also be an empty string, or a nullptr for this case. * * @param input Input text to encrypt/decrypt * @param input_length Length of ciphertext diff --git a/src/crypto/tests/CHIPCryptoPALTest.cpp b/src/crypto/tests/CHIPCryptoPALTest.cpp index a0106761aa79da..c261d5c943b903 100644 --- a/src/crypto/tests/CHIPCryptoPALTest.cpp +++ b/src/crypto/tests/CHIPCryptoPALTest.cpp @@ -202,8 +202,8 @@ const AesCtrTestEntry theAesCtrTestVector[] = { constexpr size_t kAesCtrTestVectorSize = sizeof(theAesCtrTestVector) / sizeof(theAesCtrTestVector[0]); -constexpr size_t KEY_LENGTH = 16; -constexpr size_t NONCE_LENGTH = 13; +constexpr size_t KEY_LENGTH = Crypto::kAES_CCM128_Key_Length; +constexpr size_t NONCE_LENGTH = Crypto::kAES_CCM128_Nonce_Length; static void TestAES_CTR_128_Encrypt(nlTestSuite * inSuite, const AesCtrTestEntry * vector) {