Blame SOURCES/010-fips.patch

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