Skip to content

Commit 86aca87

Browse files
cpugopherbot
authored andcommitted
crypto/internal/fips140test: add SSH KDF ACVP tests
Adds ACVP test coverage for the SP 800-135rev1 SSH KDF based on the NIST spec: https://pages.nist.gov/ACVP/draft-celi-acvp-kdf-ssh.html Only SHA1, SHA2-224, SHA2-256, SHA2-384, and SHA2-512 are valid hash algorithms for the SSH KDF algorithm. We do not include SHA-1 since it is out of scope for our FIPS module. Similarly only TDES, AES-128, AES-192 and AES-256 are valid ciphers, and we do not include TDES. Updates #69642 Change-Id: I70e45b77a91bd8aa631da30fab54c97e974f433c Reviewed-on: https://go-review.googlesource.com/c/go/+/636355 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Filippo Valsorda <[email protected]>
1 parent 072eea9 commit 86aca87

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

src/crypto/internal/fips140test/acvp_capabilities.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@
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

6464
{"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"]}
65+
{"algorithm":"TLS-v1.3","mode":"KDF","revision":"RFC8446","hmacAlg":["SHA2-256","SHA2-384"],"runningMode":["DHE","PSK","PSK-DHE"]},
66+
{"algorithm":"kdf-components","mode":"ssh","revision":"1.0","hashAlg":["SHA2-224","SHA2-256","SHA2-384","SHA2-512"],"cipher":["AES-128","AES-192","AES-256"]}
6667
]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@
4545
{"Wrapper": "go", "In": "vectors/CMAC-AES.bz2", "Out": "expected/CMAC-AES.bz2"},
4646

4747
{"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"}
48+
{"Wrapper": "go", "In": "vectors/TLS-v1.3.bz2", "Out": "expected/TLS-v1.3.bz2"},
49+
{"Wrapper": "go", "In": "vectors/kdf-components.bz2", "Out": "expected/kdf-components.bz2"}
4950
]

src/crypto/internal/fips140test/acvp_test.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"crypto/internal/fips140/sha256"
3737
"crypto/internal/fips140/sha3"
3838
"crypto/internal/fips140/sha512"
39+
"crypto/internal/fips140/ssh"
3940
"crypto/internal/fips140/subtle"
4041
"crypto/internal/fips140/tls12"
4142
"crypto/internal/fips140/tls13"
@@ -120,6 +121,8 @@ var (
120121
// https://pages.nist.gov/ACVP/draft-celi-acvp-kdf-tls.html#section-7.2
121122
// TLS 1.3 KDF algorithm capabilities:
122123
// https://pages.nist.gov/ACVP/draft-hammett-acvp-kdf-tls-v1.3.html#section-7.2
124+
// SSH KDF algorithm capabilities:
125+
// https://pages.nist.gov/ACVP/draft-celi-acvp-kdf-ssh.html#section-7.2
123126
//go:embed acvp_capabilities.json
124127
capabilitiesJson []byte
125128

@@ -237,6 +240,17 @@ var (
237240
"TLSKDF/1.2/SHA2-256": cmdTlsKdf12Aft(func() fips140.Hash { return sha256.New() }),
238241
"TLSKDF/1.2/SHA2-384": cmdTlsKdf12Aft(func() fips140.Hash { return sha512.New384() }),
239242
"TLSKDF/1.2/SHA2-512": cmdTlsKdf12Aft(func() fips140.Hash { return sha512.New() }),
243+
244+
// Note: only SHA2-224, SHA2-256, SHA2-384 and SHA2-512 are valid hash functions for SSHKDF.
245+
// See https://pages.nist.gov/ACVP/draft-celi-acvp-kdf-ssh.html#section-7.2.1
246+
"SSHKDF/SHA2-224/client": cmdSshKdfAft(func() fips140.Hash { return sha256.New224() }, ssh.ClientKeys),
247+
"SSHKDF/SHA2-224/server": cmdSshKdfAft(func() fips140.Hash { return sha256.New224() }, ssh.ServerKeys),
248+
"SSHKDF/SHA2-256/client": cmdSshKdfAft(func() fips140.Hash { return sha256.New() }, ssh.ClientKeys),
249+
"SSHKDF/SHA2-256/server": cmdSshKdfAft(func() fips140.Hash { return sha256.New() }, ssh.ServerKeys),
250+
"SSHKDF/SHA2-384/client": cmdSshKdfAft(func() fips140.Hash { return sha512.New384() }, ssh.ClientKeys),
251+
"SSHKDF/SHA2-384/server": cmdSshKdfAft(func() fips140.Hash { return sha512.New384() }, ssh.ServerKeys),
252+
"SSHKDF/SHA2-512/client": cmdSshKdfAft(func() fips140.Hash { return sha512.New() }, ssh.ClientKeys),
253+
"SSHKDF/SHA2-512/server": cmdSshKdfAft(func() fips140.Hash { return sha512.New() }, ssh.ServerKeys),
240254
}
241255
)
242256

@@ -1372,12 +1386,39 @@ func cmdTlsKdf12Aft(h func() fips140.Hash) command {
13721386
}
13731387
}
13741388

1389+
func cmdSshKdfAft(hFunc func() fips140.Hash, direction ssh.Direction) command {
1390+
return command{
1391+
requiredArgs: 4, // K, H, SessionID, cipher
1392+
handler: func(args [][]byte) ([][]byte, error) {
1393+
k := args[0]
1394+
h := args[1]
1395+
sessionID := args[2]
1396+
cipher := string(args[3])
1397+
1398+
var keyLen int
1399+
switch cipher {
1400+
case "AES-128":
1401+
keyLen = 16
1402+
case "AES-192":
1403+
keyLen = 24
1404+
case "AES-256":
1405+
keyLen = 32
1406+
default:
1407+
return nil, fmt.Errorf("unsupported cipher: %q", cipher)
1408+
}
1409+
1410+
ivKey, encKey, intKey := ssh.Keys(hFunc, direction, k, h, sessionID, 16, keyLen, hFunc().Size())
1411+
return [][]byte{ivKey, encKey, intKey}, nil
1412+
},
1413+
}
1414+
}
1415+
13751416
func TestACVP(t *testing.T) {
13761417
testenv.SkipIfShortAndSlow(t)
13771418

13781419
const (
13791420
bsslModule = "boringssl.googlesource.com/boringssl.git"
1380-
bsslVersion = "v0.0.0-20250108043213-d3f61eeacbf7"
1421+
bsslVersion = "v0.0.0-20250116010235-21f54b2730ee"
13811422
goAcvpModule = "github.com/cpu/go-acvp"
13821423
goAcvpVersion = "v0.0.0-20250102201911-6839fc40f9f8"
13831424
)

0 commit comments

Comments
 (0)