diff options
Diffstat (limited to 'security/keymint/aidl/vts/functional/KeyMintTest.cpp')
-rw-r--r-- | security/keymint/aidl/vts/functional/KeyMintTest.cpp | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/security/keymint/aidl/vts/functional/KeyMintTest.cpp b/security/keymint/aidl/vts/functional/KeyMintTest.cpp index 217ea0e847..3f33686119 100644 --- a/security/keymint/aidl/vts/functional/KeyMintTest.cpp +++ b/security/keymint/aidl/vts/functional/KeyMintTest.cpp @@ -4951,6 +4951,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. @@ -6591,7 +6634,7 @@ TEST_P(ClearOperationsTest, TooManyOperations) { size_t i; for (i = 0; i < max_operations; i++) { - result = Begin(KeyPurpose::ENCRYPT, key_blob_, params, &out_params, op_handles[i]); + result = Begin(KeyPurpose::DECRYPT, key_blob_, params, &out_params, op_handles[i]); if (ErrorCode::OK != result) { break; } @@ -6599,12 +6642,12 @@ TEST_P(ClearOperationsTest, TooManyOperations) { EXPECT_EQ(ErrorCode::TOO_MANY_OPERATIONS, result); // Try again just in case there's a weird overflow bug EXPECT_EQ(ErrorCode::TOO_MANY_OPERATIONS, - Begin(KeyPurpose::ENCRYPT, key_blob_, params, &out_params)); + Begin(KeyPurpose::DECRYPT, key_blob_, params, &out_params)); for (size_t j = 0; j < i; j++) { EXPECT_EQ(ErrorCode::OK, Abort(op_handles[j])) << "Aboort failed for i = " << j << std::endl; } - EXPECT_EQ(ErrorCode::OK, Begin(KeyPurpose::ENCRYPT, key_blob_, params, &out_params)); + EXPECT_EQ(ErrorCode::OK, Begin(KeyPurpose::DECRYPT, key_blob_, params, &out_params)); AbortIfNeeded(); } |