Skip to content

Commit 3c3e4a1

Browse files
Add support for HMAC-SHA3 to ACVP tool (#2866)
### Description of changes: Recent ACVP testing has uncovered that we don't support HMAC-SHA3 through our ACVP harness. One thing to note is that HMAC-SHA3 does not support precomputed keys as seen in 80f986b. I've added additional logic to work around this. ### Call-outs: This will be cherry-picked over to FIPS branch once in main. ### Testing: Took new HMAC-SHA3 vectors from demo vectors and ran `trim_vectors.go` on them. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent 5188ef8 commit 3c3e4a1

File tree

9 files changed

+62
-14
lines changed

9 files changed

+62
-14
lines changed
720 Bytes
Binary file not shown.
785 Bytes
Binary file not shown.
1005 Bytes
Binary file not shown.
1.2 KB
Binary file not shown.
205 KB
Binary file not shown.
260 KB
Binary file not shown.
255 KB
Binary file not shown.
248 KB
Binary file not shown.

util/fipstools/acvp/modulewrapper/modulewrapper.cc

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,46 @@ static bool GetConfig(const Span<const uint8_t> args[],
492492
"min": 32, "max": 256, "increment": 8
493493
}]
494494
},
495+
{
496+
"algorithm": "HMAC-SHA3-224",
497+
"revision": "1.0",
498+
"keyLen": [{
499+
"min": 8, "max": 524288, "increment": 8
500+
}],
501+
"macLen": [{
502+
"min": 32, "max": 224, "increment": 8
503+
}]
504+
},
505+
{
506+
"algorithm": "HMAC-SHA3-256",
507+
"revision": "1.0",
508+
"keyLen": [{
509+
"min": 8, "max": 524288, "increment": 8
510+
}],
511+
"macLen": [{
512+
"min": 32, "max": 256, "increment": 8
513+
}]
514+
},
515+
{
516+
"algorithm": "HMAC-SHA3-384",
517+
"revision": "1.0",
518+
"keyLen": [{
519+
"min": 8, "max": 524288, "increment": 8
520+
}],
521+
"macLen": [{
522+
"min": 32, "max": 384, "increment": 8
523+
}]
524+
},
525+
{
526+
"algorithm": "HMAC-SHA3-512",
527+
"revision": "1.0",
528+
"keyLen": [{
529+
"min": 8, "max": 524288, "increment": 8
530+
}],
531+
"macLen": [{
532+
"min": 32, "max": 512, "increment": 8
533+
}]
534+
},
495535
{
496536
"vsId": 0,
497537
"algorithm": "PBKDF",
@@ -2275,21 +2315,25 @@ static bool HMAC(const Span<const uint8_t> args[], ReplyCallback write_reply) {
22752315
return false;
22762316
}
22772317

2278-
// HMAC computation with precomputed keys
2279-
// The purpose of this call is to test |HMAC_set_precomputed_key_export| and
2280-
// |HMAC_get_precomputed_key|, which are called by |HMAC_with_precompute|.
2281-
uint8_t digest_with_precompute[EVP_MAX_MD_SIZE];
2282-
unsigned digest_with_precompute_len;
2283-
if (::HMAC_with_precompute(md, args[1].data(), args[1].size(), args[0].data(),
2284-
args[0].size(), digest_with_precompute,
2285-
&digest_with_precompute_len) == nullptr) {
2286-
return false;
2287-
}
2318+
// SHA3 does not support pre-computed keys. See aws/aws-lc@80f986b.
2319+
if (md != EVP_sha3_224() && md != EVP_sha3_256() && md != EVP_sha3_384() &&
2320+
md != EVP_sha3_512()) {
2321+
// HMAC computation with precomputed keys
2322+
// The purpose of this call is to test |HMAC_set_precomputed_key_export| and
2323+
// |HMAC_get_precomputed_key|, which are called by |HMAC_with_precompute|.
2324+
uint8_t digest_with_precompute[EVP_MAX_MD_SIZE];
2325+
unsigned digest_with_precompute_len;
2326+
if (::HMAC_with_precompute(md, args[1].data(), args[1].size(), args[0].data(),
2327+
args[0].size(), digest_with_precompute,
2328+
&digest_with_precompute_len) == nullptr) {
2329+
return false;
2330+
}
22882331

2289-
// The two HMAC computations must yield exactly the same results
2290-
if (digest_len != digest_with_precompute_len ||
2291-
memcmp(digest, digest_with_precompute, digest_len) != 0) {
2292-
return false;
2332+
// The two HMAC computations must yield exactly the same results
2333+
if (digest_len != digest_with_precompute_len ||
2334+
memcmp(digest, digest_with_precompute, digest_len) != 0) {
2335+
return false;
2336+
}
22932337
}
22942338

22952339
return write_reply({Span<const uint8_t>(digest, digest_len)});
@@ -3462,6 +3506,10 @@ static struct {
34623506
{"HMAC-SHA2-512", 2, HMAC<EVP_sha512>},
34633507
{"HMAC-SHA2-512/224", 2, HMAC<EVP_sha512_224>},
34643508
{"HMAC-SHA2-512/256", 2, HMAC<EVP_sha512_256>},
3509+
{"HMAC-SHA3-224", 2, HMAC<EVP_sha3_224>},
3510+
{"HMAC-SHA3-256", 2, HMAC<EVP_sha3_256>},
3511+
{"HMAC-SHA3-384", 2, HMAC<EVP_sha3_384>},
3512+
{"HMAC-SHA3-512", 2, HMAC<EVP_sha3_512>},
34653513
{"ctrDRBG/AES-256", 6, DRBG<false>},
34663514
{"ctrDRBG-reseed/AES-256", 8, DRBG<true>},
34673515
{"ECDSA/keyGen", 1, ECDSAKeyGen},

0 commit comments

Comments
 (0)