Blame SOURCES/rhbz1952381.patch

e6cd3c
diff --git a/src/crypto/ecdsa/ecdsa_test.go b/src/crypto/ecdsa/ecdsa_test.go
e6cd3c
index d60fdb8..b90782a 100644
e6cd3c
--- a/src/crypto/ecdsa/ecdsa_test.go
e6cd3c
+++ b/src/crypto/ecdsa/ecdsa_test.go
e6cd3c
@@ -323,6 +323,10 @@ func TestVectors(t *testing.T) {
e6cd3c
 			h.Write(msg)
e6cd3c
 			hashed := h.Sum(hashed[:0])
e6cd3c
 			if boring.Enabled() {
e6cd3c
+				// SHA-1 signatures not supported in OpenSSL 3.0
e6cd3c
+			        if ch == crypto.SHA1 {
e6cd3c
+					expected = false
e6cd3c
+				}
e6cd3c
 				if HashVerify(pub, msg, r, s, ch) != expected {
e6cd3c
 					t.Fatalf("incorrect result on line %d", lineNo)
e6cd3c
 				}
034e53
diff --git a/src/crypto/internal/boring/aes.go b/src/crypto/internal/boring/aes.go
8d5b6a
index 457decf..961795a 100644
034e53
--- a/src/crypto/internal/boring/aes.go
034e53
+++ b/src/crypto/internal/boring/aes.go
034e53
@@ -130,7 +130,11 @@ func (c *aesCipher) Decrypt(dst, src []byte) {
034e53
 			panic("cipher: unable to initialize EVP cipher ctx")
034e53
 		}
034e53
 	}
034e53
-
034e53
+	// Workaround - padding detection is broken but we don't need it
034e53
+	// since we check for full blocks
034e53
+	if C._goboringcrypto_EVP_CIPHER_CTX_set_padding(c.dec_ctx, 0) != 1 {
034e53
+		panic("crypto/cipher: could not disable cipher padding")
034e53
+	}
034e53
 	outlen := C.int(0)
034e53
 	C._goboringcrypto_EVP_CipherUpdate(c.dec_ctx, (*C.uchar)(unsafe.Pointer(&dst[0])), &outlen, (*C.uchar)(unsafe.Pointer(&src[0])), C.int(aesBlockSize))
034e53
 	runtime.KeepAlive(c)
8d5b6a
@@ -157,6 +161,11 @@ func (x *aesCBC) CryptBlocks(dst, src []byte) {
034e53
 	}
034e53
 	if len(src) > 0 {
034e53
 		outlen := C.int(0)
034e53
+		// Workaround - padding detection is broken but we don't need it
034e53
+		// since we check for full blocks
034e53
+		if C._goboringcrypto_EVP_CIPHER_CTX_set_padding(x.ctx, 0) != 1 {
034e53
+			panic("crypto/cipher: could not disable cipher padding")
034e53
+		}
034e53
 		if C._goboringcrypto_EVP_CipherUpdate(
034e53
 			x.ctx,
034e53
 			base(dst), &outlen,
034e53
diff --git a/src/crypto/internal/boring/boring.go b/src/crypto/internal/boring/boring.go
034e53
index e7ae80c..45c856b 100644
034e53
--- a/src/crypto/internal/boring/boring.go
034e53
+++ b/src/crypto/internal/boring/boring.go
034e53
@@ -20,7 +20,8 @@ import (
034e53
 	"math/big"
034e53
 	"os"
034e53
 	"runtime"
034e53
-	"strings"
034e53
+	"unsafe"
034e53
+	"fmt"
034e53
 )
034e53
 
034e53
 const (
034e53
@@ -68,8 +69,22 @@ func enableBoringFIPSMode() {
034e53
 }
034e53
 
034e53
 func fipsModeEnabled() bool {
034e53
-	return os.Getenv("GOLANG_FIPS") == "1" ||
034e53
-		C._goboringcrypto_FIPS_mode() == fipsOn
034e53
+	// Due to the way providers work in openssl 3, the FIPS methods are not
034e53
+	// necessarily going to be available for us to load based on the GOLANG_FIPS
034e53
+	// environment variable alone. For now, we must rely on the config to tell
034e53
+	// us if the provider is configured and active.
034e53
+
034e53
+	fipsConfigured := C._goboringcrypto_FIPS_mode() == fipsOn
034e53
+	openSSLVersion := C._goboringcrypto_internal_OPENSSL_VERSION_NUMBER()
034e53
+	if openSSLVersion >= C.ulong(0x30000000) {
034e53
+		if !fipsConfigured && os.Getenv("GOLANG_FIPS") == "1" {
034e53
+			panic("GOLANG_FIPS=1 specified but OpenSSL FIPS provider is not configured")
034e53
+		}
034e53
+		return fipsConfigured
034e53
+
034e53
+	} else {
034e53
+		return os.Getenv("GOLANG_FIPS") == "1" || fipsConfigured
034e53
+	}
034e53
 }
034e53
 
034e53
 var randstub bool
034e53
@@ -126,23 +141,31 @@ func PanicIfStrictFIPS(msg string) {
034e53
 }
034e53
 
034e53
 func NewOpenSSLError(msg string) error {
034e53
-	var b strings.Builder
034e53
 	var e C.ulong
034e53
 
034e53
-	b.WriteString(msg)
034e53
-	b.WriteString("\nopenssl error(s):\n")
034e53
+	message := fmt.Sprintf("\n%v\nopenssl error(s):", msg)
034e53
 
034e53
 	for {
034e53
-		e = C._goboringcrypto_internal_ERR_get_error()
034e53
+		var file *C.char
034e53
+		var line C.int
034e53
+		var fnc  *C.char
034e53
+		var data  *C.char
034e53
+		var flags C.int
034e53
+		e = C._goboringcrypto_internal_ERR_get_error_all(&file, &line, &fnc, &data, &flags)
034e53
 		if e == 0 {
034e53
 			break
034e53
 		}
034e53
-		var buf [256]byte
034e53
-		C._goboringcrypto_internal_ERR_error_string_n(e, base(buf[:]), 256)
034e53
-		b.Write(buf[:])
034e53
-		b.WriteByte('\n')
034e53
+		var buf [256]C.char
034e53
+                C._goboringcrypto_internal_ERR_error_string_n(e, (*C.uchar)(unsafe.Pointer (&buf[0])), 256)
034e53
+		message = fmt.Sprintf("%v\nfile: %v\nline: %v\nfunction: %v\nflags: %v\nerror string: %s\n",
034e53
+			message,
034e53
+			C.GoString(file),
034e53
+			line,
034e53
+			C.GoString(fnc),
034e53
+			flags,
034e53
+		        C.GoString(&(buf[0])))
034e53
 	}
034e53
-	return errors.New(b.String())
034e53
+	return errors.New(message)
034e53
 }
034e53
 
034e53
 type fail string
034e53
diff --git a/src/crypto/internal/boring/goopenssl.h b/src/crypto/internal/boring/goopenssl.h
e6cd3c
index 355638b..2737441 100644
034e53
--- a/src/crypto/internal/boring/goopenssl.h
034e53
+++ b/src/crypto/internal/boring/goopenssl.h
034e53
@@ -14,6 +14,15 @@
034e53
 
034e53
 #include <openssl/ossl_typ.h>
034e53
 
034e53
+#if OPENSSL_VERSION_NUMBER < 0x30000000
034e53
+#define OPENSSL_DLSYM_CALL(handle, func) dlsym(handle, func)
034e53
+#else
034e53
+#define __USE_GNU
034e53
+#define OPENSSL_DLSYM_CALL(handle, func) dlvsym(handle, func, "OPENSSL_3.0.0")
034e53
+#endif
034e53
+
034e53
+#include <dlfcn.h>
034e53
+
034e53
 #define unlikely(x) __builtin_expect(!!(x), 0)
034e53
 #define DEFINEFUNC(ret, func, args, argscall)        \
034e53
 	typedef ret(*_goboringcrypto_PTR_##func) args;   \
034e53
@@ -22,7 +31,7 @@
034e53
 	{                                                \
034e53
 		if (unlikely(!_g_##func))                    \
034e53
 		{                                            \
034e53
-			_g_##func = dlsym(handle, #func);        \
034e53
+			_g_##func = OPENSSL_DLSYM_CALL(handle, #func); \
034e53
 		}                                            \
034e53
 		return _g_##func argscall;                   \
034e53
 	}
034e53
@@ -34,7 +43,7 @@
034e53
 	{                                                \
034e53
 		if (unlikely(!_g_internal_##func))                    \
034e53
 		{                                            \
034e53
-			_g_internal_##func = dlsym(handle, #func);        \
034e53
+			_g_internal_##func = OPENSSL_DLSYM_CALL(handle, #func); \
034e53
 		}                                            \
034e53
 		return _g_internal_##func argscall;                   \
034e53
 	}
034e53
@@ -45,7 +54,6 @@
034e53
 		return func argscall;                     \
034e53
 	}
034e53
 
034e53
-#include <dlfcn.h>
034e53
 
034e53
 static void* handle;
034e53
 static void*
034e53
@@ -57,8 +65,10 @@ _goboringcrypto_DLOPEN_OPENSSL(void)
034e53
 	}
034e53
 #if OPENSSL_VERSION_NUMBER < 0x10100000L
034e53
 	handle = dlopen("libcrypto.so.10", RTLD_NOW | RTLD_GLOBAL);
034e53
-#else
034e53
+#elif OPENSSL_VERSION_NUMBER < 0x30000000L
034e53
 	handle = dlopen("libcrypto.so.1.1", RTLD_NOW | RTLD_GLOBAL);
034e53
+#else
034e53
+	handle = dlopen("libcrypto.so.3", RTLD_NOW | RTLD_GLOBAL);
034e53
 #endif
034e53
 	return handle;
034e53
 }
034e53
@@ -68,6 +78,10 @@ _goboringcrypto_DLOPEN_OPENSSL(void)
034e53
 
034e53
 DEFINEFUNCINTERNAL(int, OPENSSL_init, (void), ())
034e53
 
034e53
+static unsigned long _goboringcrypto_internal_OPENSSL_VERSION_NUMBER(void) {
034e53
+	return OPENSSL_VERSION_NUMBER;
034e53
+}
034e53
+
034e53
 static void
034e53
 _goboringcrypto_OPENSSL_setup(void) {
034e53
 	_goboringcrypto_internal_OPENSSL_init();
034e53
@@ -76,6 +90,9 @@ _goboringcrypto_OPENSSL_setup(void) {
034e53
 #include <openssl/err.h>
034e53
 DEFINEFUNCINTERNAL(void, ERR_print_errors_fp, (FILE* fp), (fp))
034e53
 DEFINEFUNCINTERNAL(unsigned long, ERR_get_error, (void), ())
034e53
+DEFINEFUNCINTERNAL(unsigned long, ERR_get_error_all,
034e53
+		(const char **file, int *line, const char **func, const char **data, int *flags),
034e53
+		(file, line, func, data, flags))
034e53
 DEFINEFUNCINTERNAL(void, ERR_error_string_n, (unsigned long e, unsigned char *buf, size_t len), (e, buf, len))
034e53
 
034e53
 #include <openssl/crypto.h>
034e53
@@ -112,8 +129,15 @@ _goboringcrypto_CRYPTO_set_locking_callback(void (*locking_function)(int mode, i
034e53
 
034e53
 int _goboringcrypto_OPENSSL_thread_setup(void);
034e53
 
034e53
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
034e53
 DEFINEFUNC(int, FIPS_mode, (void), ())
034e53
 DEFINEFUNC(int, FIPS_mode_set, (int r), (r))
034e53
+#else
034e53
+DEFINEFUNC(int, EVP_default_properties_is_fips_enabled, (OSSL_LIB_CTX *libctx), (libctx))
034e53
+static inline int _goboringcrypto_FIPS_mode(void) {
034e53
+	return _goboringcrypto_EVP_default_properties_is_fips_enabled(NULL);
034e53
+}
034e53
+#endif
034e53
 
034e53
 #include <openssl/rand.h>
034e53
 
e6cd3c
@@ -711,12 +735,9 @@ _goboringcrypto_EVP_PKEY_CTX_set_rsa_padding(GO_EVP_PKEY_CTX* ctx, int pad) {
e6cd3c
 #endif
e6cd3c
 }
e6cd3c
 
e6cd3c
-static inline int
e6cd3c
-_goboringcrypto_EVP_PKEY_CTX_set0_rsa_oaep_label(GO_EVP_PKEY_CTX *ctx, uint8_t *l, int llen)
e6cd3c
-{
e6cd3c
-
e6cd3c
-	return _goboringcrypto_EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_RSA_OAEP_LABEL, llen, (void *)l);
e6cd3c
-}
e6cd3c
+DEFINEFUNC(int, EVP_PKEY_CTX_set0_rsa_oaep_label,
e6cd3c
+		(GO_EVP_PKEY_CTX *ctx, uint8_t *l, int llen),
e6cd3c
+		(ctx, l, llen))
e6cd3c
 
e6cd3c
 static inline int
e6cd3c
 _goboringcrypto_EVP_PKEY_CTX_set_rsa_oaep_md(GO_EVP_PKEY_CTX *ctx, const GO_EVP_MD *md)
e6cd3c
@@ -736,6 +757,7 @@ static inline int
034e53
 _goboringcrypto_EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) {
034e53
 	return _goboringcrypto_EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_MD, 0, (void *)md);
034e53
 }
034e53
+
034e53
 static inline int
034e53
 _goboringcrypto_EVP_PKEY_CTX_set_rsa_mgf1_md(GO_EVP_PKEY_CTX * ctx, const GO_EVP_MD *md) {
034e53
 	return _goboringcrypto_EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA,
034e53
diff --git a/src/crypto/internal/boring/openssl_port_rsa.c b/src/crypto/internal/boring/openssl_port_rsa.c
e6cd3c
index 92fbb36..781975c 100644
034e53
--- a/src/crypto/internal/boring/openssl_port_rsa.c
034e53
+++ b/src/crypto/internal/boring/openssl_port_rsa.c
e6cd3c
@@ -91,31 +91,40 @@ int _goboringcrypto_RSA_sign_pss_mgf1(GO_RSA *rsa, unsigned int *out_len, uint8_
034e53
 
034e53
 	if (_goboringcrypto_EVP_PKEY_set1_RSA(pkey, rsa) <= 0)
e6cd3c
 		goto err;
e6cd3c
-
e6cd3c
+	
034e53
 	ctx = _goboringcrypto_EVP_PKEY_CTX_new(pkey, NULL /* no engine */);
034e53
 	if (!ctx)
e6cd3c
 		goto err;
034e53
 
034e53
-	if (_goboringcrypto_EVP_PKEY_sign_init(ctx) <= 0)
034e53
-		goto err;
034e53
-	if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING) <= 0)
034e53
+	if (_goboringcrypto_EVP_PKEY_sign_init(ctx) <= 0) {
034e53
 		goto err;
034e53
-	if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, salt_len) <= 0)
034e53
+	}
034e53
+	// This is moved earlier because openssl 3.0 alpha defaults
034e53
+	// to sha1 in EVP_PKEY_CTRL_RSA_PADDING if unset and produces an error
034e53
+	if (_goboringcrypto_EVP_PKEY_CTX_set_signature_md(ctx, md) <= 0) {
034e53
 		goto err;
034e53
-	if (_goboringcrypto_EVP_PKEY_CTX_set_signature_md(ctx, md) <= 0)
034e53
+	}
034e53
+	if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING) <= 0) {
034e53
 		goto err;
034e53
-	if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, mgf1_md) <= 0)
034e53
+	}
034e53
+	if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, salt_len) <= 0) {
034e53
 		goto err;
e6cd3c
-
034e53
+	}
034e53
+	// doesnt take null anymore
034e53
+	if (mgf1_md)
034e53
+		if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, mgf1_md) <= 0) {
034e53
+			goto err;
034e53
+		}
034e53
 	/* Determine buffer length */
