Blame SOURCES/010-fips.patch

4bd38e
diff --git a/vendor/golang.org/x/crypto/internal/boring/boring.go b/vendor/golang.org/x/crypto/internal/boring/boring.go
4bd38e
new file mode 100644
4bd38e
index 0000000..a9c550e
4bd38e
--- /dev/null
4bd38e
+++ b/vendor/golang.org/x/crypto/internal/boring/boring.go
4bd38e
@@ -0,0 +1,74 @@
4bd38e
+// Copyright 2017 The Go Authors. All rights reserved.
4bd38e
+// Copyright 2021 Red Hat.
4bd38e
+// Use of this source code is governed by a BSD-style
4bd38e
+// license that can be found in the LICENSE file.
4bd38e
+
4bd38e
+// +build linux
4bd38e
+// +build !android
4bd38e
+// +build !no_openssl
4bd38e
+// +build !cmd_go_bootstrap
4bd38e
+// +build !msan
4bd38e
+
4bd38e
+package boring
4bd38e
+
4bd38e
+// #include "openssl_pbkdf2.h"
4bd38e
+// #cgo LDFLAGS: -ldl
4bd38e
+import "C"
4bd38e
+import (
4bd38e
+	"bytes"
4bd38e
+	"crypto/sha1"
4bd38e
+	"crypto/sha256"
4bd38e
+	"hash"
4bd38e
+	"unsafe"
4bd38e
+)
4bd38e
+
4bd38e
+var (
4bd38e
+	emptySha1   = sha1.Sum([]byte{})
4bd38e
+	emptySha256 = sha256.Sum256([]byte{})
4bd38e
+)
4bd38e
+
4bd38e
+func hashToMD(h hash.Hash) *C.GO_EVP_MD {
4bd38e
+	emptyHash := h.Sum([]byte{})
4bd38e
+
4bd38e
+	switch {
4bd38e
+	case bytes.Equal(emptyHash, emptySha1[:]):
4bd38e
+		return C._goboringcrypto_EVP_sha1()
4bd38e
+	case bytes.Equal(emptyHash, emptySha256[:]):
4bd38e
+		return C._goboringcrypto_EVP_sha256()
4bd38e
+	}
4bd38e
+	return nil
4bd38e
+}
4bd38e
+
4bd38e
+// charptr returns the address of the underlying array in b,
4bd38e
+// being careful not to panic when b has zero length.
4bd38e
+func charptr(b []byte) *C.char {
4bd38e
+	if len(b) == 0 {
4bd38e
+		return nil
4bd38e
+	}
4bd38e
+	return (*C.char)(unsafe.Pointer(&b[0]))
4bd38e
+}
4bd38e
+
4bd38e
+// ucharptr returns the address of the underlying array in b,
4bd38e
+// being careful not to panic when b has zero length.
4bd38e
+func ucharptr(b []byte) *C.uchar {
4bd38e
+	if len(b) == 0 {
4bd38e
+		return nil
4bd38e
+	}
4bd38e
+	return (*C.uchar)(unsafe.Pointer(&b[0]))
4bd38e
+}
4bd38e
+
4bd38e
+func Pbkdf2Key(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte {
4bd38e
+	// println("[debug] using pbkdf2 from OpenSSL")
4bd38e
+	ch := h()
4bd38e
+	md := hashToMD(ch)
4bd38e
+	if md == nil {
4bd38e
+		return nil
4bd38e
+	}
4bd38e
+
4bd38e
+	out := make([]byte, keyLen)
4bd38e
+	ok := C._goboringcrypto_PKCS5_PBKDF2_HMAC(charptr(password), C.int(len(password)), ucharptr(salt), C.int(len(salt)), C.int(iter), md, C.int(keyLen), ucharptr(out))
4bd38e
+	if ok != 1 {
4bd38e
+		panic("boringcrypto: PKCS5_PBKDF2_HMAC failed")
4bd38e
+	}
4bd38e
+	return out
4bd38e
+}
4bd38e
diff --git a/vendor/golang.org/x/crypto/internal/boring/notboring.go b/vendor/golang.org/x/crypto/internal/boring/notboring.go
4bd38e
new file mode 100644
4bd38e
index 0000000..e244fb5
4bd38e
--- /dev/null
4bd38e
+++ b/vendor/golang.org/x/crypto/internal/boring/notboring.go
4bd38e
@@ -0,0 +1,16 @@
4bd38e
+// Copyright 2017 The Go Authors. All rights reserved.
4bd38e
+// Copyright 2021 Red Hat.
4bd38e
+// Use of this source code is governed by a BSD-style
4bd38e
+// license that can be found in the LICENSE file.
4bd38e
+
4bd38e
+// +build !linux !cgo android cmd_go_bootstrap msan no_openssl
4bd38e
+
4bd38e
+package boring
4bd38e
+
4bd38e
+import (
4bd38e
+	"hash"
4bd38e
+)
4bd38e
+
4bd38e
+func Pbkdf2Key(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte {
4bd38e
+	panic("boringcrypto: not available")
4bd38e
+}
4bd38e
diff --git a/vendor/golang.org/x/crypto/internal/boring/openssl_pbkdf2.h b/vendor/golang.org/x/crypto/internal/boring/openssl_pbkdf2.h
4bd38e
new file mode 100644
4bd38e
index 0000000..6dfdf10
4bd38e
--- /dev/null
4bd38e
+++ b/vendor/golang.org/x/crypto/internal/boring/openssl_pbkdf2.h
4bd38e
@@ -0,0 +1,5 @@
4bd38e
+#include "/usr/lib/golang/src/crypto/internal/boring/goboringcrypto.h"
4bd38e
+
4bd38e
+DEFINEFUNC(int, PKCS5_PBKDF2_HMAC,
4bd38e
+    (const char *pass, int passlen, const unsigned char *salt, int saltlen, int iter, EVP_MD *digest, int keylen, unsigned char *out),
4bd38e
+    (pass, passlen, salt, saltlen, iter, digest, keylen, out))
4bd38e
diff --git a/vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go b/vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go
4bd38e
index 593f653..799a611 100644
4bd38e
--- a/vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go
4bd38e
+++ b/vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go
4bd38e
@@ -19,8 +19,11 @@ pbkdf2.Key.
4bd38e
 package pbkdf2 // import "golang.org/x/crypto/pbkdf2"
4bd38e
 
4bd38e
 import (
4bd38e
+	"crypto/boring"
4bd38e
 	"crypto/hmac"
4bd38e
 	"hash"
4bd38e
+
4bd38e
+	xboring "golang.org/x/crypto/internal/boring"
4bd38e
 )
4bd38e
 
4bd38e
 // Key derives a key from the password, salt and iteration count, returning a
4bd38e
@@ -40,6 +43,10 @@ import (
4bd38e
 // Using a higher iteration count will increase the cost of an exhaustive
4bd38e
 // search but will also make derivation proportionally slower.
4bd38e
 func Key(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte {
4bd38e
+	if boring.Enabled() {
4bd38e
+		return xboring.Pbkdf2Key(password, salt, iter, keyLen, h)
4bd38e
+	}
4bd38e
+
4bd38e
 	prf := hmac.New(h, password)
4bd38e
 	hashLen := prf.Size()
4bd38e
 	numBlocks := (keyLen + hashLen - 1) / hashLen