Merge "Added LargeFinishInput test"
This commit is contained in:
commit
0cd9dd3893
1 changed files with 51 additions and 0 deletions
|
@ -4604,6 +4604,57 @@ TEST_F(ClearOperationsTest, ServiceDeath) {
|
|||
}
|
||||
}
|
||||
|
||||
typedef KeymasterHidlTest TransportLimitTest;
|
||||
|
||||
/*
|
||||
* TransportLimitTest.LargeFinishInput
|
||||
*
|
||||
* Verifies that passing large input data to finish either succeeds or fails as expected.
|
||||
*/
|
||||
TEST_F(TransportLimitTest, LargeFinishInput) {
|
||||
ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
|
||||
.Authorization(TAG_NO_AUTH_REQUIRED)
|
||||
.AesEncryptionKey(128)
|
||||
.BlockMode(BlockMode::ECB)
|
||||
.Padding(PaddingMode::NONE)));
|
||||
|
||||
for (int msg_size = 10 /*1KB*/; msg_size <= 17 /*128KB*/; msg_size++) {
|
||||
auto cipher_params =
|
||||
AuthorizationSetBuilder().BlockMode(BlockMode::ECB).Padding(PaddingMode::NONE);
|
||||
|
||||
AuthorizationSet out_params;
|
||||
EXPECT_EQ(ErrorCode::OK, Begin(KeyPurpose::ENCRYPT, cipher_params, &out_params));
|
||||
|
||||
string plain_message = std::string(1 << msg_size, 'x');
|
||||
string encrypted_message;
|
||||
auto rc = Finish(plain_message, &encrypted_message);
|
||||
|
||||
if (rc == ErrorCode::OK) {
|
||||
EXPECT_EQ(plain_message.size(), encrypted_message.size())
|
||||
<< "Encrypt finish returned OK, but did not consume all of the given input";
|
||||
} else {
|
||||
EXPECT_EQ(ErrorCode::INVALID_INPUT_LENGTH, rc)
|
||||
<< "Encrypt finish failed in an unexpected way when given a large input";
|
||||
continue;
|
||||
}
|
||||
cipher_params.push_back(out_params);
|
||||
|
||||
EXPECT_EQ(ErrorCode::OK, Begin(KeyPurpose::DECRYPT, cipher_params));
|
||||
|
||||
string decrypted_message;
|
||||
rc = Finish(encrypted_message, &decrypted_message);
|
||||
|
||||
if (rc == ErrorCode::OK) {
|
||||
EXPECT_EQ(plain_message.size(), decrypted_message.size())
|
||||
<< "Decrypt finish returned OK, did not consume all of the given input";
|
||||
} else {
|
||||
EXPECT_EQ(ErrorCode::INVALID_INPUT_LENGTH, rc)
|
||||
<< "Encrypt finish failed in an unexpected way when given a large input";
|
||||
}
|
||||
}
|
||||
|
||||
CheckedDeleteKey();
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace V4_0
|
||||
|
|
Loading…
Reference in a new issue