1- diff --git a/api/go1.19.txt b/api/go1.19.txt
2- index f31d633af9..e078f4aee1 100644
3- --- a/api/go1.19.txt
4- +++ b/api/go1.19.txt
5- @@ -290,6 +290,8 @@ pkg sync/atomic, type Uint64 struct #50860
6- pkg sync/atomic, type Uintptr struct #50860
7- pkg time, method (Duration) Abs() Duration #51414
8- pkg time, method (Time) ZoneBounds() (Time, Time) #50062
9- + pkg crypto/ecdsa, func HashSign(io.Reader, *PrivateKey, []uint8, crypto.Hash) (*big.Int, *big.Int, error) #000000
10- + pkg crypto/ecdsa, func HashVerify(*PublicKey, []uint8, *big.Int, *big.Int, crypto.Hash) bool #000000
11- pkg crypto/x509, func ParseCRL //deprecated #50674
12- pkg crypto/x509, func ParseDERCRL //deprecated #50674
13- pkg crypto/x509, method (*Certificate) CheckCRLSignature //deprecated #50674
141diff --git a/src/cmd/go/testdata/script/gopath_std_vendor.txt b/src/cmd/go/testdata/script/gopath_std_vendor.txt
152index 4aaf46b5d0..c231e299d9 100644
163--- a/src/cmd/go/testdata/script/gopath_std_vendor.txt
@@ -51,105 +38,6 @@ index 10da95afbb..af6bcd86f4 100644
5138 if testing.Short() {
5239 t.Skip("test requires running 'go build'")
5340 }
54- diff --git a/src/crypto/ecdsa/ecdsa_hashsignverify.go b/src/crypto/ecdsa/ecdsa_hashsignverify.go
55- new file mode 100644
56- index 0000000000..37f3a18223
57- --- /dev/null
58- +++ b/src/crypto/ecdsa/ecdsa_hashsignverify.go
59- @@ -0,0 +1,45 @@
60- + package ecdsa
61- +
62- + import (
63- + "crypto"
64- + "crypto/internal/boring"
65- + "crypto/internal/randutil"
66- + "math/big"
67- + "io"
68- + )
69- +
70- + func HashSign(rand io.Reader, priv *PrivateKey, msg []byte, h crypto.Hash) (*big.Int, *big.Int, error) {
71- + randutil.MaybeReadByte(rand)
72- +
73- + if boring.Enabled {
74- + b, err := boringPrivateKey(priv)
75- + if err != nil {
76- + return nil, nil, err
77- + }
78- + return boring.HashSignECDSA(b, msg, h)
79- + }
80- + boring.UnreachableExceptTests()
81- +
82- + hash := h.New()
83- + hash.Write(msg)
84- + d := hash.Sum(nil)
85- +
86- + return Sign(rand, priv, d)
87- + }
88- +
89- + func HashVerify(pub *PublicKey, msg []byte, r, s *big.Int, h crypto.Hash) bool {
90- + if boring.Enabled {
91- + bpk, err := boringPublicKey(pub)
92- + if err != nil {
93- + return false
94- + }
95- + return boring.HashVerifyECDSA(bpk, msg, r, s, h)
96- + }
97- + boring.UnreachableExceptTests()
98- +
99- + hash := h.New()
100- + hash.Write(msg)
101- + d := hash.Sum(nil)
102- +
103- + return Verify(pub, d, r, s)
104- + }
105- diff --git a/src/crypto/ecdsa/ecdsa_hashsignverify_test.go b/src/crypto/ecdsa/ecdsa_hashsignverify_test.go
106- new file mode 100644
107- index 0000000000..d12ba2f441
108- --- /dev/null
109- +++ b/src/crypto/ecdsa/ecdsa_hashsignverify_test.go
110- @@ -0,0 +1,42 @@
111- + package ecdsa
112- +
113- + import (
114- + "crypto"
115- + "crypto/internal/boring"
116- + "crypto/elliptic"
117- + "crypto/rand"
118- + "testing"
119- + )
120- +
121- + func testHashSignAndHashVerify(t *testing.T, c elliptic.Curve, tag string) {
122- + priv, err := GenerateKey(c, rand.Reader)
123- + if priv == nil {
124- + t.Fatal(err)
125- + }
126- +
127- + msg := []byte("testing")
128- + h := crypto.SHA256
129- + r, s, err := HashSign(rand.Reader, priv, msg, h)
130- + if err != nil {
131- + t.Errorf("%s: error signing: %s", tag, err)
132- + return
133- + }
134- +
135- + if !HashVerify(&priv.PublicKey, msg, r, s, h) {
136- + t.Errorf("%s: Verify failed", tag)
137- + }
138- +
139- + msg[0] ^= 0xff
140- + if HashVerify(&priv.PublicKey, msg, r, s, h) {
141- + t.Errorf("%s: Verify should not have succeeded", tag)
142- + }
143- + }
144- + func TestHashSignAndHashVerify(t *testing.T) {
145- + testHashSignAndHashVerify(t, elliptic.P256(), "p256")
146- +
147- + if testing.Short() && !boring.Enabled {
148- + return
149- + }
150- + testHashSignAndHashVerify(t, elliptic.P384(), "p384")
151- + testHashSignAndHashVerify(t, elliptic.P521(), "p521")
152- + }
15341diff --git a/src/crypto/ecdsa/ecdsa_test.go b/src/crypto/ecdsa/ecdsa_test.go
15442index 08a0903eb1..61a4662036 100644
15543--- a/src/crypto/ecdsa/ecdsa_test.go
@@ -247,50 +135,6 @@ index f933f2800a..223ce04340 100644
247135 testenv.MustHaveExternalNetwork(t)
248136
249137 // Create a temp dir and modcache subdir.
250- diff --git a/src/crypto/internal/backend/bbig/big.go b/src/crypto/internal/backend/bbig/big.go
251- new file mode 100644
252- index 0000000000..c0800df578
253- --- /dev/null
254- +++ b/src/crypto/internal/backend/bbig/big.go
255- @@ -0,0 +1,38 @@
256- + // Copyright 2022 The Go Authors. All rights reserved.
257- + // Use of this source code is governed by a BSD-style
258- + // license that can be found in the LICENSE file.
259- +
260- + // This is a mirror of crypto/internal/boring/bbig/big.go.
261- +
262- + package bbig
263- +
264- + import (
265- + "math/big"
266- + "unsafe"
267- +
268- + "github.com/golang-fips/openssl-fips/openssl"
269- + )
270- +
271- + func Enc(b *big.Int) openssl.BigInt {
272- + if b == nil {
273- + return nil
274- + }
275- + x := b.Bits()
276- + if len(x) == 0 {
277- + return openssl.BigInt{}
278- + }
279- + // TODO: Use unsafe.Slice((*uint)(&x[0]), len(x)) once go1.16 is no longer supported.
280- + return (*(*[]uint)(unsafe.Pointer(&x)))[:len(x)]
281- + }
282- +
283- + func Dec(b openssl.BigInt) *big.Int {
284- + if b == nil {
285- + return nil
286- + }
287- + if len(b) == 0 {
288- + return new(big.Int)
289- + }
290- + // TODO: Use unsafe.Slice((*uint)(&b[0]), len(b)) once go1.16 is no longer supported.
291- + x := (*(*[]big.Word)(unsafe.Pointer(&b)))[:len(b)]
292- + return new(big.Int).SetBits(x)
293- + }
294138diff --git a/src/crypto/internal/backend/boringtest/config.go b/src/crypto/internal/backend/boringtest/config.go
295139new file mode 100644
296140index 0000000000..6c8c00d11e
@@ -366,7 +210,7 @@ index 0000000000..15c1ee8cbe
366210+ "crypto/cipher"
367211+ "crypto/internal/boring/sig"
368212+ "math/big"
369- + "github.com/golang-fips/openssl-fips/openssl "
213+ + bbig "crypto/internal/boring "
370214+ "hash"
371215+ "io"
372216+ )
@@ -419,16 +263,16 @@ index 0000000000..15c1ee8cbe
419263+ func NewGCMTLS(c cipher.Block) (cipher.AEAD, error) {
420264+ panic("boringcrypto: not available")
421265+ }
422- + func GenerateKeyECDSA(curve string) (X, Y, D openssl .BigInt, err error) {
266+ + func GenerateKeyECDSA(curve string) (X, Y, D bbig .BigInt, err error) {
423267+ panic("boringcrypto: not available")
424268+ }
425- + func NewPrivateKeyECDSA(curve string, X, Y, D openssl .BigInt) (*PrivateKeyECDSA, error) {
269+ + func NewPrivateKeyECDSA(curve string, X, Y, D bbig .BigInt) (*PrivateKeyECDSA, error) {
426270+ panic("boringcrypto: not available")
427271+ }
428- + func NewPublicKeyECDSA(curve string, X, Y openssl .BigInt) (*PublicKeyECDSA, error) {
272+ + func NewPublicKeyECDSA(curve string, X, Y bbig .BigInt) (*PublicKeyECDSA, error) {
429273+ panic("boringcrypto: not available")
430274+ }
431- + func SignECDSA(priv *PrivateKeyECDSA, hash []byte, h crypto.Hash) (r, s openssl .BigInt, err error) {
275+ + func SignECDSA(priv *PrivateKeyECDSA, hash []byte, h crypto.Hash) (r, s bbig .BigInt, err error) {
432276+ panic("boringcrypto: not available")
433277+ }
434278+ func SignMarshalECDSA(priv *PrivateKeyECDSA, hash []byte) ([]byte, error) {
@@ -462,7 +306,7 @@ index 0000000000..15c1ee8cbe
462306+ type PublicKeyRSA struct{ _ int }
463307+ type PrivateKeyRSA struct{ _ int }
464308+
465- + func DecryptRSAOAEP(h hash.Hash, priv *PrivateKeyRSA, ciphertext, label []byte) ([]byte, error) {
309+ + func DecryptRSAOAEP(h, h2 hash.Hash, priv *PrivateKeyRSA, ciphertext, label []byte) ([]byte, error) {
466310+ panic("boringcrypto: not available")
467311+ }
468312+ func DecryptRSAPKCS1(priv *PrivateKeyRSA, ciphertext []byte) ([]byte, error) {
@@ -471,7 +315,7 @@ index 0000000000..15c1ee8cbe
471315+ func DecryptRSANoPadding(priv *PrivateKeyRSA, ciphertext []byte) ([]byte, error) {
472316+ panic("boringcrypto: not available")
473317+ }
474- + func EncryptRSAOAEP(h hash.Hash, pub *PublicKeyRSA, msg, label []byte) ([]byte, error) {
318+ + func EncryptRSAOAEP(h, h2 hash.Hash, pub *PublicKeyRSA, msg, label []byte) ([]byte, error) {
475319+ panic("boringcrypto: not available")
476320+ }
477321+ func EncryptRSAPKCS1(pub *PublicKeyRSA, msg []byte) ([]byte, error) {
@@ -480,20 +324,20 @@ index 0000000000..15c1ee8cbe
480324+ func EncryptRSANoPadding(pub *PublicKeyRSA, msg []byte) ([]byte, error) {
481325+ panic("boringcrypto: not available")
482326+ }
483- + func GenerateKeyRSA(bits int) (N, E, D, P, Q, Dp, Dq, Qinv openssl .BigInt, err error) {
327+ + func GenerateKeyRSA(bits int) (N, E, D, P, Q, Dp, Dq, Qinv bbig .BigInt, err error) {
484328+ panic("boringcrypto: not available")
485329+ }
486- + func NewPrivateKeyRSA(N, E, D, P, Q, Dp, Dq, Qinv openssl .BigInt) (*PrivateKeyRSA, error) {
330+ + func NewPrivateKeyRSA(N, E, D, P, Q, Dp, Dq, Qinv bbig .BigInt) (*PrivateKeyRSA, error) {
487331+ panic("boringcrypto: not available")
488332+ }
489- + func NewPublicKeyRSA(N, E openssl .BigInt) (*PublicKeyRSA, error) { panic("boringcrypto: not available") }
490- + func SignRSAPKCS1v15(priv *PrivateKeyRSA, h crypto.Hash, hashed []byte, msgHashed bool ) ([]byte, error) {
333+ + func NewPublicKeyRSA(N, E bbig .BigInt) (*PublicKeyRSA, error) { panic("boringcrypto: not available") }
334+ + func SignRSAPKCS1v15(priv *PrivateKeyRSA, h crypto.Hash, hashed []byte) ([]byte, error) {
491335+ panic("boringcrypto: not available")
492336+ }
493337+ func SignRSAPSS(priv *PrivateKeyRSA, h crypto.Hash, hashed []byte, saltLen int) ([]byte, error) {
494338+ panic("boringcrypto: not available")
495339+ }
496- + func VerifyRSAPKCS1v15(pub *PublicKeyRSA, h crypto.Hash, hashed, sig []byte, msgHashed bool ) error {
340+ + func VerifyRSAPKCS1v15(pub *PublicKeyRSA, h crypto.Hash, hashed, sig []byte) error {
497341+ panic("boringcrypto: not available")
498342+ }
499343+ func VerifyRSAPSS(pub *PublicKeyRSA, h crypto.Hash, hashed, sig []byte, saltLen int) error {
@@ -520,7 +364,7 @@ new file mode 100644
520364index 0000000000..2087c555a4
521365--- /dev/null
522366+++ b/src/crypto/internal/backend/openssl.go
523- @@ -0,0 +1,106 @@
367+ @@ -0,0 +1,122 @@
524368+ // Copyright 2017 The Go Authors. All rights reserved.
525369+ // Use of this source code is governed by a BSD-style
526370+ // license that can be found in the LICENSE file.
@@ -534,11 +378,20 @@ index 0000000000..2087c555a4
534378+ package backend
535379+
536380+ import (
537- + "github.com/golang-fips/openssl-fips/openssl"
381+ + "os"
382+ + "github.com/golang-fips/openssl/v2"
538383+ )
539384+
540385+ // Enabled controls whether FIPS crypto is enabled.
541- + var Enabled = openssl.Enabled
386+ + var enabled bool
387+ +
388+ + func init() {
389+ + enabled = openssl.FIPS()
390+ + }
391+ +
392+ + func Enabled() bool {
393+ + return enabled
394+ + }
542395+
543396+ // Unreachable marks code that should be unreachable
544397+ // when OpenSSLCrypto is in use. It panics only when
@@ -549,6 +402,13 @@ index 0000000000..2087c555a4
549402+ }
550403+ }
551404+
405+ + // ExecutingTest returns a boolean indicating if we're
406+ + // executing under a test binary or not.
407+ + func ExecutingTest() bool {
408+ + name := os.Args[0]
409+ + return hasSuffix(name, "_test") || hasSuffix(name, ".test")
410+ + }
411+ +
552412+ // Provided by runtime.crypto_backend_runtime_arg0 to avoid os import.
553413+ func runtime_arg0() string
554414+
@@ -567,7 +427,7 @@ index 0000000000..2087c555a4
567427+ }
568428+ }
569429+
570- + var ExecutingTest = openssl.ExecutingTest
430+ +
571431+
572432+ const RandReader = openssl.RandReader
573433+
@@ -627,6 +487,27 @@ index 0000000000..2087c555a4
627487+ var ExtractHKDF = openssl.ExtractHKDF
628488+ var ExpandHKDF = openssl.ExpandHKDF
629489+ var SupportsHKDF = openssl.SupportsHKDF
490+ diff --git a/src/crypto/internal/backend/bbig/big.go b/src/crypto/internal/backend/bbig/big.go
491+ new file mode 100644
492+ index 0000000000..7fac1ec7e1
493+ --- /dev/null
494+ +++ b/src/crypto/internal/backend/bbig/big.go
495+ @@ -0,0 +1,15 @@
496+ + // Copyright 2022 The Go Authors. All rights reserved.
497+ + // Use of this source code is governed by a BSD-style
498+ + // license that can be found in the LICENSE file.
499+ +
500+ + // This is a mirror of
501+ + // https://github.com/golang/go/blob/36b87f273cc43e21685179dc1664ebb5493d26ae/src/crypto/internal/boring/bbig/big.go.
502+ +
503+ + package bbig
504+ +
505+ + import (
506+ + "github.com/golang-fips/openssl/v2/bbig"
507+ + )
508+ +
509+ + var Enc = bbig.Enc
510+ + var Dec = bbig.Dec
630511diff --git a/src/crypto/rsa/pkcs1v15_test.go b/src/crypto/rsa/pkcs1v15_test.go
631512index dfa1eddc88..39a4fc184a 100644
632513--- a/src/crypto/rsa/pkcs1v15_test.go
@@ -862,7 +743,7 @@ index 63bc8dad1a..ab56ccd1ed 100644
862743 return nil, err
863744 }
864745- return boring.EncryptRSAOAEP(hash, hash, bkey, msg, label)
865- + return boring.EncryptRSAOAEP(hash, bkey, msg, label)
746+ + return boring.EncryptRSAOAEP(hash, hash, bkey, msg, label)
866747 }
867748 boring.UnreachableExceptTests()
868749
@@ -871,7 +752,7 @@ index 63bc8dad1a..ab56ccd1ed 100644
871752 return nil, err
872753 }
873754- out, err := boring.DecryptRSAOAEP(hash, mgfHash, bkey, ciphertext, label)
874- + out, err := boring.DecryptRSAOAEP(hash, bkey, ciphertext, label)
755+ + out, err := boring.DecryptRSAOAEP(hash, mgfHash, bkey, ciphertext, label)
875756 if err != nil {
876757 return nil, ErrDecryption
877758 }
@@ -1577,7 +1458,7 @@ index 08452c7b1d..0732db0662 100644
15771458+ fmt, crypto/cipher,
15781459 crypto/internal/boring/bcache
15791460 < crypto/internal/boring
1580- + < github.com/golang-fips/openssl-fips/openssl
1461+ + < github.com/golang-fips/openssl/v2
15811462+ < crypto/internal/backend
15821463 < crypto/boring;
15831464
@@ -1591,7 +1472,7 @@ index 08452c7b1d..0732db0662 100644
15911472
15921473 # CRYPTO-MATH is core bignum-based crypto - no cgo, net; fmt now ok.
15931474 CRYPTO, FMT, math/big
1594- + < github.com/golang-fips/openssl-fips/openssl /bbig
1475+ + < github.com/golang-fips/openssl/v2 /bbig
15951476 < crypto/internal/boring/bbig
15961477+ < crypto/internal/backend/bbig
15971478 < crypto/rand
@@ -1601,7 +1482,7 @@ index 08452c7b1d..0732db0662 100644
16011482 }
16021483
16031484 func TestDependencies(t *testing.T) {
1604- + t.Skip("openssl-fips based toolchain has different dependencies than upstream")
1485+ + t.Skip("openssl based toolchain has different dependencies than upstream")
16051486 if !testenv.HasSrc() {
16061487 // Tests run in a limited file system and we do not
16071488 // provide access to every source file.
@@ -1619,7 +1500,7 @@ index 08452c7b1d..0732db0662 100644
16191500 var imports []string
16201501 var haveImport = map[string]bool{}
16211502- if pkg == "crypto/internal/boring" {
1622- + if pkg == "crypto/internal/boring" || pkg == "github.com/golang-fips/openssl-fips/openssl " {
1503+ + if pkg == "crypto/internal/boring" || pkg == "github.com/golang-fips/openssl/v2 " {
16231504 haveImport["C"] = true // kludge: prevent C from appearing in crypto/internal/boring imports
16241505 }
16251506 fset := token.NewFileSet()
0 commit comments