Skip to content

Commit 0580e2a

Browse files
cpugopherbot
authored andcommitted
crypto/internal/fips140test: add KDA HKDF ACVP tests
Adds ACVP test coverage for the SP 800-56Crev2 HKDF KDA based on the NIST spec: https://pages.nist.gov/ACVP/draft-hammett-acvp-kas-kdf-hkdf.html Updates #69642 Change-Id: Ie4f48f9b0181eaf6c2201a9796d366a31c474eba Reviewed-on: https://go-review.googlesource.com/c/go/+/636115 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> Auto-Submit: Filippo Valsorda <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]>
1 parent 035d3c8 commit 0580e2a

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/crypto/internal/fips140test/acvp_capabilities.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
{"algorithm":"HMAC-SHA3-384","keyLen":[{"increment":8,"max":524288,"min":8}],"macLen":[{"increment":8,"max":384,"min":32}],"revision":"1.0"},
2727
{"algorithm":"HMAC-SHA3-512","keyLen":[{"increment":8,"max":524288,"min":8}],"macLen":[{"increment":8,"max":512,"min":32}],"revision":"1.0"},
2828

29+
{"algorithm":"KDA","mode":"HKDF","revision":"Sp800-56Cr1","fixedInfoPattern":"uPartyInfo||vPartyInfo","encoding":["concatenation"],"hmacAlg":["SHA2-224","SHA2-256","SHA2-384","SHA2-512","SHA2-512/224","SHA2-512/256","SHA3-224","SHA3-256","SHA3-384","SHA3-512"],"macSaltMethods":["default","random"],"l":2048,"z":[{"min":224,"max":65336,"increment":8}]},
30+
2931
{"algorithm":"PBKDF","capabilities":[{"iterationCount":[{"min":1,"max":10000,"increment":1}],"keyLen":[{"min":112,"max":4096,"increment":8}],"passwordLen":[{"min":8,"max":64,"increment":1}],"saltLen":[{"min":128,"max":512,"increment":8}],"hmacAlg":["SHA2-224","SHA2-256","SHA2-384","SHA2-512","SHA2-512/224","SHA2-512/256","SHA3-224","SHA3-256","SHA3-384","SHA3-512"]}],"revision":"1.0"},
3032

3133
{"algorithm":"ML-KEM","mode":"keyGen","revision":"FIPS203","parameterSets":["ML-KEM-768","ML-KEM-1024"]},

src/crypto/internal/fips140test/acvp_test.config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
{"Wrapper": "go", "In": "vectors/HMAC-SHA2-512-224.bz2", "Out": "expected/HMAC-SHA2-512-224.bz2"},
2222
{"Wrapper": "go", "In": "vectors/HMAC-SHA2-512-256.bz2", "Out": "expected/HMAC-SHA2-512-256.bz2"},
2323

24+
{"Wrapper": "go", "In": "vectors/KDA.bz2", "Out": "expected/KDA.bz2"},
25+
2426
{"Wrapper": "go", "In": "vectors/HMAC-SHA3-224.bz2", "Out": "expected/HMAC-SHA3-224.bz2"},
2527
{"Wrapper": "go", "In": "vectors/HMAC-SHA3-256.bz2", "Out": "expected/HMAC-SHA3-256.bz2"},
2628
{"Wrapper": "go", "In": "vectors/HMAC-SHA3-384.bz2", "Out": "expected/HMAC-SHA3-384.bz2"},
@@ -41,4 +43,4 @@
4143
{"Wrapper": "go", "In": "vectors/ACVP-AES-GCM.bz2", "Out": "expected/ACVP-AES-GCM.bz2"},
4244

4345
{"Wrapper": "go", "In": "vectors/CMAC-AES.bz2", "Out": "expected/CMAC-AES.bz2"}
44-
]
46+
]

src/crypto/internal/fips140test/acvp_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"crypto/internal/fips140/ecdsa"
3030
"crypto/internal/fips140/ed25519"
3131
"crypto/internal/fips140/edwards25519"
32+
"crypto/internal/fips140/hkdf"
3233
"crypto/internal/fips140/hmac"
3334
"crypto/internal/fips140/mlkem"
3435
"crypto/internal/fips140/pbkdf2"
@@ -111,6 +112,8 @@ var (
111112
// https://pages.nist.gov/ACVP/draft-fussell-acvp-ecdsa.html#section-7
112113
// AES algorithm capabilities:
113114
// https://pages.nist.gov/ACVP/draft-celi-acvp-symmetric.html#section-7.3
115+
// HKDF KDA algorithm capabilities:
116+
// https://pages.nist.gov/ACVP/draft-hammett-acvp-kas-kdf-hkdf.html#section-7.3
114117
//go:embed acvp_capabilities.json
115118
capabilitiesJson []byte
116119

@@ -164,6 +167,17 @@ var (
164167
"HMAC-SHA3-384": cmdHmacAft(func() fips140.Hash { return sha3.New384() }),
165168
"HMAC-SHA3-512": cmdHmacAft(func() fips140.Hash { return sha3.New512() }),
166169

170+
"HKDF/SHA2-224": cmdHkdfAft(func() fips140.Hash { return sha256.New224() }),
171+
"HKDF/SHA2-256": cmdHkdfAft(func() fips140.Hash { return sha256.New() }),
172+
"HKDF/SHA2-384": cmdHkdfAft(func() fips140.Hash { return sha512.New384() }),
173+
"HKDF/SHA2-512": cmdHkdfAft(func() fips140.Hash { return sha512.New() }),
174+
"HKDF/SHA2-512/224": cmdHkdfAft(func() fips140.Hash { return sha512.New512_224() }),
175+
"HKDF/SHA2-512/256": cmdHkdfAft(func() fips140.Hash { return sha512.New512_256() }),
176+
"HKDF/SHA3-224": cmdHkdfAft(func() fips140.Hash { return sha3.New224() }),
177+
"HKDF/SHA3-256": cmdHkdfAft(func() fips140.Hash { return sha3.New256() }),
178+
"HKDF/SHA3-384": cmdHkdfAft(func() fips140.Hash { return sha3.New384() }),
179+
"HKDF/SHA3-512": cmdHkdfAft(func() fips140.Hash { return sha3.New512() }),
180+
167181
"PBKDF": cmdPbkdf(),
168182

169183
"ML-KEM-768/keyGen": cmdMlKem768KeyGenAft(),
@@ -500,6 +514,20 @@ func cmdHmacAft(h func() fips140.Hash) command {
500514
}
501515
}
502516

517+
func cmdHkdfAft(h func() fips140.Hash) command {
518+
return command{
519+
requiredArgs: 4, // Key, salt, info, length bytes
520+
handler: func(args [][]byte) ([][]byte, error) {
521+
key := args[0]
522+
salt := args[1]
523+
info := args[2]
524+
keyLen := int(binary.LittleEndian.Uint32(args[3]))
525+
526+
return [][]byte{hkdf.Key(h, key, salt, string(info), keyLen)}, nil
527+
},
528+
}
529+
}
530+
503531
func cmdPbkdf() command {
504532
return command{
505533
// Hash name, key length, salt, password, iteration count

0 commit comments

Comments
 (0)