From 99bd1df99b2ada05877f36f85ff2f7f37e176fd6 Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Thu, 3 Apr 2025 09:57:44 -0700 Subject: [PATCH] Remove MAC truncation from FIPS interface. This is only valid in ACVP if the truncation occurs within the FIPS module. But that's not a useful service: the caller can always discard a few bytes and is better positioned to do so. Change-Id: Id5e6459c9fa6d8b1b8f7a398feab6c4816adf8ab Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/78247 Commit-Queue: Adam Langley Auto-Submit: Adam Langley Reviewed-by: Bob Beck --- .../acvp/acvptool/subprocess/hmac.go | 6 ++-- .../acvp/modulewrapper/modulewrapper.cc | 34 +++++-------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/util/fipstools/acvp/acvptool/subprocess/hmac.go b/util/fipstools/acvp/acvptool/subprocess/hmac.go index 3273f3ce9..e4d5e405c 100644 --- a/util/fipstools/acvp/acvptool/subprocess/hmac.go +++ b/util/fipstools/acvp/acvptool/subprocess/hmac.go @@ -119,14 +119,14 @@ func (h *hmacPrimitive) Process(vectorSet []byte, m Transactable) (any, error) { } m.TransactAsync(h.algo, 1, [][]byte{msg, key}, func(result [][]byte) error { - if l := len(result[0]); l < outBytes { - return fmt.Errorf("HMAC result too short: %d bytes but wanted %d", l, outBytes) + if l := len(result[0]); l != outBytes { + return fmt.Errorf("incorrect HMAC length: %d bytes but wanted %d", l, outBytes) } // https://pages.nist.gov/ACVP/draft-fussell-acvp-mac.html#name-test-vectors response.Tests = append(response.Tests, hmacTestResponse{ ID: test.ID, - MACHex: hex.EncodeToString(result[0][:outBytes]), + MACHex: hex.EncodeToString(result[0]), }) return nil }) diff --git a/util/fipstools/acvp/modulewrapper/modulewrapper.cc b/util/fipstools/acvp/modulewrapper/modulewrapper.cc index 7f4d9fa0d..018aceb4b 100644 --- a/util/fipstools/acvp/modulewrapper/modulewrapper.cc +++ b/util/fipstools/acvp/modulewrapper/modulewrapper.cc @@ -442,9 +442,7 @@ static bool GetConfig(const Span args[], "keyLen": [{ "min": 8, "max": 524288, "increment": 8 }], - "macLen": [{ - "min": 32, "max": 160, "increment": 8 - }] + "macLen": [160] }, { "algorithm": "HMAC-SHA2-224", @@ -452,9 +450,7 @@ static bool GetConfig(const Span args[], "keyLen": [{ "min": 8, "max": 524288, "increment": 8 }], - "macLen": [{ - "min": 32, "max": 224, "increment": 8 - }] + "macLen": [224] }, { "algorithm": "HMAC-SHA2-256", @@ -462,9 +458,7 @@ static bool GetConfig(const Span args[], "keyLen": [{ "min": 8, "max": 524288, "increment": 8 }], - "macLen": [{ - "min": 32, "max": 256, "increment": 8 - }] + "macLen": [256] }, { "algorithm": "HMAC-SHA2-384", @@ -472,9 +466,7 @@ static bool GetConfig(const Span args[], "keyLen": [{ "min": 8, "max": 524288, "increment": 8 }], - "macLen": [{ - "min": 32, "max": 384, "increment": 8 - }] + "macLen": [384] }, { "algorithm": "HMAC-SHA2-512", @@ -482,9 +474,7 @@ static bool GetConfig(const Span args[], "keyLen": [{ "min": 8, "max": 524288, "increment": 8 }], - "macLen": [{ - "min": 32, "max": 512, "increment": 8 - }] + "macLen": [512] }, { "algorithm": "HMAC-SHA2-512/256", @@ -492,9 +482,7 @@ static bool GetConfig(const Span args[], "keyLen": [{ "min": 8, "max": 524288, "increment": 8 }], - "macLen": [{ - "min": 32, "max": 256, "increment": 8 - }] + "macLen": [256] }, { "algorithm": "ctrDRBG", @@ -848,11 +836,7 @@ static bool GetConfig(const Span args[], "increment": 8 }], "keyLen": [128, 256], - "macLen": [{ - "min": 8, - "max": 128, - "increment": 8 - }] + "macLen": [128] }] }, { @@ -1966,11 +1950,11 @@ static bool CMAC_AES(const Span args[], return false; } memcpy(&mac_len, args[0].data(), sizeof(mac_len)); - if (mac_len > sizeof(mac)) { + if (mac_len != sizeof(mac)) { return false; } - return write_reply({Span(mac, mac_len)}); + return write_reply({Span(mac, sizeof(mac))}); } static bool CMAC_AESVerify(const Span args[],