Skip to content

Commit 03c41d2

Browse files
cpugopherbot
authored andcommitted
crypto/internal/fipstest: add PBKDF ACVP testing
This commit extends the acvp_test.go module wrapper and its described capabilities to included test coverage for PBKDF vectors. Notably this requires using an updated boringssl version to pick up support for PBKDF vectors in acvptool. Updates #69642 Change-Id: I17dcf2c19c38773fa9123d8e9b2172522e218a8b Reviewed-on: https://go-review.googlesource.com/c/go/+/619755 Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Filippo Valsorda <filippo@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Filippo Valsorda <filippo@golang.org>
1 parent 5d115c3 commit 03c41d2

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

src/crypto/internal/fips140test/acvp_capabilities.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@
2121
{"algorithm":"HMAC-SHA3-224","keyLen":[{"increment":8,"max":524288,"min":8}],"macLen":[{"increment":8,"max":224,"min":32}],"revision":"1.0"},
2222
{"algorithm":"HMAC-SHA3-256","keyLen":[{"increment":8,"max":524288,"min":8}],"macLen":[{"increment":8,"max":256,"min":32}],"revision":"1.0"},
2323
{"algorithm":"HMAC-SHA3-384","keyLen":[{"increment":8,"max":524288,"min":8}],"macLen":[{"increment":8,"max":384,"min":32}],"revision":"1.0"},
24-
{"algorithm":"HMAC-SHA3-512","keyLen":[{"increment":8,"max":524288,"min":8}],"macLen":[{"increment":8,"max":512,"min":32}],"revision":"1.0"}
24+
{"algorithm":"HMAC-SHA3-512","keyLen":[{"increment":8,"max":524288,"min":8}],"macLen":[{"increment":8,"max":512,"min":32}],"revision":"1.0"},
25+
26+
{"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"}
2527
]

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@
2121
{"Wrapper": "go", "In": "vectors/HMAC-SHA3-224.bz2", "Out": "expected/HMAC-SHA3-224.bz2"},
2222
{"Wrapper": "go", "In": "vectors/HMAC-SHA3-256.bz2", "Out": "expected/HMAC-SHA3-256.bz2"},
2323
{"Wrapper": "go", "In": "vectors/HMAC-SHA3-384.bz2", "Out": "expected/HMAC-SHA3-384.bz2"},
24-
{"Wrapper": "go", "In": "vectors/HMAC-SHA3-512.bz2", "Out": "expected/HMAC-SHA3-512.bz2"}
24+
{"Wrapper": "go", "In": "vectors/HMAC-SHA3-512.bz2", "Out": "expected/HMAC-SHA3-512.bz2"},
25+
26+
{"Wrapper": "go", "In": "vectors/PBKDF.bz2", "Out": "expected/PBKDF.bz2"}
2527
]

src/crypto/internal/fips140test/acvp_test.go

+63-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"crypto/internal/cryptotest"
2525
"crypto/internal/fips140"
2626
"crypto/internal/fips140/hmac"
27+
"crypto/internal/fips140/pbkdf2"
2728
"crypto/internal/fips140/sha256"
2829
"crypto/internal/fips140/sha3"
2930
"crypto/internal/fips140/sha512"
@@ -72,6 +73,8 @@ var (
7273
// https://pages.nist.gov/ACVP/draft-celi-acvp-sha.html#section-7.2
7374
// HMAC algorithm capabilities:
7475
// https://pages.nist.gov/ACVP/draft-fussell-acvp-mac.html#section-7
76+
// PBKDF2 algorithm capabilities:
77+
// https://pages.nist.gov/ACVP/draft-celi-acvp-pbkdf.html#section-7.3
7578
//go:embed acvp_capabilities.json
7679
capabilitiesJson []byte
7780

@@ -113,6 +116,8 @@ var (
113116
"HMAC-SHA3-256": cmdHmacAft(func() fips140.Hash { return sha3.New256() }),
114117
"HMAC-SHA3-384": cmdHmacAft(func() fips140.Hash { return sha3.New384() }),
115118
"HMAC-SHA3-512": cmdHmacAft(func() fips140.Hash { return sha3.New512() }),
119+
120+
"PBKDF": cmdPbkdf(),
116121
}
117122
)
118123

@@ -343,14 +348,70 @@ func cmdHmacAft(h func() fips140.Hash) command {
343348
}
344349
}
345350

351+
func cmdPbkdf() command {
352+
return command{
353+
// Hash name, key length, salt, password, iteration count
354+
requiredArgs: 5,
355+
handler: func(args [][]byte) ([][]byte, error) {
356+
h, err := lookupHash(string(args[0]))
357+
if err != nil {
358+
return nil, fmt.Errorf("PBKDF2 failed: %w", err)
359+
}
360+
361+
keyLen := binary.LittleEndian.Uint32(args[1]) / 8
362+
salt := args[2]
363+
password := args[3]
364+
iterationCount := binary.LittleEndian.Uint32(args[4])
365+
366+
derivedKey, err := pbkdf2.Key(h, string(password), salt, int(iterationCount), int(keyLen))
367+
if err != nil {
368+
return nil, fmt.Errorf("PBKDF2 failed: %w", err)
369+
}
370+
371+
return [][]byte{derivedKey}, nil
372+
},
373+
}
374+
}
375+
376+
func lookupHash(name string) (func() fips140.Hash, error) {
377+
var h func() fips140.Hash
378+
379+
switch name {
380+
case "SHA2-224":
381+
h = func() fips140.Hash { return sha256.New224() }
382+
case "SHA2-256":
383+
h = func() fips140.Hash { return sha256.New() }
384+
case "SHA2-384":
385+
h = func() fips140.Hash { return sha512.New384() }
386+
case "SHA2-512":
387+
h = func() fips140.Hash { return sha512.New() }
388+
case "SHA2-512/224":
389+
h = func() fips140.Hash { return sha512.New512_224() }
390+
case "SHA2-512/256":
391+
h = func() fips140.Hash { return sha512.New512_256() }
392+
case "SHA3-224":
393+
h = func() fips140.Hash { return sha3.New224() }
394+
case "SHA3-256":
395+
h = func() fips140.Hash { return sha3.New256() }
396+
case "SHA3-384":
397+
h = func() fips140.Hash { return sha3.New384() }
398+
case "SHA3-512":
399+
h = func() fips140.Hash { return sha3.New512() }
400+
default:
401+
return nil, fmt.Errorf("unknown hash name: %q", name)
402+
}
403+
404+
return h, nil
405+
}
406+
346407
func TestACVP(t *testing.T) {
347408
testenv.SkipIfShortAndSlow(t)
348409

349410
const (
350411
bsslModule = "boringssl.googlesource.com/boringssl.git"
351-
bsslVersion = "v0.0.0-20241009223352-905c3903fd42"
412+
bsslVersion = "v0.0.0-20241015160643-2587c4974dbe"
352413
goAcvpModule = "github.com/cpu/go-acvp"
353-
goAcvpVersion = "v0.0.0-20241009200939-159f4c69a90d"
414+
goAcvpVersion = "v0.0.0-20241011151719-6e0509dcb7ce"
354415
)
355416

356417
// 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)