From 57e1ab63454977e08adccc106756cfa691d9d839 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Thu, 31 Oct 2024 14:48:53 +0100 Subject: [PATCH 1/3] fix TestMarshalHash --- .../0002-Add-crypto-backend-foundation.patch | 23 ++++++++++++++--- patches/0005-Add-CNG-crypto-backend.patch | 25 +------------------ 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/patches/0002-Add-crypto-backend-foundation.patch b/patches/0002-Add-crypto-backend-foundation.patch index e02dd1457d..6ba293fd76 100644 --- a/patches/0002-Add-crypto-backend-foundation.patch +++ b/patches/0002-Add-crypto-backend-foundation.patch @@ -54,9 +54,10 @@ Subject: [PATCH] Add crypto backend foundation src/crypto/tls/prf_test.go | 12 +- src/crypto/x509/boring_test.go | 5 + src/go/build/deps_test.go | 4 + + src/hash/marshal_test.go | 3 + src/net/smtp/smtp_test.go | 72 ++++--- src/runtime/runtime_boring.go | 5 + - 52 files changed, 858 insertions(+), 106 deletions(-) + 53 files changed, 861 insertions(+), 106 deletions(-) create mode 100644 src/crypto/ed25519/boring.go create mode 100644 src/crypto/ed25519/notboring.go create mode 100644 src/crypto/internal/backend/backend_test.go @@ -912,7 +913,7 @@ index c984c3f4968598..229dd457f8d53c 100644 d.Reset() d.Write(data) diff --git a/src/crypto/md5/md5_test.go b/src/crypto/md5/md5_test.go -index 6a8258a67e860c..63dfe196da7a58 100644 +index 6a8258a67e860c..61ea6b5153f617 100644 --- a/src/crypto/md5/md5_test.go +++ b/src/crypto/md5/md5_test.go @@ -6,6 +6,7 @@ package md5 @@ -1347,7 +1348,7 @@ index d87c689c9001ad..7584c380af0cec 100644 } h := New224() diff --git a/src/crypto/sha256/sha256_test.go b/src/crypto/sha256/sha256_test.go -index ffd16386515830..09f7046548bf8f 100644 +index ffd16386515830..58632c01dc6a7f 100644 --- a/src/crypto/sha256/sha256_test.go +++ b/src/crypto/sha256/sha256_test.go @@ -8,7 +8,7 @@ package sha256 @@ -1412,7 +1413,7 @@ index 0a12fde7bc060b..ca752598e4343a 100644 "hash" ) diff --git a/src/crypto/sha512/sha512_test.go b/src/crypto/sha512/sha512_test.go -index fdad37b1863ae8..78fa1f60a542b5 100644 +index fdad37b1863ae8..cf6e4c395cd4fb 100644 --- a/src/crypto/sha512/sha512_test.go +++ b/src/crypto/sha512/sha512_test.go @@ -8,7 +8,7 @@ package sha512 @@ -1908,6 +1909,20 @@ index c6a2518f62ff3a..578b4d6f68504c 100644 < crypto/rand < crypto/internal/mlkem768 < crypto/ed25519 +diff --git a/src/hash/marshal_test.go b/src/hash/marshal_test.go +index 3091f7a67acede..b066f8281c5265 100644 +--- a/src/hash/marshal_test.go ++++ b/src/hash/marshal_test.go +@@ -65,6 +65,9 @@ func TestMarshalHash(t *testing.T) { + } + + h := tt.new() ++ if _, ok := h.(encoding.BinaryMarshaler); !ok { ++ t.Skip("BinaryMarshaler not implemented") ++ } + h.Write(buf[:256]) + sum := h.Sum(nil) + diff --git a/src/net/smtp/smtp_test.go b/src/net/smtp/smtp_test.go index 389eda9ad54b99..110d60beb0e70c 100644 --- a/src/net/smtp/smtp_test.go diff --git a/patches/0005-Add-CNG-crypto-backend.patch b/patches/0005-Add-CNG-crypto-backend.patch index 54a29efb91..fab2306d04 100644 --- a/patches/0005-Add-CNG-crypto-backend.patch +++ b/patches/0005-Add-CNG-crypto-backend.patch @@ -37,11 +37,10 @@ Subject: [PATCH] Add CNG crypto backend src/go/build/deps_test.go | 5 + src/go/build/vendor_test.go | 1 + src/hash/example_test.go | 2 + - src/hash/marshal_test.go | 4 + .../goexperiment/exp_cngcrypto_off.go | 9 + src/internal/goexperiment/exp_cngcrypto_on.go | 9 + src/internal/goexperiment/flags.go | 1 + - 37 files changed, 394 insertions(+), 26 deletions(-) + 36 files changed, 390 insertions(+), 26 deletions(-) create mode 100644 src/crypto/ecdsa/badlinkname.go create mode 100644 src/crypto/internal/backend/bbig/big_cng.go create mode 100644 src/crypto/internal/backend/cng_windows.go @@ -824,28 +823,6 @@ index f07b9aaa2c4898..2ff6c4827391c0 100644 package hash_test import ( -diff --git a/src/hash/marshal_test.go b/src/hash/marshal_test.go -index 3091f7a67acede..824be4a90fd4db 100644 ---- a/src/hash/marshal_test.go -+++ b/src/hash/marshal_test.go -@@ -21,6 +21,7 @@ import ( - "hash/crc32" - "hash/crc64" - "hash/fnv" -+ "internal/goexperiment" - "testing" - ) - -@@ -76,6 +77,9 @@ func TestMarshalHash(t *testing.T) { - } - h2m, ok := h2.(encoding.BinaryMarshaler) - if !ok { -+ if goexperiment.CNGCrypto { -+ t.Skip("CNGCrypto does not hash marshaling") -+ } - t.Fatalf("Hash does not implement MarshalBinary") - } - enc, err := h2m.MarshalBinary() diff --git a/src/internal/goexperiment/exp_cngcrypto_off.go b/src/internal/goexperiment/exp_cngcrypto_off.go new file mode 100644 index 00000000000000..831460053281e2 From bd9da3b55a9451bced809cf47a027d6cc7ba4787 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Mon, 4 Nov 2024 10:21:30 +0100 Subject: [PATCH 2/3] only conditionally skip TestMarshalHash in boring mode --- .../0002-Add-crypto-backend-foundation.patch | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/patches/0002-Add-crypto-backend-foundation.patch b/patches/0002-Add-crypto-backend-foundation.patch index 6ba293fd76..87de796c19 100644 --- a/patches/0002-Add-crypto-backend-foundation.patch +++ b/patches/0002-Add-crypto-backend-foundation.patch @@ -54,10 +54,12 @@ Subject: [PATCH] Add crypto backend foundation src/crypto/tls/prf_test.go | 12 +- src/crypto/x509/boring_test.go | 5 + src/go/build/deps_test.go | 4 + - src/hash/marshal_test.go | 3 + + src/hash/boring_test.go | 5 + + src/hash/marshal_test.go | 5 + + src/hash/notboring_test.go | 5 + src/net/smtp/smtp_test.go | 72 ++++--- src/runtime/runtime_boring.go | 5 + - 53 files changed, 861 insertions(+), 106 deletions(-) + 55 files changed, 873 insertions(+), 106 deletions(-) create mode 100644 src/crypto/ed25519/boring.go create mode 100644 src/crypto/ed25519/notboring.go create mode 100644 src/crypto/internal/backend/backend_test.go @@ -67,6 +69,8 @@ Subject: [PATCH] Add crypto backend foundation create mode 100644 src/crypto/internal/backend/nobackend.go create mode 100644 src/crypto/internal/backend/norequirefips.go create mode 100644 src/crypto/internal/backend/stub.s + create mode 100644 src/hash/boring_test.go + create mode 100644 src/hash/notboring_test.go diff --git a/src/crypto/aes/cipher.go b/src/crypto/aes/cipher.go index cde2e45d2ca559..cf47a4fc57d8e2 100644 @@ -1909,20 +1913,44 @@ index c6a2518f62ff3a..578b4d6f68504c 100644 < crypto/rand < crypto/internal/mlkem768 < crypto/ed25519 +diff --git a/src/hash/boring_test.go b/src/hash/boring_test.go +new file mode 100644 +index 00000000000000..cd07ee1c00d379 +--- /dev/null ++++ b/src/hash/boring_test.go +@@ -0,0 +1,5 @@ ++//go:build systemcrypto ++ ++package hash_test ++ ++const boringEnabled = true diff --git a/src/hash/marshal_test.go b/src/hash/marshal_test.go -index 3091f7a67acede..b066f8281c5265 100644 +index 3091f7a67acede..fead8cc4bec73a 100644 --- a/src/hash/marshal_test.go +++ b/src/hash/marshal_test.go -@@ -65,6 +65,9 @@ func TestMarshalHash(t *testing.T) { +@@ -65,6 +65,11 @@ func TestMarshalHash(t *testing.T) { } h := tt.new() -+ if _, ok := h.(encoding.BinaryMarshaler); !ok { -+ t.Skip("BinaryMarshaler not implemented") ++ if boringEnabled { ++ if _, ok := h.(encoding.BinaryMarshaler); !ok { ++ t.Skip("BinaryMarshaler not implemented") ++ } + } h.Write(buf[:256]) sum := h.Sum(nil) +diff --git a/src/hash/notboring_test.go b/src/hash/notboring_test.go +new file mode 100644 +index 00000000000000..e1874086d3f315 +--- /dev/null ++++ b/src/hash/notboring_test.go +@@ -0,0 +1,5 @@ ++//go:build !systemcrypto ++ ++package hash_test ++ ++const boringEnabled = false diff --git a/src/net/smtp/smtp_test.go b/src/net/smtp/smtp_test.go index 389eda9ad54b99..110d60beb0e70c 100644 --- a/src/net/smtp/smtp_test.go From b3aa2e82b3dac0db8660dde73e1751542531c739 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Mon, 4 Nov 2024 11:42:52 +0100 Subject: [PATCH 3/3] fix TestMarshalHash --- .../0002-Add-crypto-backend-foundation.patch | 8 +++--- patches/0004-Add-OpenSSL-crypto-backend.patch | 28 +++++++++++++++++-- patches/0005-Add-CNG-crypto-backend.patch | 24 +++++++++++++++- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/patches/0002-Add-crypto-backend-foundation.patch b/patches/0002-Add-crypto-backend-foundation.patch index 87de796c19..93536512b2 100644 --- a/patches/0002-Add-crypto-backend-foundation.patch +++ b/patches/0002-Add-crypto-backend-foundation.patch @@ -1915,11 +1915,11 @@ index c6a2518f62ff3a..578b4d6f68504c 100644 < crypto/ed25519 diff --git a/src/hash/boring_test.go b/src/hash/boring_test.go new file mode 100644 -index 00000000000000..cd07ee1c00d379 +index 00000000000000..c90899062a9665 --- /dev/null +++ b/src/hash/boring_test.go @@ -0,0 +1,5 @@ -+//go:build systemcrypto ++//go:build goexperiment.boringcrypto + +package hash_test + @@ -1942,11 +1942,11 @@ index 3091f7a67acede..fead8cc4bec73a 100644 diff --git a/src/hash/notboring_test.go b/src/hash/notboring_test.go new file mode 100644 -index 00000000000000..e1874086d3f315 +index 00000000000000..79f8c22f2b7416 --- /dev/null +++ b/src/hash/notboring_test.go @@ -0,0 +1,5 @@ -+//go:build !systemcrypto ++//go:build !goexperiment.boringcrypto + +package hash_test + diff --git a/patches/0004-Add-OpenSSL-crypto-backend.patch b/patches/0004-Add-OpenSSL-crypto-backend.patch index 1f3d5cd632..938e6927e2 100644 --- a/patches/0004-Add-OpenSSL-crypto-backend.patch +++ b/patches/0004-Add-OpenSSL-crypto-backend.patch @@ -34,11 +34,13 @@ Subject: [PATCH] Add OpenSSL crypto backend src/go.sum | 2 + src/go/build/deps_test.go | 7 +- src/go/build/vendor_test.go | 1 + + src/hash/boring_test.go | 2 +- + src/hash/notboring_test.go | 2 +- .../goexperiment/exp_opensslcrypto_off.go | 9 + .../goexperiment/exp_opensslcrypto_on.go | 9 + src/internal/goexperiment/flags.go | 1 + src/os/exec/exec_test.go | 9 + - 34 files changed, 406 insertions(+), 23 deletions(-) + 36 files changed, 408 insertions(+), 25 deletions(-) create mode 100644 src/crypto/internal/backend/bbig/big_openssl.go create mode 100644 src/crypto/internal/backend/openssl_linux.go create mode 100644 src/internal/goexperiment/exp_opensslcrypto_off.go @@ -714,7 +716,7 @@ index c83a7272c9f01f..a0548a7f9179c5 100644 package x509 diff --git a/src/go.mod b/src/go.mod -index df27f25e789f05..3e9514234e7125 100644 +index df27f25e789f05..12d8c8f4f97321 100644 --- a/src/go.mod +++ b/src/go.mod @@ -3,6 +3,7 @@ module std @@ -726,7 +728,7 @@ index df27f25e789f05..3e9514234e7125 100644 golang.org/x/net v0.27.1-0.20240722181819-765c7e89b3bd ) diff --git a/src/go.sum b/src/go.sum -index b4efd6d3c50c11..d159c7d47bac3b 100644 +index b4efd6d3c50c11..4c3ca847c21cd2 100644 --- a/src/go.sum +++ b/src/go.sum @@ -1,3 +1,5 @@ @@ -786,6 +788,26 @@ index 7f6237ffd59c11..7c821ae4bc5727 100644 } // Verify that the vendor directories contain only packages matching the list above. +diff --git a/src/hash/boring_test.go b/src/hash/boring_test.go +index c90899062a9665..802c0f8b8987bf 100644 +--- a/src/hash/boring_test.go ++++ b/src/hash/boring_test.go +@@ -1,4 +1,4 @@ +-//go:build goexperiment.boringcrypto ++//go:build goexperiment.boringcrypto || goexperiment.opensslcrypto + + package hash_test + +diff --git a/src/hash/notboring_test.go b/src/hash/notboring_test.go +index 79f8c22f2b7416..f3e8ed3e1cbf20 100644 +--- a/src/hash/notboring_test.go ++++ b/src/hash/notboring_test.go +@@ -1,4 +1,4 @@ +-//go:build !goexperiment.boringcrypto ++//go:build !goexperiment.boringcrypto && !goexperiment.opensslcrypto + + package hash_test + diff --git a/src/internal/goexperiment/exp_opensslcrypto_off.go b/src/internal/goexperiment/exp_opensslcrypto_off.go new file mode 100644 index 00000000000000..62033547c6143a diff --git a/patches/0005-Add-CNG-crypto-backend.patch b/patches/0005-Add-CNG-crypto-backend.patch index fab2306d04..aac1155e60 100644 --- a/patches/0005-Add-CNG-crypto-backend.patch +++ b/patches/0005-Add-CNG-crypto-backend.patch @@ -36,11 +36,13 @@ Subject: [PATCH] Add CNG crypto backend src/go.sum | 2 + src/go/build/deps_test.go | 5 + src/go/build/vendor_test.go | 1 + + src/hash/boring_test.go | 2 +- src/hash/example_test.go | 2 + + src/hash/notboring_test.go | 2 +- .../goexperiment/exp_cngcrypto_off.go | 9 + src/internal/goexperiment/exp_cngcrypto_on.go | 9 + src/internal/goexperiment/flags.go | 1 + - 36 files changed, 390 insertions(+), 26 deletions(-) + 38 files changed, 392 insertions(+), 28 deletions(-) create mode 100644 src/crypto/ecdsa/badlinkname.go create mode 100644 src/crypto/internal/backend/bbig/big_cng.go create mode 100644 src/crypto/internal/backend/cng_windows.go @@ -810,6 +812,16 @@ index 7c821ae4bc5727..1d0b9b20e9b1d4 100644 } // Verify that the vendor directories contain only packages matching the list above. +diff --git a/src/hash/boring_test.go b/src/hash/boring_test.go +index 802c0f8b8987bf..99e1933f84b52c 100644 +--- a/src/hash/boring_test.go ++++ b/src/hash/boring_test.go +@@ -1,4 +1,4 @@ +-//go:build goexperiment.boringcrypto || goexperiment.opensslcrypto ++//go:build goexperiment.boringcrypto || goexperiment.opensslcrypto || goexperiment.cngcrypto + + package hash_test + diff --git a/src/hash/example_test.go b/src/hash/example_test.go index f07b9aaa2c4898..2ff6c4827391c0 100644 --- a/src/hash/example_test.go @@ -823,6 +835,16 @@ index f07b9aaa2c4898..2ff6c4827391c0 100644 package hash_test import ( +diff --git a/src/hash/notboring_test.go b/src/hash/notboring_test.go +index f3e8ed3e1cbf20..a85fc430cfa655 100644 +--- a/src/hash/notboring_test.go ++++ b/src/hash/notboring_test.go +@@ -1,4 +1,4 @@ +-//go:build !goexperiment.boringcrypto && !goexperiment.opensslcrypto ++//go:build !goexperiment.boringcrypto && !goexperiment.opensslcrypto && !goexperiment.cngcrypto + + package hash_test + diff --git a/src/internal/goexperiment/exp_cngcrypto_off.go b/src/internal/goexperiment/exp_cngcrypto_off.go new file mode 100644 index 00000000000000..831460053281e2