Skip to content

Commit 47d0b0f

Browse files
cpugopherbot
authored andcommitted
crypto/internal/fips140test: add TLS-v1.3 ACVP tests
Adds ACVP test coverage for the SP 800-56Crev2 IG 2.4.B TLS v1.3 KDF based on the NIST spec: https://pages.nist.gov/ACVP/draft-hammett-acvp-kdf-tls-v1.3.html Only SHA2-256 and SHA2-384 are valid hash algorithms for the TLS1.3 KDF algorithm. The BoringSSL acvptool "lowers" the more complicated TLS 1.3 KDF ACVP test cases into simple invocations of our module wrapper's pre-existing HKDF commands, and the new "HKDFExtract/$HASH" and "HKDFExpandLabel/$HASH" commands added in this branch. Updates #69642 Change-Id: I5fb1af5b5b33c1845b27cf8968e6523e89bcc589 Reviewed-on: https://go-review.googlesource.com/c/go/+/636117 Reviewed-by: Roland Shoemaker <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Filippo Valsorda <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]>
1 parent 3310f32 commit 47d0b0f

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/crypto/internal/fips140test/acvp_capabilities.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@
6161
{"algorithm":"ACVP-AES-GCM","direction":["encrypt","decrypt"],"keyLen":[128,192,256],"payloadLen":[{"min":0,"max":65536,"increment":8}],"aadLen":[{"min":0,"max":65536,"increment":8}],"tagLen":[128],"ivLen":[96],"ivGen":"internal","ivGenMode":"8.2.2","revision":"1.0"},
6262
{"algorithm":"CMAC-AES","capabilities":[{"direction":["gen","ver"],"msgLen":[{"min":0,"max":524288,"increment":8}],"keyLen":[128,256],"macLen":[{"min":8,"max":128,"increment":8}]}],"revision":"1.0"},
6363

64-
{"algorithm":"TLS-v1.2","mode":"KDF","revision":"RFC7627","hashAlg":["SHA2-256","SHA2-384","SHA2-512"]}
64+
{"algorithm":"TLS-v1.2","mode":"KDF","revision":"RFC7627","hashAlg":["SHA2-256","SHA2-384","SHA2-512"]},
65+
{"algorithm":"TLS-v1.3","mode":"KDF","revision":"RFC8446","hmacAlg":["SHA2-256","SHA2-384"],"runningMode":["DHE","PSK","PSK-DHE"]}
6566
]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@
4444

4545
{"Wrapper": "go", "In": "vectors/CMAC-AES.bz2", "Out": "expected/CMAC-AES.bz2"},
4646

47-
{"Wrapper": "go", "In": "vectors/TLS-v1.2.bz2", "Out": "expected/TLS-v1.2.bz2"}
47+
{"Wrapper": "go", "In": "vectors/TLS-v1.2.bz2", "Out": "expected/TLS-v1.2.bz2"},
48+
{"Wrapper": "go", "In": "vectors/TLS-v1.3.bz2", "Out": "expected/TLS-v1.3.bz2"}
4849
]

src/crypto/internal/fips140test/acvp_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"crypto/internal/fips140/sha512"
3939
"crypto/internal/fips140/subtle"
4040
"crypto/internal/fips140/tls12"
41+
"crypto/internal/fips140/tls13"
4142
"crypto/rand"
4243
_ "embed"
4344
"encoding/binary"
@@ -117,6 +118,8 @@ var (
117118
// https://pages.nist.gov/ACVP/draft-hammett-acvp-kas-kdf-hkdf.html#section-7.3
118119
// TLS 1.2 KDF algorithm capabilities:
119120
// https://pages.nist.gov/ACVP/draft-celi-acvp-kdf-tls.html#section-7.2
121+
// TLS 1.3 KDF algorithm capabilities:
122+
// https://pages.nist.gov/ACVP/draft-hammett-acvp-kdf-tls-v1.3.html#section-7.2
120123
//go:embed acvp_capabilities.json
121124
capabilitiesJson []byte
122125

@@ -181,6 +184,11 @@ var (
181184
"HKDF/SHA3-384": cmdHkdfAft(func() fips140.Hash { return sha3.New384() }),
182185
"HKDF/SHA3-512": cmdHkdfAft(func() fips140.Hash { return sha3.New512() }),
183186

187+
"HKDFExtract/SHA2-256": cmdHkdfExtractAft(func() fips140.Hash { return sha256.New() }),
188+
"HKDFExtract/SHA2-384": cmdHkdfExtractAft(func() fips140.Hash { return sha512.New384() }),
189+
"HKDFExpandLabel/SHA2-256": cmdHkdfExpandLabelAft(func() fips140.Hash { return sha256.New() }),
190+
"HKDFExpandLabel/SHA2-384": cmdHkdfExpandLabelAft(func() fips140.Hash { return sha512.New384() }),
191+
184192
"PBKDF": cmdPbkdf(),
185193

186194
"ML-KEM-768/keyGen": cmdMlKem768KeyGenAft(),
@@ -537,6 +545,32 @@ func cmdHkdfAft(h func() fips140.Hash) command {
537545
}
538546
}
539547

548+
func cmdHkdfExtractAft(h func() fips140.Hash) command {
549+
return command{
550+
requiredArgs: 2, // secret, salt
551+
handler: func(args [][]byte) ([][]byte, error) {
552+
secret := args[0]
553+
salt := args[1]
554+
555+
return [][]byte{hkdf.Extract(h, secret, salt)}, nil
556+
},
557+
}
558+
}
559+
560+
func cmdHkdfExpandLabelAft(h func() fips140.Hash) command {
561+
return command{
562+
requiredArgs: 4, // output length, secret, label, transcript hash
563+
handler: func(args [][]byte) ([][]byte, error) {
564+
keyLen := int(binary.LittleEndian.Uint32(args[0]))
565+
secret := args[1]
566+
label := args[2]
567+
transcriptHash := args[3]
568+
569+
return [][]byte{tls13.ExpandLabel(h, secret, string(label), transcriptHash, keyLen)}, nil
570+
},
571+
}
572+
}
573+
540574
func cmdPbkdf() command {
541575
return command{
542576
// Hash name, key length, salt, password, iteration count

0 commit comments

Comments
 (0)