034e53
-	if (_goboringcrypto_EVP_PKEY_sign(ctx, NULL, &siglen, in, in_len) <= 0)
034e53
+	if (_goboringcrypto_EVP_PKEY_sign(ctx, NULL, &siglen, in, in_len) <= 0) {
034e53
 		goto err;
034e53
-
034e53
-	if (max_out < siglen)
034e53
+	}
034e53
+	if (max_out < siglen) {
034e53
 		goto err;
034e53
-
034e53
-	if (_goboringcrypto_EVP_PKEY_sign(ctx, out, &siglen, in, in_len) <= 0)
034e53
+	}
034e53
+	if (_goboringcrypto_EVP_PKEY_sign(ctx, out, &siglen, in, in_len) <= 0) {
034e53
 		goto err;
034e53
+	}
034e53
 
034e53
 	*out_len = siglen;
034e53
 	ret = 1;
e6cd3c
@@ -142,23 +151,31 @@ int _goboringcrypto_RSA_verify_pss_mgf1(RSA *rsa, const uint8_t *msg, unsigned i
034e53
 
034e53
 	if (_goboringcrypto_EVP_PKEY_set1_RSA(pkey, rsa) <= 0)
e6cd3c
 		goto err;
e6cd3c
-
e6cd3c
+	
034e53
 	ctx = _goboringcrypto_EVP_PKEY_CTX_new(pkey, NULL /* no engine */);
034e53
 	if (!ctx)
e6cd3c
 		goto err;
034e53
 
034e53
-	if (_goboringcrypto_EVP_PKEY_verify_init(ctx) <= 0)
034e53
+	if (_goboringcrypto_EVP_PKEY_verify_init(ctx) <= 0) {
034e53
 		goto err;
e6cd3c
-	if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING) <= 0)
e6cd3c
-		goto err;
034e53
-	if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, salt_len) <= 0)
034e53
+	}
034e53
+	if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING) <= 0) {
034e53
 		goto err;
034e53
-	if (_goboringcrypto_EVP_PKEY_CTX_set_signature_md(ctx, md) <= 0)
034e53
+	}
034e53
+	if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, salt_len) <= 0) {
034e53
 		goto err;
034e53
-	if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, mgf1_md) <= 0)
034e53
+	}
034e53
+	if (_goboringcrypto_EVP_PKEY_CTX_set_signature_md(ctx, md) <= 0) {
034e53
 		goto err;
034e53
-	if (_goboringcrypto_EVP_PKEY_verify(ctx, sig, sig_len, msg, msg_len) <= 0)
034e53
+	}
034e53
+	// doesnt take null anymore
034e53
+	if (mgf1_md)
034e53
+		if (_goboringcrypto_EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, mgf1_md) <= 0) {
034e53
+			goto err;
034e53
+		}
034e53
+	if (_goboringcrypto_EVP_PKEY_verify(ctx, sig, sig_len, msg, msg_len) <= 0) {
034e53
 		goto err;
034e53
+	}
034e53
 
034e53
 	ret = 1;
034e53
 
034e53
diff --git a/src/crypto/internal/boring/rand.go b/src/crypto/internal/boring/rand.go
034e53
index ff5c439..6047d65 100644
034e53
--- a/src/crypto/internal/boring/rand.go
034e53
+++ b/src/crypto/internal/boring/rand.go
034e53
@@ -20,7 +20,7 @@ func (randReader) Read(b []byte) (int, error) {
034e53
 	// Note: RAND_bytes should never fail; the return value exists only for historical reasons.
034e53
 	// We check it even so.
034e53
 	if len(b) > 0 && C._goboringcrypto_RAND_bytes((*C.uint8_t)(unsafe.Pointer(&b[0])), C.size_t(len(b))) == 0 {
034e53
-		return 0, fail("RAND_bytes")
034e53
+		return 0, NewOpenSSLError("RAND_bytes")
034e53
 	}
034e53
 	return len(b), nil
034e53
 }
