From bcbdc045802b87c3d5fec29369dc08f51a1fb482 Mon Sep 17 00:00:00 2001 From: Moreno Ambrosin Date: Fri, 12 Jan 2024 00:38:11 -0800 Subject: [PATCH] Use test vectors from the internal `//testdata/testvector:*` targets PiperOrigin-RevId: 597764947 Change-Id: I56aefab42979ed61137522af8d4f7cdc4cd4008b --- aead/subtle/BUILD.bazel | 6 +++++- daead/subtle/BUILD.bazel | 2 +- hybrid/subtle/BUILD.bazel | 5 ++++- internal/aead/BUILD.bazel | 5 ++++- internal/signature/BUILD.bazel | 3 ++- keyderivation/internal/streamingprf/BUILD.bazel | 2 +- kwp/subtle/BUILD.bazel | 2 +- mac/subtle/BUILD.bazel | 2 +- prf/subtle/BUILD.bazel | 6 +++++- signature/subtle/BUILD.bazel | 3 ++- subtle/BUILD.bazel | 2 +- testutil/BUILD.bazel | 2 +- testutil/wycheproofutil.go | 10 +++++++--- 13 files changed, 35 insertions(+), 15 deletions(-) diff --git a/aead/subtle/BUILD.bazel b/aead/subtle/BUILD.bazel index f9412e5..b0c8ad4 100644 --- a/aead/subtle/BUILD.bazel +++ b/aead/subtle/BUILD.bazel @@ -39,7 +39,11 @@ go_test( "xchacha20poly1305_test.go", "xchacha20poly1305_vectors_test.go", ], - data = ["@wycheproof//testvectors:all"], + data = [ + "//testdata/testvectors:aes_gcm", + "//testdata/testvectors:aes_gcm_siv", + "//testdata/testvectors:chacha20_poly1305", + ], deps = [ ":subtle", "//mac/subtle", diff --git a/daead/subtle/BUILD.bazel b/daead/subtle/BUILD.bazel index ecbd2e4..6e935dc 100644 --- a/daead/subtle/BUILD.bazel +++ b/daead/subtle/BUILD.bazel @@ -11,7 +11,7 @@ go_library( go_test( name = "subtle_test", srcs = ["aes_siv_test.go"], - data = ["@wycheproof//testvectors:all"], + data = ["//testdata/testvectors:aes_siv_cmac"], deps = [ ":subtle", "//subtle/random", diff --git a/hybrid/subtle/BUILD.bazel b/hybrid/subtle/BUILD.bazel index 03312b7..dc451de 100644 --- a/hybrid/subtle/BUILD.bazel +++ b/hybrid/subtle/BUILD.bazel @@ -33,7 +33,10 @@ go_test( "public_key_test.go", "subtle_test.go", ], - data = ["@wycheproof//testvectors:all"], + data = [ + "//testdata/testvectors:ecdh", + "//testdata/testvectors:ecdh_ecpoint", + ], deps = [ ":subtle", "//hybrid", diff --git a/internal/aead/BUILD.bazel b/internal/aead/BUILD.bazel index 242fa70..5ca23a7 100644 --- a/internal/aead/BUILD.bazel +++ b/internal/aead/BUILD.bazel @@ -21,7 +21,10 @@ go_test( "chacha20poly1305_insecure_nonce_test.go", "chacha20poly1305_insecure_nonce_vectors_test.go", ], - data = ["@wycheproof//testvectors:all"], + data = [ + "//testdata/testvectors:aes_gcm", + "//testdata/testvectors:chacha20_poly1305", + ], deps = [ ":aead", "//subtle/random", diff --git a/internal/signature/BUILD.bazel b/internal/signature/BUILD.bazel index a03aff1..4316ad7 100644 --- a/internal/signature/BUILD.bazel +++ b/internal/signature/BUILD.bazel @@ -26,7 +26,8 @@ go_test( "rsassapss_signer_verifier_test.go", ], data = [ - "@wycheproof//testvectors:all", + "//testdata/testvectors:rsa_pss", + "//testdata/testvectors:rsa_signature", ], deps = [ ":signature", diff --git a/keyderivation/internal/streamingprf/BUILD.bazel b/keyderivation/internal/streamingprf/BUILD.bazel index a0ac8c1..24bb854 100644 --- a/keyderivation/internal/streamingprf/BUILD.bazel +++ b/keyderivation/internal/streamingprf/BUILD.bazel @@ -34,7 +34,7 @@ go_test( "streaming_prf_factory_test.go", "streaming_prf_test.go", ], - data = ["@wycheproof//testvectors:all"], + data = ["//testdata/testvectors:kdf"], embed = [":streamingprf"], deps = [ "//aead", diff --git a/kwp/subtle/BUILD.bazel b/kwp/subtle/BUILD.bazel index 3967f21..97bd860 100644 --- a/kwp/subtle/BUILD.bazel +++ b/kwp/subtle/BUILD.bazel @@ -12,7 +12,7 @@ go_library( go_test( name = "subtle_test", srcs = ["kwp_test.go"], - data = ["@wycheproof//testvectors:all"], + data = ["//testdata/testvectors:keywrap"], deps = [ ":subtle", "//subtle/random", diff --git a/mac/subtle/BUILD.bazel b/mac/subtle/BUILD.bazel index 18bdf01..b63c6ab 100644 --- a/mac/subtle/BUILD.bazel +++ b/mac/subtle/BUILD.bazel @@ -21,7 +21,7 @@ go_test( "cmac_test.go", "hmac_test.go", ], - data = ["@wycheproof//testvectors:all"], + data = ["//testdata/testvectors:aes_cmac"], deps = [ ":subtle", "//subtle/random", diff --git a/prf/subtle/BUILD.bazel b/prf/subtle/BUILD.bazel index 0978a54..e44bbaa 100644 --- a/prf/subtle/BUILD.bazel +++ b/prf/subtle/BUILD.bazel @@ -26,7 +26,11 @@ go_test( "hmac_test.go", "subtle_test.go", ], - data = ["@wycheproof//testvectors:all"], + data = [ + "//testdata/testvectors:aes_cmac", + "//testdata/testvectors:hmac", + "//testdata/testvectors:kdf", + ], deps = [ ":subtle", "//testutil", diff --git a/signature/subtle/BUILD.bazel b/signature/subtle/BUILD.bazel index 983c6a0..0b3087e 100644 --- a/signature/subtle/BUILD.bazel +++ b/signature/subtle/BUILD.bazel @@ -26,7 +26,8 @@ go_test( "subtle_test.go", ], data = [ - "@wycheproof//testvectors:all", + "//testdata/testvectors:ecdsa", + "//testdata/testvectors:eddsa", ], deps = [ ":subtle", diff --git a/subtle/BUILD.bazel b/subtle/BUILD.bazel index 2400ffe..24f1f33 100644 --- a/subtle/BUILD.bazel +++ b/subtle/BUILD.bazel @@ -23,7 +23,7 @@ go_test( "subtle_test.go", "x25519_test.go", ], - data = ["@wycheproof//testvectors:xdh"], + data = ["//testdata/testvectors:xdh"], deps = [ ":subtle", "//testutil", diff --git a/testutil/BUILD.bazel b/testutil/BUILD.bazel index 7ae301c..3ff27ec 100644 --- a/testutil/BUILD.bazel +++ b/testutil/BUILD.bazel @@ -46,7 +46,7 @@ go_test( "wycheproofutil_test.go", ], data = [ - "@wycheproof//testvectors:all", + "//testdata/testvectors:aes_gcm", ], deps = [ ":testutil", diff --git a/testutil/wycheproofutil.go b/testutil/wycheproofutil.go index da25ce7..5571fd5 100644 --- a/testutil/wycheproofutil.go +++ b/testutil/wycheproofutil.go @@ -26,7 +26,7 @@ import ( ) const ( - wycheproofDir = "wycheproof/testvectors" + testvectorsDir = "testdata/testvectors" ) // SkipTestIfTestSrcDirIsNotSet skips the test if TEST_SRCDIR is not set. @@ -89,12 +89,16 @@ func (a *HexBytes) UnmarshalText(text []byte) error { // // When using this in a test function, the function should start with // SkipTestIfTestSrcDirIsNotSet(), to expediently skip the test. -func PopulateSuite(suite interface{}, filename string) error { +func PopulateSuite(suite any, filename string) error { srcDir, ok := os.LookupEnv("TEST_SRCDIR") if !ok { return errors.New("TEST_SRCDIR not found") } - f, err := os.Open(filepath.Join(srcDir, wycheproofDir, filename)) + workspaceDir, ok := os.LookupEnv("TEST_WORKSPACE") + if !ok { + return errors.New("TEST_WORKSPACE not found") + } + f, err := os.Open(filepath.Join(srcDir, workspaceDir, testvectorsDir, filename)) if err != nil { return err }