Skip to content

Commit aa1bc95

Browse files
committed
update call pattern for CRT AES
1 parent 053e82c commit aa1bc95

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/aws-cpp-sdk-core/source/utils/crypto/crt/CRTSymmetricCipher.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ namespace Aws
8585

8686
void CRTSymmetricCipher::Reset()
8787
{
88+
m_lastFetchedTag = GetTag();
8889
m_cipher.Reset();
90+
m_cipher.SetTag(Crt::ByteCursorFromArray(m_lastFetchedTag.GetUnderlyingData(), m_lastFetchedTag.GetLength()));
8991
}
9092

9193
bool CRTSymmetricCipher::Good() const

src/aws-cpp-sdk-core/source/utils/crypto/factory/Factories.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ class DefaultAES_GCMFactory : public SymmetricCipherFactory
376376
if (aad)
377377
{
378378
auto aadCur = Aws::Crt::ByteCursorFromArray(aad->GetUnderlyingData(), aad->GetLength());
379-
return Aws::MakeShared<CRTSymmetricCipher>(s_allocationTag, Aws::Crt::Crypto::SymmetricCipher::CreateAES_256_GCM_Cipher(keyCur, Aws::Crt::Optional<Aws::Crt::ByteCursor>(), Aws::Crt::Optional<Aws::Crt::ByteCursor>(), aadCur));
379+
const auto cipher = Aws::MakeShared<CRTSymmetricCipher>(s_allocationTag,
380+
Aws::Crt::Crypto::SymmetricCipher::CreateAES_256_GCM_Cipher(keyCur,
381+
Aws::Crt::Optional<Aws::Crt::ByteCursor>(),
382+
aadCur));
383+
return cipher;
380384
}
381385

382386
return Aws::MakeShared<CRTSymmetricCipher>(s_allocationTag, Aws::Crt::Crypto::SymmetricCipher::CreateAES_256_GCM_Cipher(keyCur));
@@ -398,7 +402,12 @@ class DefaultAES_GCMFactory : public SymmetricCipherFactory
398402
Aws::Crt::Optional<Aws::Crt::ByteCursor> tagCur = tag.GetLength() > 0 ? Aws::Crt::ByteCursorFromArray(tag.GetUnderlyingData(), tag.GetLength()) : Aws::Crt::Optional<Aws::Crt::ByteCursor>();
399403
Aws::Crt::Optional<Aws::Crt::ByteCursor> aadCur = aad.GetLength() > 0 ? Aws::Crt::ByteCursorFromArray(aad.GetUnderlyingData(), aad.GetLength()) : Aws::Crt::Optional<Aws::Crt::ByteCursor>();
400404

401-
return Aws::MakeShared<CRTSymmetricCipher>(s_allocationTag, Aws::Crt::Crypto::SymmetricCipher::CreateAES_256_GCM_Cipher(keyCur, ivCur, tagCur, aadCur));
405+
auto cipher = Aws::Crt::Crypto::SymmetricCipher::CreateAES_256_GCM_Cipher(keyCur, ivCur, aadCur);
406+
if (cipher && tagCur.has_value())
407+
{
408+
cipher.SetTag(tagCur.value());
409+
}
410+
return Aws::MakeShared<CRTSymmetricCipher>(s_allocationTag, std::move(cipher));
402411
#else
403412
AWS_UNREFERENCED_PARAM(key);
404413
AWS_UNREFERENCED_PARAM(iv);

tests/aws-cpp-sdk-core-tests/utils/crypto/SymmetricCiphersTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ TEST_F(AES_GCM_TEST, TestBadTagCausesFailure)
270270
ASSERT_TRUE(*cipher);
271271

272272
const_cast<CryptoBuffer&>(cipher->GetTag())[8] = 0;
273-
274273
cipher->Reset();
275274
auto decryptResult = cipher->DecryptBuffer(encryptedResult);
276275
auto finalDecryptBuffer = cipher->FinalizeDecryption();
276+
ASSERT_FALSE(*cipher);
277277
ASSERT_EQ(0u, finalDecryptBuffer.GetLength());
278278
}
279279

0 commit comments

Comments
 (0)