034e53
diff --git a/src/crypto/internal/boring/rsa.go b/src/crypto/internal/boring/rsa.go
e6cd3c
index b3a907f..b74e7a9 100644
034e53
--- a/src/crypto/internal/boring/rsa.go
034e53
+++ b/src/crypto/internal/boring/rsa.go
e6cd3c
@@ -120,7 +120,9 @@ func (k *PrivateKeyRSA) withKey(f func(*C.GO_RSA) C.int) C.int {
e6cd3c
 
e6cd3c
 func setupRSA(withKey func(func(*C.GO_RSA) C.int) C.int,
e6cd3c
 	padding C.int, h hash.Hash, label []byte, saltLen int, ch crypto.Hash,
e6cd3c
-	init func(*C.GO_EVP_PKEY_CTX) C.int) (pkey *C.GO_EVP_PKEY, ctx *C.GO_EVP_PKEY_CTX, err error) {
e6cd3c
+	init func(*C.GO_EVP_PKEY_CTX) C.int) (_pkey *C.GO_EVP_PKEY, _ctx *C.GO_EVP_PKEY_CTX, err error) {
e6cd3c
+	var pkey *C.GO_EVP_PKEY
e6cd3c
+	var ctx *C.GO_EVP_PKEY_CTX
e6cd3c
 	defer func() {
e6cd3c
 		if err != nil {
e6cd3c
 			if pkey != nil {
e6cd3c
@@ -141,7 +143,7 @@ func setupRSA(withKey func(func(*C.GO_RSA) C.int) C.int,
034e53
 	if withKey(func(key *C.GO_RSA) C.int {
034e53
 		return C._goboringcrypto_EVP_PKEY_set1_RSA(pkey, key)
034e53
 	}) == 0 {
034e53
-		return nil, nil, fail("EVP_PKEY_set1_RSA")
034e53
+		return nil, nil, NewOpenSSLError("EVP_PKEY_set1_RSA")
034e53
 	}
034e53
 	ctx = C._goboringcrypto_EVP_PKEY_CTX_new(pkey, nil)
034e53
 	if ctx == nil {
e6cd3c
@@ -162,23 +164,12 @@ func setupRSA(withKey func(func(*C.GO_RSA) C.int) C.int,
e6cd3c
 			return nil, nil, NewOpenSSLError("EVP_PKEY_set_rsa_oaep_md failed")
e6cd3c
 		}
034e53
 		// ctx takes ownership of label, so malloc a copy for BoringCrypto to free.
e6cd3c
-		var clabel *C.uint8_t
e6cd3c
-		clabel = nil
e6cd3c
-		// OpenSSL 1.1.1 does not take ownership of the label if the length is zero.
e6cd3c
-		// Depending on the malloc implementation, if clabel is allocated with malloc(0),
e6cd3c
-		// metadata for the size-zero allocation is never cleaned up, which is a memory leak.
e6cd3c
-		// As such, we must only allocate clabel if the label is of non zero length.
e6cd3c
-		if len(label) > 0 {
e6cd3c
-			clabel = (*C.uint8_t)(C.malloc(C.size_t(len(label))))
e6cd3c
-			if clabel == nil {
e6cd3c
-				return nil, nil, fail("OPENSSL_malloc")
e6cd3c
-			}
e6cd3c
-			copy((*[1 << 30]byte)(unsafe.Pointer(clabel))[:len(label)], label)
e6cd3c
+		clabel := (*C.uint8_t)(C.malloc(C.size_t(len(label))))
e6cd3c
+		if clabel == nil {
034e53
+			return nil, nil, NewOpenSSLError("OPENSSL_malloc")
034e53
 		}
e6cd3c
-		if C._goboringcrypto_EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, clabel, C.int(len(label))) != 1 {
e6cd3c
-			if clabel != nil {
e6cd3c
-				C.free(unsafe.Pointer(clabel))
e6cd3c
-			}
e6cd3c
+		copy((*[1 << 30]byte)(unsafe.Pointer(clabel))[:len(label)], label)
e6cd3c
+		if C._goboringcrypto_EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, clabel, C.int(len(label))) == 0 {
e6cd3c
 			return nil, nil, NewOpenSSLError("EVP_PKEY_CTX_set0_rsa_oaep_label failed")
e6cd3c
 		}
e6cd3c
 	}
e6cd3c
@@ -276,12 +267,13 @@ func SignRSAPSS(priv *PrivateKeyRSA, h crypto.Hash, hashed []byte, saltLen int)
034e53
 	}
034e53
 	var out []byte
034e53
 	var outLen C.uint
034e53
-	if priv.withKey(func(key *C.GO_RSA) C.int {
034e53
+	result := priv.withKey(func(key *C.GO_RSA) C.int {
034e53
 		out = make([]byte, C._goboringcrypto_RSA_size(key))
034e53
 		return C._goboringcrypto_RSA_sign_pss_mgf1(key, &outLen, base(out), C.uint(len(out)),
034e53
 			base(hashed), C.uint(len(hashed)), md, nil, C.int(saltLen))
034e53
-	}) == 0 {
034e53
-		return nil, fail("RSA_sign_pss_mgf1")
034e53
+	})
034e53
+	if result != 1 {
034e53
+		return nil, NewOpenSSLError("RSA_sign_pss_mgf1: returned " + strconv.Itoa(int(result)))
034e53
 	}
034e53
 
034e53
 	return out[:outLen], nil
e6cd3c
@@ -295,11 +287,12 @@ func VerifyRSAPSS(pub *PublicKeyRSA, h crypto.Hash, hashed, sig []byte, saltLen
034e53
 	if saltLen == 0 {
034e53
 		saltLen = -2 // auto-recover
034e53
 	}
034e53
-	if pub.withKey(func(key *C.GO_RSA) C.int {
034e53
+	result := pub.withKey(func(key *C.GO_RSA) C.int {
034e53
 		return C._goboringcrypto_RSA_verify_pss_mgf1(key, base(hashed), C.uint(len(hashed)),
034e53
 			md, nil, C.int(saltLen), base(sig), C.uint(len(sig)))
034e53
-	}) == 0 {
034e53
-		return fail("RSA_verify_pss_mgf1")
034e53
+		})
034e53
+	if result != 1 {
034e53
+		return NewOpenSSLError("RSA_verify_pss_mgf1: returned " + strconv.Itoa(int(result)))
034e53
 	}
034e53
 	return nil
034e53
 }
034e53
diff --git a/src/crypto/rsa/pkcs1v15.go b/src/crypto/rsa/pkcs1v15.go
034e53
index 2d425f9..ceb32d0 100644
034e53
--- a/src/crypto/rsa/pkcs1v15.go
034e53
+++ b/src/crypto/rsa/pkcs1v15.go
034e53
@@ -102,7 +102,7 @@ func DecryptPKCS1v15(rand io.Reader, priv *PrivateKey, ciphertext []byte) ([]byt
034e53
 		}
034e53
 		out, err := boring.DecryptRSAPKCS1(bkey, ciphertext)
034e53
 		if err != nil {
034e53
-			return nil, ErrDecryption
034e53
+			return nil, err
034e53
 		}
034e53
 		return out, nil
034e53
 	}
034e53
diff --git a/src/crypto/rsa/pkcs1v15_test.go b/src/crypto/rsa/pkcs1v15_test.go
034e53
index 3dd1ec9..60c769c 100644
034e53
--- a/src/crypto/rsa/pkcs1v15_test.go
034e53
+++ b/src/crypto/rsa/pkcs1v15_test.go
034e53
@@ -9,7 +9,6 @@ import (
034e53
 	"crypto"
034e53
 	"crypto/internal/boring"
034e53
 	"crypto/rand"
034e53
-	"crypto/sha1"
034e53
 	"crypto/sha256"
034e53
 	"encoding/base64"
034e53
 	"encoding/hex"
034e53
@@ -32,22 +31,22 @@ type DecryptPKCS1v15Test struct {
034e53
 	in, out string
034e53
 }
034e53
 
034e53
-// These test vectors were generated with `openssl rsautl -pkcs -encrypt`
034e53
+// Test vectors for testRSA2048PrivateKey
034e53
 var decryptPKCS1v15Tests = []DecryptPKCS1v15Test{
034e53
 	{
034e53
-		"gIcUIoVkD6ATMBk/u/nlCZCCWRKdkfjCgFdo35VpRXLduiKXhNz1XupLLzTXAybEq15juc+EgY5o0DHv/nt3yg==",
034e53
+		"Ppg5lRhQZ8zLMgU8jFWURwm+Oj3t1+9x8qIDZwWMlP6O1QVO4xXxHdheVnLRa0Iq+L5HTgjk/PNNkSLIMD11ERxbMD5NtXoj64qaQDkyIBXaN0FNc5Nga/Lbb+vXVYSJ5F4KIOUYaOwzgNSCMensYNz5/7TloMy2Zoqa6vsWzcU+ujfyFaNjJXC26ZM0zv/4v9Aqqb/WIsLjEgdVvplqL1jwbI8Vv/MLEpQRay3S2RHoS9PIcvGKe3Ze0nOE8rAPiRQKfAsX+zlMkw1+LDttb5Dg/vM4lGF6jTg/nmfgCb6gjWE+QpapLKuZIN3WOwG/zslKeROErPn71xAlVeHI1Q==",
034e53
 		"x",
034e53
 	},
034e53
 	{
034e53
-		"Y7TOCSqofGhkRb+jaVRLzK8xw2cSo1IVES19utzv6hwvx+M8kFsoWQm5DzBeJCZTCVDPkTpavUuEbgp8hnUGDw==",
034e53
+		"kjtn1z9R67b0t7RydEoXeK9GC9wWt1J47i+14alOLCuWr9aqnJxYJS+jr2Z3/TWf4qqTiEujIP5bzvM8vnU2cnJqOGUqoH5xH1+8gq9aD0RbVY0auvUxPUKI3foLoMlp6M1fTSJGiuD9DASp7BZfiMvsU1kKPrLlHpu4azOKbAfIojyyt64Dl3cIpha8FBakym1SRM2iJKKBVae3Reu58uGX9lHroJAWiIdDT4VDIGXQv9dvsViPn4hvWKls5xYtf3V5GPHyvrptsLYcqBOUXM1Wnu2SpZxKRuyz9tWA3w377XNByDMchLJeC4qxdA6ayo53ckXr0no0fU0JrRHkdg==",
034e53
 		"testing.",
034e53
 	},
034e53
 	{
034e53
-		"arReP9DJtEVyV2Dg3dDp4c/PSk1O6lxkoJ8HcFupoRorBZG+7+1fDAwT1olNddFnQMjmkb8vxwmNMoTAT/BFjQ==",
034e53
+		"gljV2jJNON8RwzgVezwG/ddFWPSpGHgnUgEot42vU7Kow5TMvd43f9QAJsPQd0ocT9YIp/3km+2CSWWr+5E3fWW0p2cQBxUfnsJFsNKPvQt6Ct7Bn8HzkhxLJuvIShFzQlBuph4hBuN33dWhAFFDESsZnPvU6EFJlmTHrmqY+H9cdECU4hXQ1R7Z+lHlvT8RxDNBu1fdAarRXcKrw9EeN2ZwSvVx62aXnAcAQQkijmOn9dkObgqeii/wHPI28SR/Aa/hTw1XE5DoZmDBCx6EFJ4hcY7MKAX0iSQiaxinM+IxkqiCftOnvYv737cD/vKG6llhGCCDx0Et5xYu2JWakw==",
034e53
 		"testing.\n",
034e53
 	},
034e53
 	{
034e53
-		"WtaBXIoGC54+vH0NH0CHHE+dRDOsMc/6BrfFu2lEqcKL9+uDuWaf+Xj9mrbQCjjZcpQuX733zyok/jsnqe/Ftw==",
034e53
+		"iJiYwVBtLhZBmYngT5u+YR5+raI33OvpShPR9arl4zSss+eK5krMANZUTrRCsw8Tho6kpyDgVohfH5V/8zX4Rtslak1peZdvnmcEkJCFk0FpnlcALRBGTCXUJEwxlSgaTz00awCjkfLzMYNCwTAlEP9QxUX2kSIABKSUw4ARwZ5jQTGCdJNl696Q/cF1JjEqsjpPbjn4UYkV3gNl0xXPiTVgfNJKZir1caEGOKfOsfbTFixvA5oANgRySxwZfoj/6dW9xIVgcq/ssmkTl8TnTKQTY0dRTNWs8+HuQxp2I4MSmAun6LYdr8pom1IazJtp1BEaSDZ+thRIQ/oMsYDJXQ==",
034e53
 		"01234567890123456789012345678901234567890123456789012",
034e53
 	},
034e53
 }
034e53
@@ -55,10 +54,10 @@ var decryptPKCS1v15Tests = []DecryptPKCS1v15Test{
034e53
 func TestDecryptPKCS1v15(t *testing.T) {
034e53
 	decryptionFuncs := []func([]byte) ([]byte, error){
034e53
 		func(ciphertext []byte) (plaintext []byte, err error) {
034e53
-			return DecryptPKCS1v15(nil, rsaPrivateKey, ciphertext)
034e53
+			return DecryptPKCS1v15(nil, testRSA2048PrivateKey, ciphertext)
034e53
 		},
034e53
 		func(ciphertext []byte) (plaintext []byte, err error) {
034e53
-			return rsaPrivateKey.Decrypt(nil, ciphertext, nil)
034e53
+			return testRSA2048PrivateKey.Decrypt(nil, ciphertext, nil)
034e53
 		},
034e53
 	}
034e53
 
034e53
@@ -78,14 +77,14 @@ func TestDecryptPKCS1v15(t *testing.T) {
034e53
 
034e53
 func TestEncryptPKCS1v15(t *testing.T) {
034e53
 	random := rand.Reader
034e53
-	k := (rsaPrivateKey.N.BitLen() + 7) / 8
034e53
+	k := (testRSA2048PrivateKey.N.BitLen() + 7) / 8
034e53
 
034e53
 	tryEncryptDecrypt := func(in []byte, blind bool) bool {
034e53
 		if len(in) > k-11 {
034e53
 			in = in[0 : k-11]
034e53
 		}
034e53
 
034e53
-		ciphertext, err := EncryptPKCS1v15(random, &rsaPrivateKey.PublicKey, in)
034e53
+		ciphertext, err := EncryptPKCS1v15(random, &testRSA2048PrivateKey.PublicKey, in)
034e53
 		if err != nil {
034e53
 			t.Errorf("error encrypting: %s", err)
034e53
 			return false
034e53
@@ -97,7 +96,7 @@ func TestEncryptPKCS1v15(t *testing.T) {
034e53
 		} else {
034e53
 			rand = random
034e53
 		}
034e53
-		plaintext, err := DecryptPKCS1v15(rand, rsaPrivateKey, ciphertext)
034e53
+		plaintext, err := DecryptPKCS1v15(rand, testRSA2048PrivateKey, ciphertext)
034e53
 		if err != nil {
034e53
 			t.Errorf("error decrypting: %s", err)
034e53
 			return false
034e53
@@ -117,22 +116,22 @@ func TestEncryptPKCS1v15(t *testing.T) {
034e53
 	quick.Check(tryEncryptDecrypt, config)
034e53
 }
034e53
 
034e53
-// These test vectors were generated with `openssl rsautl -pkcs -encrypt`
034e53
+// Test vectors for testRSA2048PrivateKey
034e53
 var decryptPKCS1v15SessionKeyTests = []DecryptPKCS1v15Test{
034e53
 	{
034e53
-		"e6ukkae6Gykq0fKzYwULpZehX+UPXYzMoB5mHQUDEiclRbOTqas4Y0E6nwns1BBpdvEJcilhl5zsox/6DtGsYg==",
034e53
+		"cSBy/rsocfCY2L/WDP7+oyI/uk0qf3BuJvWo1VwV/DG9XLuu7J1Gb2e7hYl3kmdf6rSnoqDuVE3viOsGeq1OsW9w0uw08syTwdOp34z90qxlrrKsGjjz9XIgErqwlWvfQ5KQQb8KA29Ub7q0sqQMMQD75bUxN3P4GhtOG6kNVY33QoCIVR65vHLcqe3SlrxAfYzlOjMNwdPsNP1GGVyAZpccxOiBJSUrssAFvRJ3g62wj2xrrtneRztmOGOy8ZSiEjGNjJ4/lmJXt2GyPXapTTKeHFbyqh5Xu8PNgMxaCgtWgMqnK6CPbJOGgski9axyaxPzjKEjUcs99dJ1mTT+qw==",
034e53
 		"1234",
034e53
 	},
034e53
 	{
034e53
-		"Dtis4uk/q/LQGGqGk97P59K03hkCIVFMEFZRgVWOAAhxgYpCRG0MX2adptt92l67IqMki6iVQyyt0TtX3IdtEw==",
034e53
+		"lcsS8tzZSJSiaaOSQSO4pT3Je5vvrNfAVUy3Axojr4uRreMuLRTIOOmEYRM/JcWakpJelPd+EHG/aXxId8aCoBg1MkH5q8AHW3zUARhlOd91rpASVs03v5wuk0jtiQiqr0HLNyxifSEzj04VPklc6n00yuHbI+DNTATTVkxj3a5hgOECqKi2matXGcJ5FtMEPAi2V+36y2dQ+DA/tgQrhlZ4ycA2FJnjvOHRJbC6QwNzPkzbjTlCqNzq92nwWKDypVJ29CrIQ2HYXG63DOuT96gIa08hyeZEeIrAUjtb9DK1TSEF/9BDASffHevW3/CqfpRYnFSNOj2xli3wBn1Dvg==",
034e53
 		"FAIL",
034e53
 	},
034e53
 	{
034e53
-		"LIyFyCYCptPxrvTxpol8F3M7ZivlMsf53zs0vHRAv+rDIh2YsHS69ePMoPMe3TkOMZ3NupiL3takPxIs1sK+dw==",
034e53
+		"Bsrz5yYuevhqx1Pxx4zEsegU2aVBZ2h9ebtAgQkq3N/og0t+8O92XpPBoNH/HT2jHclh01aij1niCqdBn2/6GBN4irnVjrWQkoAV2Q5Q+gVS0ZYeTzeX/15M/iq9xeLjBPXqj5PmNYh+vbL05FyPB+CcY8MPyv7HmtDsAWRVDxQVWy6y4lmC1/VwnG5jtmAbapE+Vyty0iVb9/Q6UaaV7DVKVssEDmwnychibJ4ACcTQ18kLkB1AE73dXp1B/XHh6ExbHXoaPeaRYr2gEI0No6VBTrMrG5eVz3dub/a5MVeat9n/oU2QQ3s/Pm0FlF9n2mwgvKm/4nLjwjiTFt3ToQ==",
034e53
 		"abcd",
034e53
 	},
034e53
 	{
034e53
-		"bafnobel46bKy76JzqU/RIVOH0uAYvzUtauKmIidKgM0sMlvobYVAVQPeUQ/oTGjbIZ1v/6Gyi5AO4DtHruGdw==",
034e53
+		"FKynVeuuoYxonMoXWwIw3mY7KTV3yS3fe2D+h5v6FXs/0xb5PeINCEq0+Ub5LFAZcx/lIbnt4bkLZcaKDxLpBCxpvpZNdgGxP970BvE5xmOuagF47VaqCciiERTTztRjwKTu0PZ5VtcpsxiSN4axlC1NOpJnIpDsNOWUaf5G6fCCEdfZWwgxaHLbxSAy+IdUHBH+honCPPZAyGyhERdcDRGJ8a6R20MFXC18e8asHtF5VWaicaYe0fy1Mrii46WqFY8hwoSrbHOGEQkjRymM/IQvXFdxQ1vtzAFavUsr5taiVe84DvcFJ5eRZ2jpVQTdO4gBy6RyD64iNSrv8a5dqA==",
034e53
 		"FAIL",
034e53
 	},
034e53
 }
034e53
@@ -140,7 +139,7 @@ var decryptPKCS1v15SessionKeyTests = []DecryptPKCS1v15Test{
034e53
 func TestEncryptPKCS1v15SessionKey(t *testing.T) {
034e53
 	for i, test := range decryptPKCS1v15SessionKeyTests {
034e53
 		key := []byte("FAIL")
034e53
-		err := DecryptPKCS1v15SessionKey(nil, rsaPrivateKey, decodeBase64(test.in), key)
034e53
+		err := DecryptPKCS1v15SessionKey(nil, testRSA2048PrivateKey, decodeBase64(test.in), key)
034e53
 		if err != nil {
034e53
 			t.Errorf("#%d error decrypting", i)
034e53
 		}
034e53
@@ -153,7 +152,7 @@ func TestEncryptPKCS1v15SessionKey(t *testing.T) {
034e53
 
034e53
 func TestEncryptPKCS1v15DecrypterSessionKey(t *testing.T) {
034e53
 	for i, test := range decryptPKCS1v15SessionKeyTests {
034e53
-		plaintext, err := rsaPrivateKey.Decrypt(rand.Reader, decodeBase64(test.in), &PKCS1v15DecryptOptions{SessionKeyLen: 4})
034e53
+		plaintext, err := testRSA2048PrivateKey.Decrypt(rand.Reader, decodeBase64(test.in), &PKCS1v15DecryptOptions{SessionKeyLen: 4})
034e53
 		if err != nil {
034e53
 			t.Fatalf("#%d: error decrypting: %s", i, err)
034e53
 		}
034e53
@@ -187,19 +186,19 @@ type signPKCS1v15Test struct {
034e53
 	in, out string
034e53
 }
034e53
 
034e53
-// These vectors have been tested with
034e53
-//   `openssl rsautl -verify -inkey pk -in signature | hexdump -C`
034e53
-var signPKCS1v15Tests = []signPKCS1v15Test{
034e53
-	{"Test.\n", "a4f3fa6ea93bcdd0c57be020c1193ecbfd6f200a3d95c409769b029578fa0e336ad9a347600e40d3ae823b8c7e6bad88cc07c1d54c3a1523cbbb6d58efc362ae"},
034e53
+// Test vector for testRSA2048PrivateKey
034e53
+// generated with `openssl pkeyutl -rawin -digest sha256 -sign -inkey <key>`
034e53
+ var signPKCS1v15Tests = []signPKCS1v15Test{
034e53
+	{"Test.\n", "467c3c8f16223ba09aecfe44488d6b34b3f91f11379949b1d8af31636ee8b3aa51eebb96ee11678323cb1f909af17c9d0fe4b6012078af8120474474efd1bb51765e1647369ddba6525c6608113857bb0e2aaed9ad01fe041b476b162f7d4db55bb31fa957046616ce463cecb2a66f38fa62c594d07afcc870582d545853b31fa705ab8565e4085804c32e73459720bf4e08f097843b0845116d4376231fa2472abc89b1e42462002bf70f9a1df31db6d2ab6dc52c8223798a4f57c40d6a9123b80739846d779044eac28d8c783e8ce73919f1d4a6efe8fb601b8d36c5c9b61654d6f8717d1fb9fcafa19669200900899dd08ce921a1745312eb06040a405903"},
034e53
 }
034e53
 
034e53
 func TestSignPKCS1v15(t *testing.T) {
034e53
 	for i, test := range signPKCS1v15Tests {
034e53
-		h := sha1.New()
034e53
+		h := sha256.New()
034e53
 		h.Write([]byte(test.in))
034e53
 		digest := h.Sum(nil)
034e53
 
034e53
-		s, err := SignPKCS1v15(nil, rsaPrivateKey, crypto.SHA1, digest)
034e53
+		s, err := SignPKCS1v15(nil, testRSA2048PrivateKey, crypto.SHA256, digest)
034e53
 		if err != nil {
034e53
 			t.Errorf("#%d %s", i, err)
034e53
 		}
034e53
@@ -213,13 +212,13 @@ func TestSignPKCS1v15(t *testing.T) {
034e53
 
034e53
 func TestVerifyPKCS1v15(t *testing.T) {
034e53
 	for i, test := range signPKCS1v15Tests {
034e53
-		h := sha1.New()
034e53
+		h := sha256.New()
034e53
 		h.Write([]byte(test.in))
034e53
 		digest := h.Sum(nil)
034e53
 
034e53
 		sig, _ := hex.DecodeString(test.out)
034e53
 
034e53
-		err := VerifyPKCS1v15(&rsaPrivateKey.PublicKey, crypto.SHA1, digest, sig)
034e53
+		err := VerifyPKCS1v15(&testRSA2048PrivateKey.PublicKey, crypto.SHA256, digest, sig)
034e53
 		if err != nil {
034e53
 			t.Errorf("#%d %s", i, err)
034e53
 		}
034e53
@@ -230,7 +229,7 @@ func TestHashVerifyPKCS1v15(t *testing.T) {
034e53
 	for i, test := range signPKCS1v15Tests {
034e53
 		sig, _ := hex.DecodeString(test.out)
034e53
 
034e53
-		err := HashVerifyPKCS1v15(&rsaPrivateKey.PublicKey, crypto.SHA1, []byte(test.in), sig)
034e53
+		err := HashVerifyPKCS1v15(&testRSA2048PrivateKey.PublicKey, crypto.SHA256, []byte(test.in), sig)
034e53
 		if err != nil {
034e53
 			t.Errorf("#%d %s", i, err)
034e53
 		}
034e53
@@ -273,19 +272,47 @@ func TestUnpaddedSignature(t *testing.T) {
034e53
 func TestShortSessionKey(t *testing.T) {
034e53
 	// This tests that attempting to decrypt a session key where the
034e53
 	// ciphertext is too small doesn't run outside the array bounds.
034e53
-	ciphertext, err := EncryptPKCS1v15(rand.Reader, &rsaPrivateKey.PublicKey, []byte{1})
034e53
-	if err != nil {
034e53
-		t.Fatalf("Failed to encrypt short message: %s", err)
034e53
+	var keys []*PrivateKey
034e53
+	if boring.Enabled() {
034e53
+		keys = GenerateTestPrivateKeys()
034e53
+	} else {
034e53
+		keys = []*PrivateKey{rsaPrivateKey}
034e53
 	}
034e53
 
034e53
-	var key [32]byte
034e53
-	if err := DecryptPKCS1v15SessionKey(nil, rsaPrivateKey, ciphertext, key[:]); err != nil {
034e53
-		t.Fatalf("Failed to decrypt short message: %s", err)
034e53
-	}
034e53
+        for i, k := range keys {
034e53
+
034e53
+		if k.Size() >= 256 || !boring.Enabled() {
034e53
+			ciphertext, err := EncryptPKCS1v15(rand.Reader, &k.PublicKey, []byte{1})
034e53
+			if err != nil {
034e53
+				t.Fatalf("Failed to encrypt short message: key: %v, %s", i, err)
034e53
+				continue
034e53
+			}
034e53
+
034e53
+			var key [32]byte
034e53
+			if err := DecryptPKCS1v15SessionKey(nil, k, ciphertext, key[:]); err != nil {
034e53
+				t.Fatalf("Failed to decrypt short message: key: %v, %s", i, err)
034e53
+				continue
034e53
+			}
034e53
+
034e53
+			for _, v := range key {
034e53
+				if v != 0 {
034e53
+					t.Fatal("key was modified when ciphertext was invalid")
034e53
+				}
034e53
+			}
034e53
+		} else {
034e53
+			ciphertext, err := EncryptPKCS1v15(rand.Reader, &k.PublicKey, []byte{1})
034e53
+			if err == nil {
034e53
+				t.Errorf("EncryptPKCS1v15: Should reject key smaller than 2048 bits")
034e53
+			} else {
034e53
+				continue
034e53
+			}
034e53
+
034e53
+			var key [32]byte
034e53
+			err = DecryptPKCS1v15SessionKey(nil, k, ciphertext, key[:]);
034e53
+			if err != nil {
034e53
+				t.Errorf("DecryptPKCS1v15SessionKey: Should reject key smaller than 2048 bits")
034e53
+			}
034e53
 
034e53
-	for _, v := range key {
034e53
-		if v != 0 {
034e53
-			t.Fatal("key was modified when ciphertext was invalid")
034e53
 		}
034e53
 	}
034e53
 }
034e53
@@ -313,6 +340,28 @@ var rsaPrivateKey = &PrivateKey{
034e53
 	},
034e53
 }
034e53
 
034e53
+func generateKey(size int) *PrivateKey {
034e53
+	result, err := GenerateKey(rand.Reader, size)
034e53
+	if err != nil {
034e53
+		panic("could not generate key")
034e53
+	}
034e53
+	return result
034e53
+}
034e53
+
034e53
+func GenerateTestPrivateKeys() []*PrivateKey {
034e53
+
034e53
+	keys := []*PrivateKey{
034e53
+		generateKey(128),
034e53
+		generateKey(256),
034e53
+		generateKey(768),
034e53
+		generateKey(1024),
034e53
+		generateKey(2048),
034e53
+		generateKey(3072),
034e53
+		generateKey(4096),
034e53
+	}
034e53
+	return keys
034e53
+}
034e53
+
034e53
 func TestShortPKCS1v15Signature(t *testing.T) {
034e53
 	pub := &PublicKey{
034e53
 		E: 65537,
034e53
diff --git a/src/crypto/rsa/pss_test.go b/src/crypto/rsa/pss_test.go
8d5b6a
index 6a5a93f..2032b4b 100644
034e53
--- a/src/crypto/rsa/pss_test.go
034e53
+++ b/src/crypto/rsa/pss_test.go
8d5b6a
@@ -132,7 +132,6 @@ func TestPSSGolden(t *testing.T) {
034e53
 	opts := &PSSOptions{
034e53
 		SaltLength: PSSSaltLengthEqualsHash,
034e53
 	}
034e53
-
034e53
 	for marker := range values {
034e53
 		switch marker {
034e53
 		case newKeyMarker:
8d5b6a
@@ -174,18 +173,13 @@ func TestPSSOpenSSL(t *testing.T) {
034e53
 	h.Write(hashed)
034e53
 	hashed = h.Sum(nil)
034e53
 
034e53
+	// Test vector for testRSA2048PrivateKey
034e53
 	// Generated with `echo -n testing | openssl dgst -sign key.pem -sigopt rsa_padding_mode:pss -sha256 > sig`
034e53
 	sig := []byte{
034e53
-		0x95, 0x59, 0x6f, 0xd3, 0x10, 0xa2, 0xe7, 0xa2, 0x92, 0x9d,
034e53
-		0x4a, 0x07, 0x2e, 0x2b, 0x27, 0xcc, 0x06, 0xc2, 0x87, 0x2c,
034e53
-		0x52, 0xf0, 0x4a, 0xcc, 0x05, 0x94, 0xf2, 0xc3, 0x2e, 0x20,
034e53
-		0xd7, 0x3e, 0x66, 0x62, 0xb5, 0x95, 0x2b, 0xa3, 0x93, 0x9a,
034e53
-		0x66, 0x64, 0x25, 0xe0, 0x74, 0x66, 0x8c, 0x3e, 0x92, 0xeb,
034e53
-		0xc6, 0xe6, 0xc0, 0x44, 0xf3, 0xb4, 0xb4, 0x2e, 0x8c, 0x66,
034e53
-		0x0a, 0x37, 0x9c, 0x69,
034e53
+		0x50, 0x97, 0xc1, 0xe2, 0x7c, 0x67, 0x99, 0x50, 0xdc, 0x5a, 0x43, 0xc6, 0xc6, 0xf2, 0xf1, 0xff, 0xcd, 0xe7, 0x66, 0xef, 0x61, 0x41, 0x5f, 0x49, 0x4f, 0xf0, 0x11, 0xfc, 0x3d, 0xa8, 0xf9, 0x3c, 0x3a, 0x8a, 0x71, 0x5c, 0xfa, 0xbc, 0x48, 0x73, 0x37, 0xec, 0x68, 0x6d, 0x6c, 0xca, 0xe, 0x30, 0x74, 0xe1, 0xbd, 0x88, 0xb6, 0x42, 0x92, 0x8d, 0x41, 0x5f, 0x7, 0x80, 0xc5, 0xef, 0xa3, 0x2e, 0x68, 0x47, 0x83, 0xb4, 0x96, 0x4c, 0x53, 0x61, 0x2c, 0xe8, 0xb8, 0x3, 0xae, 0x44, 0x5e, 0xb3, 0x44, 0x10, 0x58, 0xfd, 0x68, 0x9c, 0x33, 0xac, 0x63, 0xfe, 0x9d, 0x84, 0xab, 0x45, 0x70, 0x54, 0xc5, 0x90, 0x1e, 0x80, 0xd4, 0x31, 0x16, 0x15, 0x4b, 0x60, 0x13, 0x24, 0xa, 0xa8, 0xbc, 0xe5, 0xeb, 0xf8, 0x7d, 0x32, 0xd9, 0xcd, 0x8b, 0xef, 0x55, 0x60, 0x1, 0xa6, 0x99, 0xa2, 0xde, 0xb0, 0x68, 0xc1, 0x64, 0x8b, 0x6, 0xe6, 0x75, 0xcf, 0x2d, 0x7a, 0x8b, 0xd6, 0xa3, 0x99, 0xf1, 0xc9, 0xaf, 0x9a, 0x81, 0xe4, 0xac, 0x2e, 0x17, 0x8c, 0x49, 0xfc, 0x12, 0x79, 0xfb, 0x4a, 0xba, 0x68, 0xd8, 0xdb, 0x43, 0x6c, 0x15, 0xaf, 0xa4, 0x16, 0x2f, 0xc9, 0x1e, 0xbe, 0xef, 0xb3, 0x35, 0x14, 0x2f, 0x35, 0x41, 0x10, 0xf8, 0x32, 0xf8, 0x0, 0x5c, 0xbf, 0x77, 0xa, 0xbb, 0x77, 0x49, 0x47, 0x54, 0x7a, 0x58, 0xfd, 0xb3, 0x2c, 0x46, 0xa0, 0x5c, 0x3, 0x7a, 0xf7, 0xab, 0x77, 0xdb, 0xca, 0x9a, 0x38, 0x89, 0xb, 0x3e, 0xb0, 0x13, 0xe8, 0x16, 0xc0, 0xca, 0x29, 0xbb, 0x4a, 0x97, 0x46, 0x53, 0x59, 0x66, 0x81, 0x84, 0x6d, 0xe5, 0xda, 0x26, 0xc9, 0x83, 0xfc, 0x67, 0xd0, 0x96, 0x72, 0x81, 0x1c, 0xe0, 0x4, 0xb7, 0x0, 0xca, 0xe0, 0x4a, 0x51, 0x4e, 0x83, 0xc8, 0xeb, 0xf7, 0x6d,
034e53
 	}
034e53
 
034e53
-	if err := VerifyPSS(&rsaPrivateKey.PublicKey, hash, hashed, sig, nil); err != nil {
034e53
+	if err := VerifyPSS(&testRSA2048PrivateKey.PublicKey, hash, hashed, sig, nil); err != nil {
034e53
 		t.Error(err)
034e53
 	}
034e53
 }
8d5b6a
@@ -212,24 +206,47 @@ func TestPSSSigning(t *testing.T) {
034e53
 		{8, 8, true},
034e53
 	}
034e53
 
034e53
+	var opts PSSOptions
034e53
 	hash := crypto.SHA1
034e53
+	keys := []*PrivateKey{rsaPrivateKey}
034e53
+	if boring.Enabled() {
034e53
+		hash = crypto.SHA256
034e53
+		keys = GenerateTestPrivateKeys()
034e53
+	}
034e53
 	h := hash.New()
034e53
 	h.Write([]byte("testing"))
034e53
 	hashed := h.Sum(nil)
034e53
-	var opts PSSOptions
034e53
 
034e53
-	for i, test := range saltLengthCombinations {
034e53
-		opts.SaltLength = test.signSaltLength
034e53
-		sig, err := SignPSS(rand.Reader, rsaPrivateKey, hash, hashed, &opts)
034e53
-		if err != nil {
034e53
-			t.Errorf("#%d: error while signing: %s", i, err)
034e53
-			continue
034e53
-		}
034e53
+	for _, key := range keys {
034e53
+		if !boring.Enabled() || key.Size() >= 256 {
034e53
+			for i, test := range saltLengthCombinations {
034e53
+				opts.SaltLength = test.signSaltLength
034e53
+				sig, err := SignPSS(rand.Reader, key, hash, hashed, &opts)
034e53
+				if err != nil {
034e53
+					t.Errorf("#%d: ALG: %v, error while signing: %s", i, hash, err)
034e53
+					continue
034e53
+				}
034e53
+				opts.SaltLength = test.verifySaltLength
034e53
+				err = VerifyPSS(&key.PublicKey, hash, hashed, sig, &opts)
034e53
+				if (err == nil) != test.good {
034e53
+					t.Errorf("#%d: bad result, wanted: %t, got: %s", i, test.good, err)
034e53
+				}
034e53
+			}
034e53
+		} else {
034e53
+			 for _, test := range saltLengthCombinations {
034e53
+				opts.SaltLength = test.signSaltLength
034e53
+				sig, err := SignPSS(rand.Reader, key, hash, hashed, &opts)
034e53
+				if err == nil {
034e53
+					t.Errorf("SignPSS should reject key of size: %v\n%v", key.Size() * 8, err)
034e53
+					continue
034e53
+				}
034e53
+				opts.SaltLength = test.verifySaltLength
034e53
+				err = VerifyPSS(&key.PublicKey, hash, hashed, sig, &opts)
034e53
+				if (err == nil) {
034e53
+					t.Errorf("VerifyPSS should reject key of size: %v\n%v", key.Size() * 8, err)
034e53
+				}
034e53
+			}
034e53
 
034e53
-		opts.SaltLength = test.verifySaltLength
034e53
-		err = VerifyPSS(&rsaPrivateKey.PublicKey, hash, hashed, sig, &opts)
034e53
-		if (err == nil) != test.good {
034e53
-			t.Errorf("#%d: bad result, wanted: %t, got: %s", i, test.good, err)
034e53
 		}
034e53
 	}
034e53
 }
e6cd3c
diff --git a/src/crypto/rsa/rsa.go b/src/crypto/rsa/rsa.go
e6cd3c
index 24e2d22..1fd5a9a 100644
e6cd3c
--- a/src/crypto/rsa/rsa.go
e6cd3c
+++ b/src/crypto/rsa/rsa.go
e6cd3c
@@ -35,6 +35,7 @@ import (
e6cd3c
 	"crypto/internal/boring"
e6cd3c
 	"crypto/internal/randutil"
e6cd3c
 	"unsafe"
e6cd3c
+	"fmt"
e6cd3c
 )
e6cd3c
 
e6cd3c
 var bigZero = big.NewInt(0)
e6cd3c
@@ -664,7 +665,7 @@ func DecryptOAEP(hash hash.Hash, random io.Reader, priv *PrivateKey, ciphertext
e6cd3c
 		}
e6cd3c
 		out, err := boring.DecryptRSAOAEP(hash, bkey, ciphertext, label)
e6cd3c
 		if err != nil {
e6cd3c
-			return nil, ErrDecryption
e6cd3c
+			return nil, fmt.Errorf("decryption error: %s", err)
e6cd3c
 		}
e6cd3c
 		return out, nil
e6cd3c
 	}
034e53
diff --git a/src/crypto/rsa/rsa_test.go b/src/crypto/rsa/rsa_test.go
034e53
index d9693a7..cfe020e 100644
034e53
--- a/src/crypto/rsa/rsa_test.go
034e53
+++ b/src/crypto/rsa/rsa_test.go
034e53
@@ -13,6 +13,7 @@ import (
034e53
 	"fmt"
034e53
 	"math/big"
034e53
 	"testing"
034e53
+
034e53
 )
034e53
 
034e53
 import "crypto/internal/boring"
034e53
@@ -34,34 +35,42 @@ func TestKeyGeneration(t *testing.T) {
034e53
 }
034e53
 
034e53
 func Test3PrimeKeyGeneration(t *testing.T) {
034e53
-	size := 768
034e53
+	var sizes []int
034e53
 	if testing.Short() {
034e53
-		size = 256
034e53
+		sizes = []int{256}
034e53
+	} else {
034e53
+		sizes = []int{128, 768, 1024, 2048, 3072}
034e53
 	}
034e53
+	for _, size := range sizes {
034e53
 
034e53
-	priv, err := GenerateMultiPrimeKey(rand.Reader, 3, size)
034e53
-	if err != nil {
034e53
-		t.Errorf("failed to generate key")
034e53
+		priv, err := GenerateMultiPrimeKey(rand.Reader, 3, size)
034e53
+		if err != nil {
034e53
+			t.Errorf("failed to generate key")
034e53
+		}
034e53
+		testKeyBasics(t, priv)
034e53
 	}
034e53
-	testKeyBasics(t, priv)
034e53
 }
034e53
 
034e53
 func Test4PrimeKeyGeneration(t *testing.T) {
034e53
-	size := 768
034e53
+	var sizes []int
034e53
 	if testing.Short() {
034e53
-		size = 256
034e53
+		sizes = []int{256}
034e53
+	} else {
034e53
+		sizes = []int{128, 768, 1024, 2048, 3072}
034e53
 	}
034e53
+	for _, size := range sizes {
034e53
 
034e53
-	priv, err := GenerateMultiPrimeKey(rand.Reader, 4, size)
034e53
-	if err != nil {
034e53
-		t.Errorf("failed to generate key")
034e53
+		priv, err := GenerateMultiPrimeKey(rand.Reader, 4, size)
034e53
+		if err != nil {
034e53
+			t.Errorf("failed to generate key")
034e53
+		}
034e53
+		testKeyBasics(t, priv)
034e53
 	}
034e53
-	testKeyBasics(t, priv)
034e53
 }
034e53
 
034e53
 func TestNPrimeKeyGeneration(t *testing.T) {
034e53
 	primeSize := 64
034e53
-	maxN := 24
034e53
+	maxN := 32
034e53
 	if testing.Short() {
034e53
 		primeSize = 16
034e53
 		maxN = 16
034e53
@@ -117,18 +126,32 @@ func testKeyBasics(t *testing.T, priv *PrivateKey) {
034e53
 	if boring.Enabled() {
034e53
 		// Cannot call encrypt/decrypt directly. Test via PKCS1v15.
034e53
 		msg := []byte("hi!")
034e53
-		enc, err := EncryptPKCS1v15(rand.Reader, &priv.PublicKey, msg)
034e53
-		if err != nil {
034e53
-			t.Errorf("EncryptPKCS1v15: %v", err)
034e53
-			return
034e53
-		}
034e53
-		dec, err := DecryptPKCS1v15(rand.Reader, priv, enc)
034e53
-		if err != nil {
034e53
-			t.Errorf("DecryptPKCS1v15: %v", err)
034e53
-			return
034e53
-		}
034e53
-		if !bytes.Equal(dec, msg) {
034e53
-			t.Errorf("got:%x want:%x (%+v)", dec, msg, priv)
034e53
+		// Should not accept keys smaller than 2048 bits (256 bytes)
034e53
+		if priv.Size() >= 256 {
034e53
+			enc, err := EncryptPKCS1v15(rand.Reader, &priv.PublicKey, msg)
034e53
+			if err != nil {
034e53
+				t.Errorf("EncryptPKCS1v15: %v", err)
034e53
+				return
034e53
+			}
034e53
+			dec, err := DecryptPKCS1v15(rand.Reader, priv, enc)
034e53
+			if err != nil {
034e53
+				t.Errorf("DecryptPKCS1v15: %v", err)
034e53
+				return
034e53
+			}
034e53
+			if !bytes.Equal(dec, msg) {
034e53
+				t.Errorf("got:%x want:%x (%+v)", dec, msg, priv)
034e53
+			}
034e53
+		} else {
034e53
+			enc, err := EncryptPKCS1v15(rand.Reader, &priv.PublicKey, msg)
034e53
+			if err == nil {
034e53
+				t.Errorf("EncryptPKCS1v15: Should not accept key of size %v", priv.Size() * 8)
034e53
+				return
034e53
+			}
034e53
+			_ , err = DecryptPKCS1v15(rand.Reader, priv, enc)
034e53
+			if err == nil {
034e53
+				t.Errorf("DecryptPKCS1v15: Should not accept key of size %v", priv.Size() * 8)
034e53
+				return
034e53
+			}
034e53
 		}
034e53
 		return
034e53
 	}
034e53
@@ -164,6 +187,7 @@ func fromBase10(base10 string) *big.Int {
034e53
 }
034e53
 
034e53
 var test2048Key *PrivateKey
034e53
+var testRSA2048PrivateKey *PrivateKey
034e53
 
034e53
 func init() {
034e53
 	test2048Key = &PrivateKey{
034e53
@@ -178,6 +202,21 @@ func init() {
034e53
 		},
034e53
 	}
034e53
 	test2048Key.Precompute()
034e53
+	// This is the same testRSA2048PrivateKey from src/crypto/tls/boring_test.go,
034e53
+	// just formatted without using the x509 Parser
034e53
+	testRSA2048PrivateKey = &PrivateKey {
034e53
+		PublicKey: PublicKey{
034e53
+                        N: fromBase10("20191212046465051006148469115982609963794084216822290493008497548603282433337961188011759317867632936762484431807200684727542982286641865915343951546098189846608892055894575224375729344858650310374442622904229900868894242623139807621975608166515302294530216022389036816474348374698399654955992710180316983674809047409565569027596663420090767109285120403886497729233127551307356270679924351259776100107640885071765865832767303853854517356000385050677175012549806941229051812974721510192346810990827150439838227830352248569839727388943852973737249863837089274675024496841834194785931485429238306703429257731792443735979"),
034e53
+                        E: 65537,
034e53
+                },
034e53
+                D: fromBase10("17880854551669112566868255345124108779447961606053558991611260520405836487267781427740459393783689829925402008838157275130340717548134956040019107677074732476577915942750039777107871579671122369249613210066309031335411813988461299033587444447689322284662780986426216011635232478916424602504476935371549462113036228740820951710434375466081011497256196435741125837599218374223248197677547321257961509961401385322723627033844333644253777689603896264679633990939957571483400832267925506777396569554295752505112186882586887396943424085633026984063372469902814987050483471096892524886948283571883744403645335501920852525393"),
034e53
+                Primes: []*big.Int{
034e53
+                        fromBase10("135564917074042739008372452399559667250812269638554028593490636590148234941034106656615266472037321030780472224077878987192393666277731486488609490961161995141171813440923127505183021899359310251888145112092740773465142711876177808655062479870526201006500762429604105802612357839979630776094264195301632424911"),
034e53
+                        fromBase10("148941278335581696308445609123523329975323575697232717856977715718810138995490768513650108277383732380774181214791356462453504708304090734692215322335879527529217737837271384209093576836051031684425884921572908683147368296418243939771852059523598364231128661438022752350148969064661946939745752818523498309989"),
034e53
+                },
034e53
+	}
034e53
+	testRSA2048PrivateKey.Precompute()
034e53
+
034e53
 }
034e53
 
034e53
 func BenchmarkRSA2048Decrypt(b *testing.B) {
034e53
@@ -317,6 +356,11 @@ func TestEncryptDecryptOAEP(t *testing.T) {
034e53
 		priv.PublicKey = PublicKey{N: n, E: test.e}
034e53
 		priv.D = d
034e53
 
034e53
+		if boring.Enabled() && priv.PublicKey.Size() < 256 {
034e53
+			t.Logf("skipping check for unsupported key less than 2048 bits")
034e53
+			continue;
034e53
+		}
034e53
+		t.Logf("running check for supported key size")
034e53
 		for j, message := range test.msgs {
034e53
 			label := []byte(fmt.Sprintf("hi#%d", j))
034e53
 			enc, err := EncryptOAEP(sha256, rand.Reader, &priv.PublicKey, message.in, label)
034e53
diff --git a/src/crypto/tls/boring_test.go b/src/crypto/tls/boring_test.go
8d5b6a
index 94a24ff..577bc73 100644
034e53
--- a/src/crypto/tls/boring_test.go
034e53
+++ b/src/crypto/tls/boring_test.go
034e53
@@ -26,7 +26,7 @@ import (
034e53
 func TestBoringServerProtocolVersion(t *testing.T) {
034e53
 	test := func(name string, v uint16, msg string) {
034e53
 		t.Run(name, func(t *testing.T) {
034e53
-			serverConfig := testConfig.Clone()
034e53
+			serverConfig := testConfigTemplate()
034e53
 			serverConfig.MinVersion = VersionSSL30
034e53
 			clientHello := &clientHelloMsg{
034e53
 				vers:               v,
034e53
@@ -108,7 +108,7 @@ func isBoringSignatureScheme(alg SignatureScheme) bool {
034e53
 }
034e53
 
034e53
 func TestBoringServerCipherSuites(t *testing.T) {
034e53
-	serverConfig := testConfig.Clone()
034e53
+	serverConfig := testConfigTemplate()
034e53
 	serverConfig.CipherSuites = allCipherSuites()
034e53
 	serverConfig.Certificates = make([]Certificate, 1)
034e53
 
034e53
@@ -148,7 +148,7 @@ func TestBoringServerCipherSuites(t *testing.T) {
034e53
 }
034e53
 
034e53
 func TestBoringServerCurves(t *testing.T) {
034e53
-	serverConfig := testConfig.Clone()
034e53
+	serverConfig := testConfigTemplate()
034e53
 	serverConfig.Certificates = make([]Certificate, 1)
034e53
 	serverConfig.Certificates[0].Certificate = [][]byte{testECDSACertificate}
034e53
 	serverConfig.Certificates[0].PrivateKey = testECDSAPrivateKey
8d5b6a
@@ -204,7 +204,7 @@ func TestBoringServerSignatureAndHash(t *testing.T) {
034e53
 
034e53
 	for _, sigHash := range defaultSupportedSignatureAlgorithms {
034e53
 		t.Run(fmt.Sprintf("%#x", sigHash), func(t *testing.T) {
034e53
-			serverConfig := testConfig.Clone()
034e53
+			serverConfig := testConfigTemplate()
034e53
 			serverConfig.Certificates = make([]Certificate, 1)
034e53
 
034e53
 			testingOnlyForceClientHelloSignatureAlgorithms = []SignatureScheme{sigHash}
8d5b6a
@@ -263,7 +263,7 @@ func TestBoringClientHello(t *testing.T) {
034e53
 	defer c.Close()
034e53
 	defer s.Close()
034e53
 
034e53
-	clientConfig := testConfig.Clone()
034e53
+	clientConfig := testConfigTemplate()
034e53
 	// All sorts of traps for the client to avoid.
034e53
 	clientConfig.MinVersion = VersionSSL30
034e53
 	clientConfig.MaxVersion = VersionTLS13
8d5b6a
@@ -337,12 +337,12 @@ func TestBoringCertAlgs(t *testing.T) {
034e53
 
034e53
 	// client verifying server cert
034e53
 	testServerCert := func(t *testing.T, desc string, pool *x509.CertPool, key interface{}, list [][]byte, ok bool) {
034e53
-		clientConfig := testConfig.Clone()
034e53
+		clientConfig := testConfigTemplate()
034e53
 		clientConfig.RootCAs = pool
034e53
 		clientConfig.InsecureSkipVerify = false
034e53
 		clientConfig.ServerName = "example.com"
034e53
 
034e53
-		serverConfig := testConfig.Clone()
034e53
+		serverConfig := testConfigTemplate()
034e53
 		serverConfig.Certificates = []Certificate{{Certificate: list, PrivateKey: key}}
034e53
 		serverConfig.BuildNameToCertificate()
034e53
 
8d5b6a
@@ -365,11 +365,11 @@ func TestBoringCertAlgs(t *testing.T) {
034e53
 
034e53
 	// server verifying client cert
034e53
 	testClientCert := func(t *testing.T, desc string, pool *x509.CertPool, key interface{}, list [][]byte, ok bool) {
034e53
-		clientConfig := testConfig.Clone()
034e53
+		clientConfig := testConfigTemplate()
034e53
 		clientConfig.ServerName = "example.com"
034e53
 		clientConfig.Certificates = []Certificate{{Certificate: list, PrivateKey: key}}
034e53
 
034e53
-		serverConfig := testConfig.Clone()
034e53
+		serverConfig := testConfigTemplate()
034e53
 		serverConfig.ClientCAs = pool
034e53
 		serverConfig.ClientAuth = RequireAndVerifyClientCert
034e53
 
8d5b6a
@@ -394,8 +394,13 @@ func TestBoringCertAlgs(t *testing.T) {
034e53
 	// exhaustive test with computed answers.
034e53
 	r1pool := x509.NewCertPool()
034e53
 	r1pool.AddCert(R1.cert)
034e53
-	testServerCert(t, "basic", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, true)
034e53
-	testClientCert(t, "basic (client cert)", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, true)
034e53
+	// openssl 3 FIPS provider fails these now without fipstls.Force()
034e53
+	shouldPass := true
034e53
+	if boring.Enabled() {
034e53
+		shouldPass = false
034e53
+	}
034e53
+	testClientCert(t, "basic (client cert)", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, shouldPass)
034e53
+	testClientCert(t, "basic (client cert)", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, shouldPass)
034e53
 	fipstls.Force()
034e53
 	testServerCert(t, "basic (fips)", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, false)
034e53
 	testClientCert(t, "basic (fips, client cert)", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, false)
8d5b6a
@@ -458,6 +463,10 @@ func TestBoringCertAlgs(t *testing.T) {
034e53
 				addRoot(r&1, R1)
034e53
 				addRoot(r&2, R2)
034e53
 				rootName = rootName[1:] // strip leading comma
034e53
+				// openssl 3 FIPS provider fails these now without fipstls.Force()
034e53
+				if boring.Enabled() {
034e53
+					shouldVerify = shouldVerifyFIPS
034e53
+				}
034e53
 				testServerCert(t, listName+"->"+rootName[1:], pool, leaf.key, list, shouldVerify)
034e53
 				testClientCert(t, listName+"->"+rootName[1:]+"(client cert)", pool, leaf.key, list, shouldVerify)
034e53
 				fipstls.Force()
8d5b6a
@@ -577,6 +586,16 @@ var (
034e53
 	testRSA2048PrivateKey  *rsa.PrivateKey
034e53
 )
034e53
 
034e53
+func testConfigTemplate() *Config {
034e53
+	config := testConfig.Clone()
034e53
+	if boring.Enabled() {
034e53
+		config.Certificates[0].Certificate = [][]byte{testRSA2048Certificate}
034e53
+		config.Certificates[0].PrivateKey = testRSA2048PrivateKey
034e53
+	}
034e53
+	return config
034e53
+
034e53
+}
034e53
+
034e53
 func init() {
034e53
 	block, _ := pem.Decode([]byte(`
034e53
 -----BEGIN CERTIFICATE-----
034e53
diff --git a/src/crypto/x509/x509_test.go b/src/crypto/x509/x509_test.go
e6cd3c
index 449379f..801a954 100644
034e53
--- a/src/crypto/x509/x509_test.go
034e53
+++ b/src/crypto/x509/x509_test.go
034e53
@@ -151,6 +151,7 @@ func TestPKIXMismatchPublicKeyFormat(t *testing.T) {
034e53
 }
034e53
 
034e53
 var testPrivateKey *rsa.PrivateKey
034e53
+var testPrivateKey2048 *rsa.PrivateKey
034e53
 
034e53
 func init() {
034e53
 	block, _ := pem.Decode([]byte(pemPrivateKey))
034e53
@@ -159,6 +160,9 @@ func init() {
034e53
 	if testPrivateKey, err = ParsePKCS1PrivateKey(block.Bytes); err != nil {
034e53
 		panic("Failed to parse private key: " + err.Error())
034e53
 	}
034e53
+	if testPrivateKey2048, err = rsa.GenerateKey(rand.Reader, 2048); err != nil {
034e53
+		panic("Failed to generate key: " + err.Error())
034e53
+	}
034e53
 }
034e53
 
034e53
 func bigFromString(s string) *big.Int {
034e53
@@ -589,8 +593,9 @@ func TestCreateSelfSignedCertificate(t *testing.T) {
034e53
 		{"RSA/ECDSA", &testPrivateKey.PublicKey, ecdsaPriv, false, ECDSAWithSHA384},
034e53
 		{"ECDSA/RSA", &ecdsaPriv.PublicKey, testPrivateKey, false, SHA256WithRSA},
034e53
 		{"ECDSA/ECDSA", &ecdsaPriv.PublicKey, ecdsaPriv, true, ECDSAWithSHA1},
034e53
-		{"RSAPSS/RSAPSS", &testPrivateKey.PublicKey, testPrivateKey, true, SHA256WithRSAPSS},
034e53
-		{"ECDSA/RSAPSS", &ecdsaPriv.PublicKey, testPrivateKey, false, SHA256WithRSAPSS},
034e53
+		// TODO: hardcode the next two keys
034e53
+		{"RSAPSS/RSAPSS", &testPrivateKey2048.PublicKey, testPrivateKey2048, true, SHA256WithRSAPSS},
034e53
+		{"ECDSA/RSAPSS", &ecdsaPriv.PublicKey, testPrivateKey2048, false, SHA256WithRSAPSS},
034e53
 		{"RSAPSS/ECDSA", &testPrivateKey.PublicKey, ecdsaPriv, false, ECDSAWithSHA384},
034e53
 		{"Ed25519", ed25519Pub, ed25519Priv, true, PureEd25519},
034e53
 	}