summaryrefslogtreecommitdiffstats
path: root/crypto/rsa
diff options
context:
space:
mode:
authorJuergen Christ <jchrist@linux.ibm.com>2023-01-20 17:43:59 +0100
committerTomas Mraz <tomas@openssl.org>2023-02-08 16:53:12 +0100
commit79040cf29e011c21789563d74da626b7465a0540 (patch)
treecf4db184af2d8fba461a64994a27635c41d1d51a /crypto/rsa
parentFix incomplete error check on BIO_set_md() (diff)
downloadopenssl-79040cf29e011c21789563d74da626b7465a0540.tar.xz
openssl-79040cf29e011c21789563d74da626b7465a0540.zip
S390x: Support ME and CRT offloading
S390x has to ability to offload modular exponentiation and CRT operations to Crypto Express Adapters. This possible performance optimization was not yet used by OpenSSL. Add support for offloading and implement an optimized version of RSA and DH with it. The environment variable OPENSSL_s390xcap now recognizes the token "nocex" to prevent offloading. Signed-off-by: Juergen Christ <jchrist@linux.ibm.com> Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20113)
Diffstat (limited to 'crypto/rsa')
-rw-r--r--crypto/rsa/rsa_ossl.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/crypto/rsa/rsa_ossl.c b/crypto/rsa/rsa_ossl.c
index 10d08ebc35..ec69076e63 100644
--- a/crypto/rsa/rsa_ossl.c
+++ b/crypto/rsa/rsa_ossl.c
@@ -33,6 +33,27 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa,
BN_CTX *ctx);
static int rsa_ossl_init(RSA *rsa);
static int rsa_ossl_finish(RSA *rsa);
+#ifdef S390X_MOD_EXP
+static int rsa_ossl_s390x_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa,
+ BN_CTX *ctx);
+static RSA_METHOD rsa_pkcs1_ossl_meth = {
+ "OpenSSL PKCS#1 RSA",
+ rsa_ossl_public_encrypt,
+ rsa_ossl_public_decrypt, /* signature verification */
+ rsa_ossl_private_encrypt, /* signing */
+ rsa_ossl_private_decrypt,
+ rsa_ossl_s390x_mod_exp,
+ s390x_mod_exp,
+ rsa_ossl_init,
+ rsa_ossl_finish,
+ RSA_FLAG_FIPS_METHOD, /* flags */
+ NULL,
+ 0, /* rsa_sign */
+ 0, /* rsa_verify */
+ NULL, /* rsa_keygen */
+ NULL /* rsa_multi_prime_keygen */
+};
+#else
static RSA_METHOD rsa_pkcs1_ossl_meth = {
"OpenSSL PKCS#1 RSA",
rsa_ossl_public_encrypt,
@@ -51,6 +72,7 @@ static RSA_METHOD rsa_pkcs1_ossl_meth = {
NULL, /* rsa_keygen */
NULL /* rsa_multi_prime_keygen */
};
+#endif
static const RSA_METHOD *default_RSA_meth = &rsa_pkcs1_ossl_meth;
@@ -1118,3 +1140,16 @@ static int rsa_ossl_finish(RSA *rsa)
BN_MONT_CTX_free(rsa->_method_mod_q);
return 1;
}
+
+#ifdef S390X_MOD_EXP
+static int rsa_ossl_s390x_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa,
+ BN_CTX *ctx)
+{
+ if (rsa->version != RSA_ASN1_VERSION_MULTI) {
+ if (s390x_crt(r0, i, rsa->p, rsa->q, rsa->dmp1, rsa->dmq1, rsa->iqmp) == 1)
+ return 1;
+ }
+ return rsa_ossl_mod_exp(r0, i, rsa, ctx);
+}
+
+#endif