Skip to content

Commit

Permalink
[style] Remove magic words.
Browse files Browse the repository at this point in the history
  • Loading branch information
turon committed Aug 23, 2022
1 parent 3c76544 commit cc70c1c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/crypto/CHIPCryptoPAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/crypto/CHIPCryptoPAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/tests/CHIPCryptoPALTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit cc70c1c

Please sign in to comment.