Skip to content
Snippets Groups Projects
Commit b6b60368 authored by Tink Team's avatar Tink Team Committed by Tink Team
Browse files

Validate HMAC key should validate size of HMAC key.

PiperOrigin-RevId: 200519180
GitOrigin-RevId: 4b11835ad9925c2635acb4814f840678fae23d67
parent 7c814aa0
No related branches found
No related tags found
No related merge requests found
......@@ -254,7 +254,7 @@ Status AesCtrHmacAeadKeyManager::Validate(
// Validate HmacKeyFormat.
auto hmac_key_format = key_format.hmac_key_format();
if (aes_ctr_key_format.key_size() < kMinKeySizeInBytes) {
if (hmac_key_format.key_size() < kMinKeySizeInBytes) {
return ToStatusF(
util::error::INVALID_ARGUMENT,
"Invalid AesCtrHmacAeadKeyFormat: HMAC key_size is too small.");
......
......@@ -274,6 +274,18 @@ TEST_F(AesCtrHmacAeadKeyManagerTest, testNewKeyErrors) {
EXPECT_PRED_FORMAT2(testing::IsSubstring, "too small",
result.status().error_message());
}
{ // Bad AesCtrHmacAeadKeyFormat: small HMAC key_size.
AesCtrHmacAeadKeyFormat key_format;
key_format.mutable_hmac_key_format()->set_key_size(8);
auto result = key_factory.NewKey(key_format);
EXPECT_FALSE(result.ok());
EXPECT_EQ(util::error::INVALID_ARGUMENT, result.status().error_code());
EXPECT_PRED_FORMAT2(testing::IsSubstring, "key_size",
result.status().error_message());
EXPECT_PRED_FORMAT2(testing::IsSubstring, "too small",
result.status().error_message());
}
}
TEST_F(AesCtrHmacAeadKeyManagerTest, testNewKeyBasic) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment