|
|
42489d |
diff --git a/api/go1.19.txt b/api/go1.19.txt
|
|
|
42489d |
index 523f752..778e1d5 100644
|
|
|
42489d |
--- a/api/go1.19.txt
|
|
|
42489d |
+++ b/api/go1.19.txt
|
|
|
42489d |
@@ -290,3 +290,5 @@ pkg sync/atomic, type Uint64 struct #50860
|
|
|
42489d |
pkg sync/atomic, type Uintptr struct #50860
|
|
|
42489d |
pkg time, method (Duration) Abs() Duration #51414
|
|
|
42489d |
pkg time, method (Time) ZoneBounds() (Time, Time) #50062
|
|
|
42489d |
+pkg crypto/ecdsa, func HashSign(io.Reader, *PrivateKey, []uint8, crypto.Hash) (*big.Int, *big.Int, error) #000000
|
|
|
42489d |
+pkg crypto/ecdsa, func HashVerify(*PublicKey, []uint8, *big.Int, *big.Int, crypto.Hash) bool #000000
|
|
|
28fbfc |
diff --git a/src/cmd/go/testdata/script/gopath_std_vendor.txt b/src/cmd/go/testdata/script/gopath_std_vendor.txt
|
|
|
28fbfc |
index a0a41a5..208aa70 100644
|
|
|
28fbfc |
--- a/src/cmd/go/testdata/script/gopath_std_vendor.txt
|
|
|
28fbfc |
+++ b/src/cmd/go/testdata/script/gopath_std_vendor.txt
|
|
|
28fbfc |
@@ -21,11 +21,11 @@ go build .
|
|
|
28fbfc |
|
|
|
28fbfc |
go list -deps -f '{{.ImportPath}} {{.Dir}}' .
|
|
|
28fbfc |
stdout $GOPATH[/\\]src[/\\]vendor[/\\]golang.org[/\\]x[/\\]net[/\\]http2[/\\]hpack
|
|
|
28fbfc |
-! stdout $GOROOT[/\\]src[/\\]vendor
|
|
|
28fbfc |
+! stdout $GOROOT[/\\]src[/\\]vendor[/\\]golang.org[/\\]x[/\\]net[/\\]http2[/\\]hpack
|
|
|
28fbfc |
|
|
|
28fbfc |
go list -test -deps -f '{{.ImportPath}} {{.Dir}}' .
|
|
|
28fbfc |
stdout $GOPATH[/\\]src[/\\]vendor[/\\]golang.org[/\\]x[/\\]net[/\\]http2[/\\]hpack
|
|
|
28fbfc |
-! stdout $GOROOT[/\\]src[/\\]vendor
|
|
|
28fbfc |
+! stdout $GOROOT[/\\]src[/\\]vendor[/\\]golang.org[/\\]x[/\\]net[/\\]http2[/\\]hpack
|
|
|
28fbfc |
|
|
|
28fbfc |
-- issue16333/issue16333.go --
|
|
|
28fbfc |
package vendoring17
|
|
|
42489d |
diff --git a/src/crypto/ecdsa/ecdsa_hashsignverify.go b/src/crypto/ecdsa/ecdsa_hashsignverify.go
|
|
|
42489d |
new file mode 100644
|
|
|
42489d |
index 0000000..37f3a18
|
|
|
42489d |
--- /dev/null
|
|
|
42489d |
+++ b/src/crypto/ecdsa/ecdsa_hashsignverify.go
|
|
|
42489d |
@@ -0,0 +1,45 @@
|
|
|
42489d |
+package ecdsa
|
|
|
42489d |
+
|
|
|
42489d |
+import (
|
|
|
42489d |
+ "crypto"
|
|
|
42489d |
+ "crypto/internal/boring"
|
|
|
42489d |
+ "crypto/internal/randutil"
|
|
|
42489d |
+ "math/big"
|
|
|
42489d |
+ "io"
|
|
|
42489d |
+)
|
|
|
42489d |
+
|
|
|
42489d |
+func HashSign(rand io.Reader, priv *PrivateKey, msg []byte, h crypto.Hash) (*big.Int, *big.Int, error) {
|
|
|
42489d |
+ randutil.MaybeReadByte(rand)
|
|
|
42489d |
+
|
|
|
42489d |
+ if boring.Enabled {
|
|
|
42489d |
+ b, err := boringPrivateKey(priv)
|
|
|
42489d |
+ if err != nil {
|
|
|
42489d |
+ return nil, nil, err
|
|
|
42489d |
+ }
|
|
|
42489d |
+ return boring.HashSignECDSA(b, msg, h)
|
|
|
42489d |
+ }
|
|
|
42489d |
+ boring.UnreachableExceptTests()
|
|
|
42489d |
+
|
|
|
42489d |
+ hash := h.New()
|
|
|
42489d |
+ hash.Write(msg)
|
|
|
42489d |
+ d := hash.Sum(nil)
|
|
|
42489d |
+
|
|
|
42489d |
+ return Sign(rand, priv, d)
|
|
|
42489d |
+}
|
|
|
42489d |
+
|
|
|
42489d |
+func HashVerify(pub *PublicKey, msg []byte, r, s *big.Int, h crypto.Hash) bool {
|
|
|
42489d |
+ if boring.Enabled {
|
|
|
42489d |
+ bpk, err := boringPublicKey(pub)
|
|
|
42489d |
+ if err != nil {
|
|
|
42489d |
+ return false
|
|
|
42489d |
+ }
|
|
|
42489d |
+ return boring.HashVerifyECDSA(bpk, msg, r, s, h)
|
|
|
42489d |
+ }
|
|
|
42489d |
+ boring.UnreachableExceptTests()
|
|
|
42489d |
+
|
|
|
42489d |
+ hash := h.New()
|
|
|
42489d |
+ hash.Write(msg)
|
|
|
42489d |
+ d := hash.Sum(nil)
|
|
|
42489d |
+
|
|
|
42489d |
+ return Verify(pub, d, r, s)
|
|
|
42489d |
+}
|
|
|
42489d |
diff --git a/src/crypto/ecdsa/ecdsa_hashsignverify_test.go b/src/crypto/ecdsa/ecdsa_hashsignverify_test.go
|
|
|
42489d |
new file mode 100644
|
|
|
42489d |
index 0000000..d12ba2f
|
|
|
42489d |
--- /dev/null
|
|
|
42489d |
+++ b/src/crypto/ecdsa/ecdsa_hashsignverify_test.go
|
|
|
42489d |
@@ -0,0 +1,42 @@
|
|
|
42489d |
+package ecdsa
|
|
|
42489d |
+
|
|
|
42489d |
+import (
|
|
|
42489d |
+ "crypto"
|
|
|
42489d |
+ "crypto/internal/boring"
|
|
|
42489d |
+ "crypto/elliptic"
|
|
|
42489d |
+ "crypto/rand"
|
|
|
42489d |
+ "testing"
|
|
|
42489d |
+)
|
|
|
42489d |
+
|
|
|
42489d |
+func testHashSignAndHashVerify(t *testing.T, c elliptic.Curve, tag string) {
|
|
|
42489d |
+ priv, err := GenerateKey(c, rand.Reader)
|
|
|
42489d |
+ if priv == nil {
|
|
|
42489d |
+ t.Fatal(err)
|
|
|
42489d |
+ }
|
|
|
42489d |
+
|
|
|
42489d |
+ msg := []byte("testing")
|
|
|
42489d |
+ h := crypto.SHA256
|
|
|
42489d |
+ r, s, err := HashSign(rand.Reader, priv, msg, h)
|
|
|
42489d |
+ if err != nil {
|
|
|
42489d |
+ t.Errorf("%s: error signing: %s", tag, err)
|
|
|
42489d |
+ return
|
|
|
42489d |
+ }
|
|
|
42489d |
+
|
|
|
42489d |
+ if !HashVerify(&priv.PublicKey, msg, r, s, h) {
|
|
|
42489d |
+ t.Errorf("%s: Verify failed", tag)
|
|
|
42489d |
+ }
|
|
|
42489d |
+
|
|
|
42489d |
+ msg[0] ^= 0xff
|
|
|
42489d |
+ if HashVerify(&priv.PublicKey, msg, r, s, h) {
|
|
|
42489d |
+ t.Errorf("%s: Verify should not have succeeded", tag)
|
|
|
42489d |
+ }
|
|
|
42489d |
+}
|
|
|
42489d |
+func TestHashSignAndHashVerify(t *testing.T) {
|
|
|
42489d |
+ testHashSignAndHashVerify(t, elliptic.P256(), "p256")
|
|
|
42489d |
+
|
|
|
42489d |
+ if testing.Short() && !boring.Enabled {
|
|
|
42489d |
+ return
|
|
|
42489d |
+ }
|
|
|
42489d |
+ testHashSignAndHashVerify(t, elliptic.P384(), "p384")
|
|
|
42489d |
+ testHashSignAndHashVerify(t, elliptic.P521(), "p521")
|
|
|
42489d |
+}
|
|
|
28fbfc |
diff --git a/src/crypto/ed25519/ed25519_test.go b/src/crypto/ed25519/ed25519_test.go
|
|
|
28fbfc |
index 7c51817..102c4e5 100644
|
|
|
28fbfc |
--- a/src/crypto/ed25519/ed25519_test.go
|
|
|
28fbfc |
+++ b/src/crypto/ed25519/ed25519_test.go
|
|
|
28fbfc |
@@ -187,6 +187,7 @@ func TestMalleability(t *testing.T) {
|
|
|
28fbfc |
}
|
|
|
28fbfc |
|
|
|
28fbfc |
func TestAllocations(t *testing.T) {
|
|
|
28fbfc |
+ t.Skip("Allocations test broken with openssl linkage")
|
|
|
28fbfc |
if boring.Enabled {
|
|
|
28fbfc |
t.Skip("skipping allocations test with BoringCrypto")
|
|
|
28fbfc |
}
|
|
|
28fbfc |
diff --git a/src/crypto/ed25519/ed25519vectors_test.go b/src/crypto/ed25519/ed25519vectors_test.go
|
|
|
28fbfc |
index f933f28..223ce04 100644
|
|
|
28fbfc |
--- a/src/crypto/ed25519/ed25519vectors_test.go
|
|
|
28fbfc |
+++ b/src/crypto/ed25519/ed25519vectors_test.go
|
|
|
28fbfc |
@@ -72,6 +72,7 @@ func TestEd25519Vectors(t *testing.T) {
|
|
|
28fbfc |
}
|
|
|
28fbfc |
|
|
|
28fbfc |
func downloadEd25519Vectors(t *testing.T) []byte {
|
|
|
28fbfc |
+ t.Skip("skipping test that downloads external data")
|
|
|
28fbfc |
testenv.MustHaveExternalNetwork(t)
|
|
|
28fbfc |
|
|
|
28fbfc |
// Create a temp dir and modcache subdir.
|
|
|
28fbfc |
diff --git a/src/crypto/internal/backend/bbig/big.go b/src/crypto/internal/backend/bbig/big.go
|
|
|
28fbfc |
new file mode 100644
|
|
|
28fbfc |
index 0000000..c0800df
|
|
|
28fbfc |
--- /dev/null
|
|
|
28fbfc |
+++ b/src/crypto/internal/backend/bbig/big.go
|
|
|
28fbfc |
@@ -0,0 +1,38 @@
|
|
|
28fbfc |
+// Copyright 2022 The Go Authors. All rights reserved.
|
|
|
28fbfc |
+// Use of this source code is governed by a BSD-style
|
|
|
28fbfc |
+// license that can be found in the LICENSE file.
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+// This is a mirror of crypto/internal/boring/bbig/big.go.
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+package bbig
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+import (
|
|
|
28fbfc |
+ "math/big"
|
|
|
28fbfc |
+ "unsafe"
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+ "github.com/golang-fips/openssl-fips/openssl"
|
|
|
28fbfc |
+)
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+func Enc(b *big.Int) openssl.BigInt {
|
|
|
28fbfc |
+ if b == nil {
|
|
|
28fbfc |
+ return nil
|
|
|
28fbfc |
+ }
|
|
|
28fbfc |
+ x := b.Bits()
|
|
|
28fbfc |
+ if len(x) == 0 {
|
|
|
28fbfc |
+ return openssl.BigInt{}
|
|
|
28fbfc |
+ }
|
|
|
28fbfc |
+ // TODO: Use unsafe.Slice((*uint)(&x[0]), len(x)) once go1.16 is no longer supported.
|
|
|
28fbfc |
+ return (*(*[]uint)(unsafe.Pointer(&x)))[:len(x)]
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+func Dec(b openssl.BigInt) *big.Int {
|
|
|
28fbfc |
+ if b == nil {
|
|
|
28fbfc |
+ return nil
|
|
|
28fbfc |
+ }
|
|
|
28fbfc |
+ if len(b) == 0 {
|
|
|
28fbfc |
+ return new(big.Int)
|
|
|
28fbfc |
+ }
|
|
|
28fbfc |
+ // TODO: Use unsafe.Slice((*uint)(&b[0]), len(b)) once go1.16 is no longer supported.
|
|
|
28fbfc |
+ x := (*(*[]big.Word)(unsafe.Pointer(&b)))[:len(b)]
|
|
|
28fbfc |
+ return new(big.Int).SetBits(x)
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
diff --git a/src/crypto/internal/backend/dummy.s b/src/crypto/internal/backend/dummy.s
|
|
|
28fbfc |
new file mode 100644
|
|
|
28fbfc |
index 0000000..e69de29
|
|
|
28fbfc |
diff --git a/src/crypto/internal/backend/nobackend.go b/src/crypto/internal/backend/nobackend.go
|
|
|
28fbfc |
new file mode 100644
|
|
|
42489d |
index 0000000..482ed6f
|
|
|
28fbfc |
--- /dev/null
|
|
|
28fbfc |
+++ b/src/crypto/internal/backend/nobackend.go
|
|
|
42489d |
@@ -0,0 +1,155 @@
|
|
|
28fbfc |
+// Copyright 2017 The Go Authors. All rights reserved.
|
|
|
28fbfc |
+// Use of this source code is governed by a BSD-style
|
|
|
28fbfc |
+// license that can be found in the LICENSE file.
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+//go:build !linux || !cgo || android || cmd_go_bootstrap || msan || no_openssl
|
|
|
28fbfc |
+// +build !linux !cgo android cmd_go_bootstrap msan no_openssl
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+package backend
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+import (
|
|
|
28fbfc |
+ "crypto"
|
|
|
28fbfc |
+ "crypto/cipher"
|
|
|
28fbfc |
+ "crypto/internal/boring/sig"
|
|
|
42489d |
+ "math/big"
|
|
|
28fbfc |
+ "github.com/golang-fips/openssl-fips/openssl"
|
|
|
28fbfc |
+ "hash"
|
|
|
42489d |
+ "io"
|
|
|
28fbfc |
+)
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+var enabled = false
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+// Unreachable marks code that should be unreachable
|
|
|
28fbfc |
+// when BoringCrypto is in use. It is a no-op without BoringCrypto.
|
|
|
28fbfc |
+func Unreachable() {
|
|
|
28fbfc |
+ // Code that's unreachable when using BoringCrypto
|
|
|
28fbfc |
+ // is exactly the code we want to detect for reporting
|
|
|
28fbfc |
+ // standard Go crypto.
|
|
|
28fbfc |
+ sig.StandardCrypto()
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+// UnreachableExceptTests marks code that should be unreachable
|
|
|
28fbfc |
+// when BoringCrypto is in use. It is a no-op without BoringCrypto.
|
|
|
28fbfc |
+func UnreachableExceptTests() {}
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+func ExecutingTest() bool { return false }
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+// This is a noop withotu BoringCrytpo.
|
|
|
28fbfc |
+func PanicIfStrictFIPS(v interface{}) {}
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+type randReader int
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+func (randReader) Read(b []byte) (int, error) { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+const RandReader = randReader(0)
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+func Enabled() bool { return false }
|
|
|
28fbfc |
+func NewSHA1() hash.Hash { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+func NewSHA224() hash.Hash { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+func NewSHA256() hash.Hash { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+func NewSHA384() hash.Hash { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+func NewSHA512() hash.Hash { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+func SHA1(_ []byte) [20]byte { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+func SHA224(_ []byte) [28]byte { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+func SHA256(_ []byte) [32]byte { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+func SHA384(_ []byte) [48]byte { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+func SHA512(_ []byte) [64]byte { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+func NewHMAC(h func() hash.Hash, key []byte) hash.Hash { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+func NewAESCipher(key []byte) (cipher.Block, error) { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+type PublicKeyECDSA struct{ _ int }
|
|
|
28fbfc |
+type PrivateKeyECDSA struct{ _ int }
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+func NewGCMTLS(c cipher.Block) (cipher.AEAD, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func GenerateKeyECDSA(curve string) (X, Y, D openssl.BigInt, err error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func NewPrivateKeyECDSA(curve string, X, Y, D openssl.BigInt) (*PrivateKeyECDSA, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func NewPublicKeyECDSA(curve string, X, Y openssl.BigInt) (*PublicKeyECDSA, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func SignECDSA(priv *PrivateKeyECDSA, hash []byte, h crypto.Hash) (r, s openssl.BigInt, err error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func SignMarshalECDSA(priv *PrivateKeyECDSA, hash []byte) ([]byte, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func VerifyECDSA(pub *PublicKeyECDSA, hash, sig []byte) bool {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+type PublicKeyECDH struct{ _ int }
|
|
|
28fbfc |
+type PrivateKeyECDH struct{ _ int }
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+func GenerateKeyECDH(curve string) (X, Y, D openssl.BigInt, err error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func NewPrivateKeyECDH(curve string, X, Y, D openssl.BigInt) (*PrivateKeyECDH, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func NewPublicKeyECDH(curve string, X, Y openssl.BigInt) (*PublicKeyECDH, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func SharedKeyECDH(priv *PrivateKeyECDH, peerPublicKey []byte) ([]byte, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+type PublicKeyRSA struct{ _ int }
|
|
|
28fbfc |
+type PrivateKeyRSA struct{ _ int }
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+func DecryptRSAOAEP(h hash.Hash, priv *PrivateKeyRSA, ciphertext, label []byte) ([]byte, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func DecryptRSAPKCS1(priv *PrivateKeyRSA, ciphertext []byte) ([]byte, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func DecryptRSANoPadding(priv *PrivateKeyRSA, ciphertext []byte) ([]byte, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func EncryptRSAOAEP(h hash.Hash, pub *PublicKeyRSA, msg, label []byte) ([]byte, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func EncryptRSAPKCS1(pub *PublicKeyRSA, msg []byte) ([]byte, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func EncryptRSANoPadding(pub *PublicKeyRSA, msg []byte) ([]byte, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func GenerateKeyRSA(bits int) (N, E, D, P, Q, Dp, Dq, Qinv openssl.BigInt, err error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func NewPrivateKeyRSA(N, E, D, P, Q, Dp, Dq, Qinv openssl.BigInt) (*PrivateKeyRSA, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func NewPublicKeyRSA(N, E openssl.BigInt) (*PublicKeyRSA, error) { panic("boringcrypto: not available") }
|
|
|
28fbfc |
+func SignRSAPKCS1v15(priv *PrivateKeyRSA, h crypto.Hash, hashed []byte, msgHashed bool) ([]byte, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func SignRSAPSS(priv *PrivateKeyRSA, h crypto.Hash, hashed []byte, saltLen int) ([]byte, error) {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func VerifyRSAPKCS1v15(pub *PublicKeyRSA, h crypto.Hash, hashed, sig []byte, msgHashed bool) error {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+func VerifyRSAPSS(pub *PublicKeyRSA, h crypto.Hash, hashed, sig []byte, saltLen int) error {
|
|
|
28fbfc |
+ panic("boringcrypto: not available")
|
|
|
28fbfc |
+}
|
|
|
42489d |
+
|
|
|
42489d |
+func ExtractHKDF(h func() hash.Hash, secret, salt []byte) ([]byte, error) {
|
|
|
42489d |
+ panic("boringcrypto: not available")
|
|
|
42489d |
+}
|
|
|
42489d |
+func ExpandHKDF(h func() hash.Hash, pseudorandomKey, info []byte) (io.Reader, error) {
|
|
|
42489d |
+ panic("boringcrypto: not available")
|
|
|
42489d |
+}
|
|
|
42489d |
+func HashVerifyECDSA(pub *PublicKeyECDSA, msg []byte, r, s *big.Int, h crypto.Hash) bool {
|
|
|
42489d |
+ panic("boringcrypto: not available")
|
|
|
42489d |
+}
|
|
|
42489d |
+func HashSignECDSA(priv *PrivateKeyECDSA, hash []byte, h crypto.Hash) (*big.Int, *big.Int, error) {
|
|
|
42489d |
+ panic("boringcrypto: not available")
|
|
|
42489d |
+}
|
|
|
28fbfc |
diff --git a/src/crypto/internal/backend/openssl.go b/src/crypto/internal/backend/openssl.go
|
|
|
28fbfc |
new file mode 100644
|
|
|
42489d |
index 0000000..4040c77
|
|
|
28fbfc |
--- /dev/null
|
|
|
28fbfc |
+++ b/src/crypto/internal/backend/openssl.go
|
|
|
42489d |
@@ -0,0 +1,105 @@
|
|
|
28fbfc |
+// Copyright 2017 The Go Authors. All rights reserved.
|
|
|
28fbfc |
+// Use of this source code is governed by a BSD-style
|
|
|
28fbfc |
+// license that can be found in the LICENSE file.
|
|
|
28fbfc |
+
|
|
|
42489d |
+//go:build linux && cgo && !android && !gocrypt && !cmd_go_bootstrap && !msan && !no_openssl
|
|
|
42489d |
+// +build linux,cgo,!android,!gocrypt,!cmd_go_bootstrap,!msan,!no_openssl
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+// Package openssl provides access to OpenSSLCrypto implementation functions.
|
|
|
28fbfc |
+// Check the variable Enabled to find out whether OpenSSLCrypto is available.
|
|
|
28fbfc |
+// If OpenSSLCrypto is not available, the functions in this package all panic.
|
|
|
28fbfc |
+package backend
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+import (
|
|
|
28fbfc |
+ "github.com/golang-fips/openssl-fips/openssl"
|
|
|
28fbfc |
+)
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+// Enabled controls whether FIPS crypto is enabled.
|
|
|
28fbfc |
+var Enabled = openssl.Enabled
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+// Unreachable marks code that should be unreachable
|
|
|
28fbfc |
+// when OpenSSLCrypto is in use. It panics only when
|
|
|
28fbfc |
+// the system is in FIPS mode.
|
|
|
28fbfc |
+func Unreachable() {
|
|
|
28fbfc |
+ if Enabled() {
|
|
|
28fbfc |
+ panic("opensslcrypto: invalid code execution")
|
|
|
28fbfc |
+ }
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+// Provided by runtime.crypto_backend_runtime_arg0 to avoid os import.
|
|
|
28fbfc |
+func runtime_arg0() string
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+func hasSuffix(s, t string) bool {
|
|
|
28fbfc |
+ return len(s) > len(t) && s[len(s)-len(t):] == t
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+// UnreachableExceptTests marks code that should be unreachable
|
|
|
28fbfc |
+// when OpenSSLCrypto is in use. It panics.
|
|
|
28fbfc |
+func UnreachableExceptTests() {
|
|
|
28fbfc |
+ name := runtime_arg0()
|
|
|
28fbfc |
+ // If OpenSSLCrypto ran on Windows we'd need to allow _test.exe and .test.exe as well.
|
|
|
28fbfc |
+ if Enabled() && !hasSuffix(name, "_test") && !hasSuffix(name, ".test") {
|
|
|
28fbfc |
+ println("opensslcrypto: unexpected code execution in", name)
|
|
|
28fbfc |
+ panic("opensslcrypto: invalid code execution")
|
|
|
28fbfc |
+ }
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+var ExecutingTest = openssl.ExecutingTest
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+const RandReader = openssl.RandReader
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+var NewGCMTLS = openssl.NewGCMTLS
|
|
|
28fbfc |
+var NewSHA1 = openssl.NewSHA1
|
|
|
28fbfc |
+var NewSHA224 = openssl.NewSHA224
|
|
|
28fbfc |
+var NewSHA256 = openssl.NewSHA256
|
|
|
28fbfc |
+var NewSHA384 = openssl.NewSHA384
|
|
|
28fbfc |
+var NewSHA512 = openssl.NewSHA512
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+var SHA1 = openssl.SHA1
|
|
|
28fbfc |
+var SHA224 = openssl.SHA224
|
|
|
28fbfc |
+var SHA256 = openssl.SHA256
|
|
|
28fbfc |
+var SHA384 = openssl.SHA384
|
|
|
28fbfc |
+var SHA512 = openssl.SHA512
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+var NewHMAC = openssl.NewHMAC
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+var NewAESCipher = openssl.NewAESCipher
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+type PublicKeyECDSA = openssl.PublicKeyECDSA
|
|
|
28fbfc |
+type PrivateKeyECDSA = openssl.PrivateKeyECDSA
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+var GenerateKeyECDSA = openssl.GenerateKeyECDSA
|
|
|
28fbfc |
+var NewPrivateKeyECDSA = openssl.NewPrivateKeyECDSA
|
|
|
28fbfc |
+var NewPublicKeyECDSA = openssl.NewPublicKeyECDSA
|
|
|
28fbfc |
+var SignMarshalECDSA = openssl.SignMarshalECDSA
|
|
|
28fbfc |
+var VerifyECDSA = openssl.VerifyECDSA
|
|
|
42489d |
+var HashVerifyECDSA = openssl.HashVerifyECDSA
|
|
|
42489d |
+var HashSignECDSA = openssl.HashSignECDSA
|
|
|
42489d |
+
|
|
|
42489d |
+type PublicKeyECDH = openssl.PublicKeyECDH
|
|
|
42489d |
+type PrivateKeyECDH = openssl.PrivateKeyECDH
|
|
|
42489d |
+
|
|
|
42489d |
+var GenerateKeyECDH = openssl.GenerateKeyECDH
|
|
|
42489d |
+var NewPrivateKeyECDH = openssl.NewPrivateKeyECDH
|
|
|
42489d |
+var NewPublicKeyECDH = openssl.NewPublicKeyECDH
|
|
|
42489d |
+var SharedKeyECDH = openssl.SharedKeyECDH
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+type PublicKeyRSA = openssl.PublicKeyRSA
|
|
|
28fbfc |
+type PrivateKeyRSA = openssl.PrivateKeyRSA
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+var DecryptRSAOAEP = openssl.DecryptRSAOAEP
|
|
|
28fbfc |
+var DecryptRSAPKCS1 = openssl.DecryptRSAPKCS1
|
|
|
28fbfc |
+var DecryptRSANoPadding = openssl.DecryptRSANoPadding
|
|
|
28fbfc |
+var EncryptRSAOAEP = openssl.EncryptRSAOAEP
|
|
|
28fbfc |
+var EncryptRSAPKCS1 = openssl.EncryptRSAPKCS1
|
|
|
28fbfc |
+var EncryptRSANoPadding = openssl.EncryptRSANoPadding
|
|
|
28fbfc |
+var GenerateKeyRSA = openssl.GenerateKeyRSA
|
|
|
28fbfc |
+var NewPrivateKeyRSA = openssl.NewPrivateKeyRSA
|
|
|
28fbfc |
+var NewPublicKeyRSA = openssl.NewPublicKeyRSA
|
|
|
28fbfc |
+var SignRSAPKCS1v15 = openssl.SignRSAPKCS1v15
|
|
|
28fbfc |
+var SignRSAPSS = openssl.SignRSAPSS
|
|
|
28fbfc |
+var VerifyRSAPKCS1v15 = openssl.VerifyRSAPKCS1v15
|
|
|
28fbfc |
+var VerifyRSAPSS = openssl.VerifyRSAPSS
|
|
|
42489d |
+
|
|
|
42489d |
+var ExtractHKDF = openssl.ExtractHKDF
|
|
|
42489d |
+var ExpandHKDF = openssl.ExpandHKDF
|
|
|
28fbfc |
diff --git a/src/crypto/tls/boring.go b/src/crypto/tls/boring.go
|
|
|
42489d |
index 1827f76..4c5c352 100644
|
|
|
28fbfc |
--- a/src/crypto/tls/boring.go
|
|
|
28fbfc |
+++ b/src/crypto/tls/boring.go
|
|
|
28fbfc |
@@ -8,8 +8,15 @@ package tls
|
|
|
28fbfc |
|
|
|
28fbfc |
import (
|
|
|
28fbfc |
"crypto/internal/boring/fipstls"
|
|
|
28fbfc |
+ boring "crypto/internal/backend"
|
|
|
28fbfc |
)
|
|
|
28fbfc |
|
|
|
28fbfc |
+func init() {
|
|
|
28fbfc |
+ if boring.Enabled && !boring.ExecutingTest() {
|
|
|
28fbfc |
+ fipstls.Force()
|
|
|
28fbfc |
+ }
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
+
|
|
|
28fbfc |
// needFIPS returns fipstls.Required(); it avoids a new import in common.go.
|
|
|
28fbfc |
func needFIPS() bool {
|
|
|
28fbfc |
return fipstls.Required()
|
|
|
42489d |
@@ -17,14 +24,14 @@ func needFIPS() bool {
|
|
|
42489d |
|
|
|
42489d |
// fipsMinVersion replaces c.minVersion in FIPS-only mode.
|
|
|
42489d |
func fipsMinVersion(c *Config) uint16 {
|
|
|
42489d |
- // FIPS requires TLS 1.2.
|
|
|
42489d |
+ // FIPS requires TLS 1.2 or later.
|
|
|
42489d |
return VersionTLS12
|
|
|
42489d |
}
|
|
|
42489d |
|
|
|
42489d |
// fipsMaxVersion replaces c.maxVersion in FIPS-only mode.
|
|
|
42489d |
func fipsMaxVersion(c *Config) uint16 {
|
|
|
42489d |
- // FIPS requires TLS 1.2.
|
|
|
42489d |
- return VersionTLS12
|
|
|
42489d |
+ // FIPS requires TLS 1.2 or later.
|
|
|
42489d |
+ return VersionTLS13
|
|
|
42489d |
}
|
|
|
42489d |
|
|
|
42489d |
// default defaultFIPSCurvePreferences is the FIPS-allowed curves,
|
|
|
42489d |
diff --git a/src/crypto/tls/boring_test.go b/src/crypto/tls/boring_test.go
|
|
|
42489d |
index f743fc8..9fec2c8 100644
|
|
|
42489d |
--- a/src/crypto/tls/boring_test.go
|
|
|
42489d |
+++ b/src/crypto/tls/boring_test.go
|
|
|
42489d |
@@ -51,11 +51,11 @@ func TestBoringServerProtocolVersion(t *testing.T) {
|
|
|
42489d |
test("VersionTLS10", VersionTLS10, "client offered only unsupported versions")
|
|
|
42489d |
test("VersionTLS11", VersionTLS11, "client offered only unsupported versions")
|
|
|
42489d |
test("VersionTLS12", VersionTLS12, "")
|
|
|
42489d |
- test("VersionTLS13", VersionTLS13, "client offered only unsupported versions")
|
|
|
42489d |
+ test("VersionTLS13", VersionTLS13, "")
|
|
|
42489d |
}
|
|
|
42489d |
|
|
|
42489d |
func isBoringVersion(v uint16) bool {
|
|
|
42489d |
- return v == VersionTLS12
|
|
|
42489d |
+ return v == VersionTLS12 || v == VersionTLS13
|
|
|
42489d |
}
|
|
|
42489d |
|
|
|
42489d |
func isBoringCipherSuite(id uint16) bool {
|
|
|
42489d |
@@ -65,7 +65,9 @@ func isBoringCipherSuite(id uint16) bool {
|
|
|
42489d |
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
|
|
42489d |
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
|
|
42489d |
TLS_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
42489d |
- TLS_RSA_WITH_AES_256_GCM_SHA384:
|
|
|
42489d |
+ TLS_RSA_WITH_AES_256_GCM_SHA384,
|
|
|
42489d |
+ TLS_AES_128_GCM_SHA256,
|
|
|
42489d |
+ TLS_AES_256_GCM_SHA384:
|
|
|
42489d |
return true
|
|
|
42489d |
}
|
|
|
42489d |
return false
|
|
|
42489d |
@@ -311,7 +313,7 @@ func TestBoringCertAlgs(t *testing.T) {
|
|
|
42489d |
// Set up some roots, intermediate CAs, and leaf certs with various algorithms.
|
|
|
42489d |
// X_Y is X signed by Y.
|
|
|
42489d |
R1 := boringCert(t, "R1", boringRSAKey(t, 2048), nil, boringCertCA|boringCertFIPSOK)
|
|
|
42489d |
- R2 := boringCert(t, "R2", boringRSAKey(t, 4096), nil, boringCertCA)
|
|
|
42489d |
+ R2 := boringCert(t, "R2", boringRSAKey(t, 4096), nil, boringCertCA|boringCertFIPSOK)
|
|
|
42489d |
|
|
|
42489d |
M1_R1 := boringCert(t, "M1_R1", boringECDSAKey(t, elliptic.P256()), R1, boringCertCA|boringCertFIPSOK)
|
|
|
42489d |
M2_R1 := boringCert(t, "M2_R1", boringECDSAKey(t, elliptic.P224()), R1, boringCertCA)
|
|
|
42489d |
diff --git a/src/crypto/tls/cipher_suites.go b/src/crypto/tls/cipher_suites.go
|
|
|
42489d |
index 9a1fa31..f7c64db 100644
|
|
|
42489d |
--- a/src/crypto/tls/cipher_suites.go
|
|
|
42489d |
+++ b/src/crypto/tls/cipher_suites.go
|
|
|
42489d |
@@ -354,6 +354,11 @@ var defaultCipherSuitesTLS13NoAES = []uint16{
|
|
|
42489d |
TLS_AES_256_GCM_SHA384,
|
|
|
42489d |
}
|
|
|
42489d |
|
|
|
42489d |
+var defaultFIPSCipherSuitesTLS13 = []uint16{
|
|
|
42489d |
+ TLS_AES_128_GCM_SHA256,
|
|
|
42489d |
+ TLS_AES_256_GCM_SHA384,
|
|
|
42489d |
+}
|
|
|
42489d |
+
|
|
|
42489d |
var (
|
|
|
42489d |
hasGCMAsmAMD64 = cpu.X86.HasAES && cpu.X86.HasPCLMULQDQ
|
|
|
42489d |
hasGCMAsmARM64 = cpu.ARM64.HasAES && cpu.ARM64.HasPMULL
|
|
|
42489d |
diff --git a/src/crypto/tls/handshake_client.go b/src/crypto/tls/handshake_client.go
|
|
|
42489d |
index e61e3eb..7031ab8 100644
|
|
|
42489d |
--- a/src/crypto/tls/handshake_client.go
|
|
|
42489d |
+++ b/src/crypto/tls/handshake_client.go
|
|
|
42489d |
@@ -127,7 +127,9 @@ func (c *Conn) makeClientHello() (*clientHelloMsg, ecdheParameters, error) {
|
|
|
42489d |
|
|
|
42489d |
var params ecdheParameters
|
|
|
42489d |
if hello.supportedVersions[0] == VersionTLS13 {
|
|
|
42489d |
- if hasAESGCMHardwareSupport {
|
|
|
42489d |
+ if needFIPS() {
|
|
|
42489d |
+ hello.cipherSuites = append(hello.cipherSuites, defaultFIPSCipherSuitesTLS13...)
|
|
|
42489d |
+ } else if hasAESGCMHardwareSupport {
|
|
|
42489d |
hello.cipherSuites = append(hello.cipherSuites, defaultCipherSuitesTLS13...)
|
|
|
42489d |
} else {
|
|
|
42489d |
hello.cipherSuites = append(hello.cipherSuites, defaultCipherSuitesTLS13NoAES...)
|
|
|
28fbfc |
diff --git a/src/crypto/tls/handshake_client_test.go b/src/crypto/tls/handshake_client_test.go
|
|
|
28fbfc |
index 380de9f..02b4ac8 100644
|
|
|
28fbfc |
--- a/src/crypto/tls/handshake_client_test.go
|
|
|
28fbfc |
+++ b/src/crypto/tls/handshake_client_test.go
|
|
|
28fbfc |
@@ -2135,6 +2135,7 @@ func testBuffering(t *testing.T, version uint16) {
|
|
|
28fbfc |
}
|
|
|
28fbfc |
|
|
|
28fbfc |
func TestAlertFlushing(t *testing.T) {
|
|
|
28fbfc |
+ t.Skip("unsupported in FIPS mode, different error returned")
|
|
|
28fbfc |
c, s := localPipe(t)
|
|
|
28fbfc |
done := make(chan bool)
|
|
|
28fbfc |
|
|
|
42489d |
diff --git a/src/crypto/tls/handshake_client_tls13.go b/src/crypto/tls/handshake_client_tls13.go
|
|
|
42489d |
index c798986..7a60702 100644
|
|
|
42489d |
--- a/src/crypto/tls/handshake_client_tls13.go
|
|
|
42489d |
+++ b/src/crypto/tls/handshake_client_tls13.go
|
|
|
42489d |
@@ -41,10 +41,6 @@ type clientHandshakeStateTLS13 struct {
|
|
|
42489d |
func (hs *clientHandshakeStateTLS13) handshake() error {
|
|
|
42489d |
c := hs.c
|
|
|
42489d |
|
|
|
42489d |
- if needFIPS() {
|
|
|
42489d |
- return errors.New("tls: internal error: TLS 1.3 reached in FIPS mode")
|
|
|
42489d |
- }
|
|
|
42489d |
-
|
|
|
42489d |
// The server must not select TLS 1.3 in a renegotiation. See RFC 8446,
|
|
|
42489d |
// sections 4.1.2 and 4.1.3.
|
|
|
42489d |
if c.handshakes > 0 {
|
|
|
42489d |
diff --git a/src/crypto/tls/handshake_server_tls13.go b/src/crypto/tls/handshake_server_tls13.go
|
|
|
42489d |
index 03a477f..1ef6afc 100644
|
|
|
42489d |
--- a/src/crypto/tls/handshake_server_tls13.go
|
|
|
42489d |
+++ b/src/crypto/tls/handshake_server_tls13.go
|
|
|
42489d |
@@ -45,10 +45,6 @@ type serverHandshakeStateTLS13 struct {
|
|
|
42489d |
func (hs *serverHandshakeStateTLS13) handshake() error {
|
|
|
42489d |
c := hs.c
|
|
|
42489d |
|
|
|
42489d |
- if needFIPS() {
|
|
|
42489d |
- return errors.New("tls: internal error: TLS 1.3 reached in FIPS mode")
|
|
|
42489d |
- }
|
|
|
42489d |
-
|
|
|
42489d |
// For an overview of the TLS 1.3 handshake, see RFC 8446, Section 2.
|
|
|
42489d |
if err := hs.processClientHello(); err != nil {
|
|
|
42489d |
return err
|
|
|
42489d |
diff --git a/src/crypto/tls/key_schedule.go b/src/crypto/tls/key_schedule.go
|
|
|
42489d |
index 3140169..323d683 100644
|
|
|
42489d |
--- a/src/crypto/tls/key_schedule.go
|
|
|
42489d |
+++ b/src/crypto/tls/key_schedule.go
|
|
|
42489d |
@@ -7,6 +7,8 @@ package tls
|
|
|
42489d |
import (
|
|
|
42489d |
"crypto/elliptic"
|
|
|
42489d |
"crypto/hmac"
|
|
|
42489d |
+ "crypto/internal/boring"
|
|
|
42489d |
+ "crypto/internal/boring/bbig"
|
|
|
42489d |
"errors"
|
|
|
42489d |
"hash"
|
|
|
42489d |
"io"
|
|
|
42489d |
@@ -43,9 +45,20 @@ func (c *cipherSuiteTLS13) expandLabel(secret []byte, label string, context []by
|
|
|
42489d |
b.AddBytes(context)
|
|
|
42489d |
})
|
|
|
42489d |
out := make([]byte, length)
|
|
|
42489d |
- n, err := hkdf.Expand(c.hash.New, secret, hkdfLabel.BytesOrPanic()).Read(out)
|
|
|
42489d |
- if err != nil || n != length {
|
|
|
42489d |
- panic("tls: HKDF-Expand-Label invocation failed unexpectedly")
|
|
|
42489d |
+ if boring.Enabled {
|
|
|
42489d |
+ reader, err := boring.ExpandHKDF(c.hash.New, secret, hkdfLabel.BytesOrPanic())
|
|
|
42489d |
+ if err != nil {
|
|
|
42489d |
+ panic("tls: HKDF-Expand-Label invocation failed unexpectedly")
|
|
|
42489d |
+ }
|
|
|
42489d |
+ n, err := reader.Read(out)
|
|
|
42489d |
+ if err != nil || n != length {
|
|
|
42489d |
+ panic("tls: HKDF-Expand-Label invocation failed unexpectedly")
|
|
|
42489d |
+ }
|
|
|
42489d |
+ } else {
|
|
|
42489d |
+ n, err := hkdf.Expand(c.hash.New, secret, hkdfLabel.BytesOrPanic()).Read(out)
|
|
|
42489d |
+ if err != nil || n != length {
|
|
|
42489d |
+ panic("tls: HKDF-Expand-Label invocation failed unexpectedly")
|
|
|
42489d |
+ }
|
|
|
42489d |
}
|
|
|
42489d |
return out
|
|
|
42489d |
}
|
|
|
42489d |
@@ -63,7 +76,15 @@ func (c *cipherSuiteTLS13) extract(newSecret, currentSecret []byte) []byte {
|
|
|
42489d |
if newSecret == nil {
|
|
|
42489d |
newSecret = make([]byte, c.hash.Size())
|
|
|
42489d |
}
|
|
|
42489d |
- return hkdf.Extract(c.hash.New, newSecret, currentSecret)
|
|
|
42489d |
+ if boring.Enabled {
|
|
|
42489d |
+ ikm, err := boring.ExtractHKDF(c.hash.New, newSecret, currentSecret)
|
|
|
42489d |
+ if err != nil {
|
|
|
42489d |
+ panic("tls: HKDF-Extract invocation failed unexpectedly")
|
|
|
42489d |
+ }
|
|
|
42489d |
+ return ikm
|
|
|
42489d |
+ } else {
|
|
|
42489d |
+ return hkdf.Extract(c.hash.New, newSecret, currentSecret)
|
|
|
42489d |
+ }
|
|
|
42489d |
}
|
|
|
42489d |
|
|
|
42489d |
// nextTrafficSecret generates the next traffic secret, given the current one,
|
|
|
42489d |
@@ -129,9 +150,19 @@ func generateECDHEParameters(rand io.Reader, curveID CurveID) (ecdheParameters,
|
|
|
42489d |
|
|
|
42489d |
p := &nistParameters{curveID: curveID}
|
|
|
42489d |
var err error
|
|
|
42489d |
- p.privateKey, p.x, p.y, err = elliptic.GenerateKey(curve, rand)
|
|
|
42489d |
- if err != nil {
|
|
|
42489d |
- return nil, err
|
|
|
42489d |
+ if boring.Enabled {
|
|
|
42489d |
+ x, y, d, err := boring.GenerateKeyECDH(curve.Params().Name)
|
|
|
42489d |
+ if err != nil {
|
|
|
42489d |
+ return nil, err
|
|
|
42489d |
+ }
|
|
|
42489d |
+ p.x = bbig.Dec(x)
|
|
|
42489d |
+ p.y = bbig.Dec(y)
|
|
|
42489d |
+ p.privateKey = bbig.Dec(d).Bytes()
|
|
|
42489d |
+ } else {
|
|
|
42489d |
+ p.privateKey, p.x, p.y, err = elliptic.GenerateKey(curve, rand)
|
|
|
42489d |
+ if err != nil {
|
|
|
42489d |
+ return nil, err
|
|
|
42489d |
+ }
|
|
|
42489d |
}
|
|
|
42489d |
return p, nil
|
|
|
42489d |
}
|
|
|
42489d |
@@ -166,15 +197,28 @@ func (p *nistParameters) PublicKey() []byte {
|
|
|
42489d |
|
|
|
42489d |
func (p *nistParameters) SharedKey(peerPublicKey []byte) []byte {
|
|
|
42489d |
curve, _ := curveForCurveID(p.curveID)
|
|
|
42489d |
- // Unmarshal also checks whether the given point is on the curve.
|
|
|
42489d |
- x, y := elliptic.Unmarshal(curve, peerPublicKey)
|
|
|
42489d |
- if x == nil {
|
|
|
42489d |
- return nil
|
|
|
42489d |
- }
|
|
|
42489d |
+ if boring.Enabled {
|
|
|
42489d |
+ k := new(big.Int).SetBytes(p.privateKey)
|
|
|
42489d |
+ priv, err := boring.NewPrivateKeyECDH(curve.Params().Name, bbig.Enc(p.x), bbig.Enc(p.y), bbig.Enc(k))
|
|
|
42489d |
+ if err != nil {
|
|
|
42489d |
+ return nil
|
|
|
42489d |
+ }
|
|
|
42489d |
+ sharedKey, err := boring.SharedKeyECDH(priv, peerPublicKey)
|
|
|
42489d |
+ if err != nil {
|
|
|
42489d |
+ return nil
|
|
|
42489d |
+ }
|
|
|
42489d |
+ return sharedKey
|
|
|
42489d |
+ } else {
|
|
|
42489d |
+ // Unmarshal also checks whether the given point is on the curve.
|
|
|
42489d |
+ x, y := elliptic.Unmarshal(curve, peerPublicKey)
|
|
|
42489d |
+ if x == nil {
|
|
|
42489d |
+ return nil
|
|
|
42489d |
+ }
|
|
|
42489d |
|
|
|
42489d |
- xShared, _ := curve.ScalarMult(x, y, p.privateKey)
|
|
|
42489d |
- sharedKey := make([]byte, (curve.Params().BitSize+7)/8)
|
|
|
42489d |
- return xShared.FillBytes(sharedKey)
|
|
|
42489d |
+ xShared, _ := curve.ScalarMult(x, y, p.privateKey)
|
|
|
42489d |
+ sharedKey := make([]byte, (curve.Params().BitSize+7)/8)
|
|
|
42489d |
+ return xShared.FillBytes(sharedKey)
|
|
|
42489d |
+ }
|
|
|
42489d |
}
|
|
|
42489d |
|
|
|
42489d |
type x25519Parameters struct {
|
|
|
42489d |
diff --git a/src/crypto/x509/boring.go b/src/crypto/x509/boring.go
|
|
|
42489d |
index 4aae905..42706f9 100644
|
|
|
42489d |
--- a/src/crypto/x509/boring.go
|
|
|
42489d |
+++ b/src/crypto/x509/boring.go
|
|
|
42489d |
@@ -26,7 +26,7 @@ func boringAllowCert(c *Certificate) bool {
|
|
|
42489d |
default:
|
|
|
42489d |
return false
|
|
|
42489d |
case *rsa.PublicKey:
|
|
|
42489d |
- if size := k.N.BitLen(); size != 2048 && size != 3072 {
|
|
|
42489d |
+ if size := k.N.BitLen(); size != 2048 && size != 3072 && size != 4096 {
|
|
|
42489d |
return false
|
|
|
42489d |
}
|
|
|
42489d |
case *ecdsa.PublicKey:
|
|
|
42489d |
diff --git a/src/crypto/x509/boring_test.go b/src/crypto/x509/boring_test.go
|
|
|
42489d |
index 7010f44..70021f3 100644
|
|
|
42489d |
--- a/src/crypto/x509/boring_test.go
|
|
|
42489d |
+++ b/src/crypto/x509/boring_test.go
|
|
|
42489d |
@@ -54,7 +54,7 @@ type boringCertificate struct {
|
|
|
42489d |
|
|
|
42489d |
func TestBoringAllowCert(t *testing.T) {
|
|
|
42489d |
R1 := testBoringCert(t, "R1", boringRSAKey(t, 2048), nil, boringCertCA|boringCertFIPSOK)
|
|
|
42489d |
- R2 := testBoringCert(t, "R2", boringRSAKey(t, 4096), nil, boringCertCA)
|
|
|
42489d |
+ R2 := testBoringCert(t, "R2", boringRSAKey(t, 4096), nil, boringCertCA|boringCertFIPSOK)
|
|
|
42489d |
|
|
|
42489d |
M1_R1 := testBoringCert(t, "M1_R1", boringECDSAKey(t, elliptic.P256()), R1, boringCertCA|boringCertFIPSOK)
|
|
|
42489d |
M2_R1 := testBoringCert(t, "M2_R1", boringECDSAKey(t, elliptic.P224()), R1, boringCertCA)
|
|
|
28fbfc |
diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go
|
|
|
42489d |
index 141fdb9..d8e81d9 100644
|
|
|
28fbfc |
--- a/src/go/build/deps_test.go
|
|
|
28fbfc |
+++ b/src/go/build/deps_test.go
|
|
|
28fbfc |
@@ -414,19 +414,23 @@ var depsRules = `
|
|
|
28fbfc |
< crypto/internal/edwards25519
|
|
|
28fbfc |
< crypto/cipher;
|
|
|
28fbfc |
|
|
|
28fbfc |
- crypto/cipher,
|
|
|
28fbfc |
+ fmt, crypto/cipher,
|
|
|
28fbfc |
crypto/internal/boring/bcache
|
|
|
28fbfc |
< crypto/internal/boring
|
|
|
28fbfc |
+ < github.com/golang-fips/openssl-fips/openssl
|
|
|
28fbfc |
+ < crypto/internal/backend
|
|
|
28fbfc |
< crypto/boring
|
|
|
28fbfc |
< crypto/aes, crypto/des, crypto/hmac, crypto/md5, crypto/rc4,
|
|
|
28fbfc |
crypto/sha1, crypto/sha256, crypto/sha512
|
|
|
28fbfc |
< CRYPTO;
|
|
|
28fbfc |
|
|
|
28fbfc |
- CGO, fmt, net !< CRYPTO;
|
|
|
28fbfc |
+ CGO, net !< CRYPTO;
|
|
|
28fbfc |
|
|
|
28fbfc |
# CRYPTO-MATH is core bignum-based crypto - no cgo, net; fmt now ok.
|
|
|
28fbfc |
CRYPTO, FMT, math/big, embed
|
|
|
28fbfc |
+ < github.com/golang-fips/openssl-fips/openssl/bbig
|
|
|
28fbfc |
< crypto/internal/boring/bbig
|
|
|
28fbfc |
+ < crypto/internal/backend/bbig
|
|
|
28fbfc |
< crypto/internal/randutil
|
|
|
28fbfc |
< crypto/rand
|
|
|
28fbfc |
< crypto/ed25519
|
|
|
42489d |
@@ -601,6 +605,7 @@ func listStdPkgs(goroot string) ([]string, error) {
|
|
|
42489d |
}
|
|
|
42489d |
|
|
|
42489d |
func TestDependencies(t *testing.T) {
|
|
|
42489d |
+ t.Skip("openssl-fips based toolchain has different dependencies than upstream")
|
|
|
42489d |
if !testenv.HasSrc() {
|
|
|
42489d |
// Tests run in a limited file system and we do not
|
|
|
42489d |
// provide access to every source file.
|
|
|
42489d |
@@ -644,7 +649,7 @@ var buildIgnore = []byte("\n//go:build ignore")
|
|
|
28fbfc |
|
|
|
28fbfc |
func findImports(pkg string) ([]string, error) {
|
|
|
28fbfc |
vpkg := pkg
|
|
|
28fbfc |
- if strings.HasPrefix(pkg, "golang.org") {
|
|
|
28fbfc |
+ if strings.HasPrefix(pkg, "golang.org") || strings.HasPrefix(pkg, "github.com") {
|
|
|
28fbfc |
vpkg = "vendor/" + pkg
|
|
|
28fbfc |
}
|
|
|
28fbfc |
dir := filepath.Join(Default.GOROOT, "src", vpkg)
|
|
|
42489d |
@@ -654,7 +659,7 @@ func findImports(pkg string) ([]string, error) {
|
|
|
28fbfc |
}
|
|
|
28fbfc |
var imports []string
|
|
|
28fbfc |
var haveImport = map[string]bool{}
|
|
|
28fbfc |
- if pkg == "crypto/internal/boring" {
|
|
|
28fbfc |
+ if pkg == "crypto/internal/boring" || pkg == "github.com/golang-fips/openssl-fips/openssl" {
|
|
|
28fbfc |
haveImport["C"] = true // kludge: prevent C from appearing in crypto/internal/boring imports
|
|
|
28fbfc |
}
|
|
|
28fbfc |
fset := token.NewFileSet()
|
|
|
28fbfc |
diff --git a/src/runtime/runtime_boring.go b/src/runtime/runtime_boring.go
|
|
|
28fbfc |
index 5a98b20..dc25cdc 100644
|
|
|
28fbfc |
--- a/src/runtime/runtime_boring.go
|
|
|
28fbfc |
+++ b/src/runtime/runtime_boring.go
|
|
|
28fbfc |
@@ -17,3 +17,8 @@ func boring_runtime_arg0() string {
|
|
|
28fbfc |
|
|
|
28fbfc |
//go:linkname fipstls_runtime_arg0 crypto/internal/boring/fipstls.runtime_arg0
|
|
|
28fbfc |
func fipstls_runtime_arg0() string { return boring_runtime_arg0() }
|
|
|
28fbfc |
+
|
|
|
28fbfc |
+//go:linkname crypto_backend_runtime_arg0 crypto/internal/backend.runtime_arg0
|
|
|
28fbfc |
+func crypto_backend_runtime_arg0() string {
|
|
|
28fbfc |
+ return boring_runtime_arg0()
|
|
|
28fbfc |
+}
|
|
|
28fbfc |
\ No newline at end of file
|