Skip to content

Commit 3310f32

Browse files
cpugopherbot
authored andcommitted
crypto/internal/fips140test: add TLS-v1.2 ACVP tests
Adds ACVP test coverage for the SP 800-135rev1 RFC 7627 TLS v1.2 KDF based on the NIST spec: https://pages.nist.gov/ACVP/draft-celi-acvp-kdf-tls.html Only SHA2-256, SHA2-384 and SHA2-512 are valid hash algorithms for the TLSKDF algorithm. Updates #69642 Change-Id: I553d4f6a1d6652ed486af0e2c94730c8063fb47f Reviewed-on: https://go-review.googlesource.com/c/go/+/636116 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: David Chase <drchase@google.com>
1 parent 0580e2a commit 3310f32

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/crypto/internal/fips140test/acvp_capabilities.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@
5959
{"algorithm":"ACVP-AES-CTR","direction":["encrypt","decrypt"],"keyLen":[128,192,256],"payloadLen":[{"min":8,"max":128,"increment":8}],"incrementalCounter":true,"overflowCounter":true,"performCounterTests":true,"revision":"1.0"},
6060
{"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":[96,104,112,120,128],"ivLen":[96],"ivGen":"external","revision":"1.0"},
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"},
62-
{"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"}
62+
{"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"},
63+
64+
{"algorithm":"TLS-v1.2","mode":"KDF","revision":"RFC7627","hashAlg":["SHA2-256","SHA2-384","SHA2-512"]}
6365
]

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@
4242
{"Wrapper": "go", "In": "vectors/ACVP-AES-CTR.bz2", "Out": "expected/ACVP-AES-CTR.bz2"},
4343
{"Wrapper": "go", "In": "vectors/ACVP-AES-GCM.bz2", "Out": "expected/ACVP-AES-GCM.bz2"},
4444

45-
{"Wrapper": "go", "In": "vectors/CMAC-AES.bz2", "Out": "expected/CMAC-AES.bz2"}
45+
{"Wrapper": "go", "In": "vectors/CMAC-AES.bz2", "Out": "expected/CMAC-AES.bz2"},
46+
47+
{"Wrapper": "go", "In": "vectors/TLS-v1.2.bz2", "Out": "expected/TLS-v1.2.bz2"}
4648
]

src/crypto/internal/fips140test/acvp_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"crypto/internal/fips140/sha3"
3838
"crypto/internal/fips140/sha512"
3939
"crypto/internal/fips140/subtle"
40+
"crypto/internal/fips140/tls12"
4041
"crypto/rand"
4142
_ "embed"
4243
"encoding/binary"
@@ -114,6 +115,8 @@ var (
114115
// https://pages.nist.gov/ACVP/draft-celi-acvp-symmetric.html#section-7.3
115116
// HKDF KDA algorithm capabilities:
116117
// https://pages.nist.gov/ACVP/draft-hammett-acvp-kas-kdf-hkdf.html#section-7.3
118+
// TLS 1.2 KDF algorithm capabilities:
119+
// https://pages.nist.gov/ACVP/draft-celi-acvp-kdf-tls.html#section-7.2
117120
//go:embed acvp_capabilities.json
118121
capabilitiesJson []byte
119122

@@ -220,6 +223,12 @@ var (
220223

221224
"CMAC-AES": cmdCmacAesAft(),
222225
"CMAC-AES/verify": cmdCmacAesVerifyAft(),
226+
227+
// Note: Only SHA2-256, SHA2-384 and SHA2-512 are valid hash functions for TLSKDF.
228+
// See https://pages.nist.gov/ACVP/draft-celi-acvp-kdf-tls.html#section-7.2.1
229+
"TLSKDF/1.2/SHA2-256": cmdTlsKdf12Aft(func() fips140.Hash { return sha256.New() }),
230+
"TLSKDF/1.2/SHA2-384": cmdTlsKdf12Aft(func() fips140.Hash { return sha512.New384() }),
231+
"TLSKDF/1.2/SHA2-512": cmdTlsKdf12Aft(func() fips140.Hash { return sha512.New() }),
223232
}
224233
)
225234

@@ -1314,6 +1323,21 @@ func cmdCmacAesVerifyAft() command {
13141323
}
13151324
}
13161325

1326+
func cmdTlsKdf12Aft(h func() fips140.Hash) command {
1327+
return command{
1328+
requiredArgs: 5, // Number output bytes, secret, label, seed1, seed2
1329+
handler: func(args [][]byte) ([][]byte, error) {
1330+
outputLen := binary.LittleEndian.Uint32(args[0])
1331+
secret := args[1]
1332+
label := string(args[2])
1333+
seed1 := args[3]
1334+
seed2 := args[4]
1335+
1336+
return [][]byte{tls12.PRF(h, secret, label, append(seed1, seed2...), int(outputLen))}, nil
1337+
},
1338+
}
1339+
}
1340+
13171341
func TestACVP(t *testing.T) {
13181342
testenv.SkipIfShortAndSlow(t)
13191343

0 commit comments

Comments
 (0)