Skip to content

Commit 11c642c

Browse files
cpugopherbot
authored andcommitted
crypto/internal/fips140test: add OneStepNoCounter ACVP tests
Adds ACVP test coverage for the SP 800-56Crev2 IG D.P KDA OneStepNoCounter mode algorithm based on the NIST spec: https://pages.nist.gov/ACVP/draft-hammett-acvp-kas-kdf-onestepnocounter.html Coverage is added for all SHA2 and SHA3 HMACs. Updates #69642 Change-Id: I337bf824a71fce6c796a1440b7f08c4f5413d92f Reviewed-on: https://go-review.googlesource.com/c/go/+/648435 Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Roland Shoemaker <roland@golang.org>
1 parent 8c6fec6 commit 11c642c

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/crypto/internal/fips140test/acvp_capabilities.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
{"algorithm":"HMAC-SHA3-512","keyLen":[{"increment":8,"max":524288,"min":8}],"macLen":[{"increment":8,"max":512,"min":32}],"revision":"1.0"},
2828

2929
{"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+
{"algorithm":"KDA","mode":"OneStepNoCounter","revision":"Sp800-56Cr2","auxFunctions":[{"auxFunctionName":"HMAC-SHA2-224","l":224,"macSaltMethods":["default","random"]},{"auxFunctionName":"HMAC-SHA2-256","l":256,"macSaltMethods":["default","random"]},{"auxFunctionName":"HMAC-SHA2-384","l":384,"macSaltMethods":["default","random"]},{"auxFunctionName":"HMAC-SHA2-512","l":512,"macSaltMethods":["default","random"]},{"auxFunctionName":"HMAC-SHA2-512/224","l":224,"macSaltMethods":["default","random"]},{"auxFunctionName":"HMAC-SHA2-512/256","l":256,"macSaltMethods":["default","random"]},{"auxFunctionName":"HMAC-SHA3-224","l":224,"macSaltMethods":["default","random"]},{"auxFunctionName":"HMAC-SHA3-256","l":256,"macSaltMethods":["default","random"]},{"auxFunctionName":"HMAC-SHA3-384","l":384,"macSaltMethods":["default","random"]},{"auxFunctionName":"HMAC-SHA3-512","l":512,"macSaltMethods":["default","random"]}],"fixedInfoPattern":"uPartyInfo||vPartyInfo","encoding":["concatenation"],"z":[{"min":224,"max":65336,"increment":8}]},
3031

3132
{"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"},
3233

src/crypto/internal/fips140test/acvp_test.go

+43-2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ var (
121121
// https://pages.nist.gov/ACVP/draft-celi-acvp-symmetric.html#section-7.3
122122
// HKDF KDA algorithm capabilities:
123123
// https://pages.nist.gov/ACVP/draft-hammett-acvp-kas-kdf-hkdf.html#section-7.3
124+
// OneStepNoCounter KDA algorithm capabilities:
125+
// https://pages.nist.gov/ACVP/draft-hammett-acvp-kas-kdf-onestepnocounter.html#section-7.2
124126
// TLS 1.2 KDF algorithm capabilities:
125127
// https://pages.nist.gov/ACVP/draft-celi-acvp-kdf-tls.html#section-7.2
126128
// TLS 1.3 KDF algorithm capabilities:
@@ -294,6 +296,17 @@ var (
294296

295297
"KDF-counter": cmdKdfCounterAft(),
296298
"KDF-feedback": cmdKdfFeedbackAft(),
299+
300+
"OneStepNoCounter/HMAC-SHA2-224": cmdOneStepNoCounterHmacAft(func() fips140.Hash { return sha256.New224() }),
301+
"OneStepNoCounter/HMAC-SHA2-256": cmdOneStepNoCounterHmacAft(func() fips140.Hash { return sha256.New() }),
302+
"OneStepNoCounter/HMAC-SHA2-384": cmdOneStepNoCounterHmacAft(func() fips140.Hash { return sha512.New384() }),
303+
"OneStepNoCounter/HMAC-SHA2-512": cmdOneStepNoCounterHmacAft(func() fips140.Hash { return sha512.New() }),
304+
"OneStepNoCounter/HMAC-SHA2-512/224": cmdOneStepNoCounterHmacAft(func() fips140.Hash { return sha512.New512_224() }),
305+
"OneStepNoCounter/HMAC-SHA2-512/256": cmdOneStepNoCounterHmacAft(func() fips140.Hash { return sha512.New512_256() }),
306+
"OneStepNoCounter/HMAC-SHA3-224": cmdOneStepNoCounterHmacAft(func() fips140.Hash { return sha3.New224() }),
307+
"OneStepNoCounter/HMAC-SHA3-256": cmdOneStepNoCounterHmacAft(func() fips140.Hash { return sha3.New256() }),
308+
"OneStepNoCounter/HMAC-SHA3-384": cmdOneStepNoCounterHmacAft(func() fips140.Hash { return sha3.New384() }),
309+
"OneStepNoCounter/HMAC-SHA3-512": cmdOneStepNoCounterHmacAft(func() fips140.Hash { return sha3.New512() }),
297310
}
298311
)
299312

@@ -1829,14 +1842,42 @@ func getRSAKey(bits int) (*rsa.PrivateKey, error) {
18291842
return key, nil
18301843
}
18311844

1845+
func cmdOneStepNoCounterHmacAft(h func() fips140.Hash) command {
1846+
return command{
1847+
requiredArgs: 4, // key, info, salt, outBytes
1848+
handler: func(args [][]byte) ([][]byte, error) {
1849+
key := args[0]
1850+
info := args[1]
1851+
salt := args[2]
1852+
outBytes := binary.LittleEndian.Uint32(args[3])
1853+
1854+
mac := hmac.New(h, salt)
1855+
mac.Size()
1856+
1857+
if outBytes != uint32(mac.Size()) {
1858+
return nil, fmt.Errorf("invalid output length: got %d, want %d", outBytes, mac.Size())
1859+
}
1860+
1861+
data := make([]byte, 0, len(key)+len(info))
1862+
data = append(data, key...)
1863+
data = append(data, info...)
1864+
1865+
mac.Write(data)
1866+
out := mac.Sum(nil)
1867+
1868+
return [][]byte{out}, nil
1869+
},
1870+
}
1871+
}
1872+
18321873
func TestACVP(t *testing.T) {
18331874
testenv.SkipIfShortAndSlow(t)
18341875

18351876
const (
18361877
bsslModule = "boringssl.googlesource.com/boringssl.git"
1837-
bsslVersion = "v0.0.0-20250123161947-ba24bde161f7"
1878+
bsslVersion = "v0.0.0-20250207174145-0bb19f6126cb"
18381879
goAcvpModule = "github.com/cpu/go-acvp"
1839-
goAcvpVersion = "v0.0.0-20250110181646-e47fea3b5d7d"
1880+
goAcvpVersion = "v0.0.0-20250117180340-0406d83a4b0d"
18401881
)
18411882

18421883
// In crypto/tls/bogo_shim_test.go the test is skipped if run on a builder with runtime.GOOS == "windows"

0 commit comments

Comments
 (0)