diff options
author | Tommy Chiu <tommychiu@google.com> | 2021-09-23 20:09:13 +0800 |
---|---|---|
committer | Tommy Chiu <tommychiu@google.com> | 2021-09-29 21:08:58 +0800 |
commit | e6f9ff6c192ef82d4731c589b222adae9a50ab15 (patch) | |
tree | 3e548dc515e0d7121055a63e89665ef6be548dc7 /security/keymint/aidl/vts/functional/KeyMintTest.cpp | |
parent | 7a0dff749294bf9034be5111589837031cbf8b5d (diff) |
Add EncryptionOperationsTest.AesCbcZeroInputSuccess
Check if the zero input data with AES-CBC-[NONE|PKCS7] padding mode
generates correct output data and length.
Bug: 200553873
Test: VtsHalKeymasterV4_0TargetTest, VtsAidlKeyMintTargetTest
Change-Id: I729c2bad65e9d8b194422032346e5ee3c4b0dce5
Diffstat (limited to 'security/keymint/aidl/vts/functional/KeyMintTest.cpp')
-rw-r--r-- | security/keymint/aidl/vts/functional/KeyMintTest.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/security/keymint/aidl/vts/functional/KeyMintTest.cpp b/security/keymint/aidl/vts/functional/KeyMintTest.cpp index 2a0ee7fd3e..4eaa8d2c22 100644 --- a/security/keymint/aidl/vts/functional/KeyMintTest.cpp +++ b/security/keymint/aidl/vts/functional/KeyMintTest.cpp @@ -4665,6 +4665,49 @@ TEST_P(EncryptionOperationsTest, AesCbcRoundTripSuccess) { } /* + * EncryptionOperationsTest.AesCbcZeroInputSuccessb + * + * Verifies that keymaster generates correct output on zero-input with + * NonePadding mode + */ +TEST_P(EncryptionOperationsTest, AesCbcZeroInputSuccess) { + ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() + .Authorization(TAG_NO_AUTH_REQUIRED) + .AesEncryptionKey(128) + .BlockMode(BlockMode::CBC) + .Padding(PaddingMode::NONE, PaddingMode::PKCS7))); + + // Zero input message + string message = ""; + for (auto padding : {PaddingMode::NONE, PaddingMode::PKCS7}) { + auto params = AuthorizationSetBuilder().BlockMode(BlockMode::CBC).Padding(padding); + AuthorizationSet out_params; + string ciphertext1 = EncryptMessage(message, params, &out_params); + vector<uint8_t> iv1 = CopyIv(out_params); + if (padding == PaddingMode::NONE) + EXPECT_EQ(message.size(), ciphertext1.size()) << "PaddingMode: " << padding; + else + EXPECT_EQ(message.size(), ciphertext1.size() - 16) << "PaddingMode: " << padding; + + out_params.Clear(); + + string ciphertext2 = EncryptMessage(message, params, &out_params); + vector<uint8_t> iv2 = CopyIv(out_params); + if (padding == PaddingMode::NONE) + EXPECT_EQ(message.size(), ciphertext2.size()) << "PaddingMode: " << padding; + else + EXPECT_EQ(message.size(), ciphertext2.size() - 16) << "PaddingMode: " << padding; + + // IVs should be random + EXPECT_NE(iv1, iv2) << "PaddingMode: " << padding; + + params.push_back(TAG_NONCE, iv1); + string plaintext = DecryptMessage(ciphertext1, params); + EXPECT_EQ(message, plaintext) << "PaddingMode: " << padding; + } +} + +/* * EncryptionOperationsTest.AesCallerNonce * * Verifies that AES caller-provided nonces work correctly. |