|
|
3a273b |
diff -up openssl-1.1.1c/Configurations/00-base-templates.conf.s390x-ecc openssl-1.1.1c/Configurations/00-base-templates.conf
|
|
|
3a273b |
--- openssl-1.1.1c/Configurations/00-base-templates.conf.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/Configurations/00-base-templates.conf 2019-11-20 11:36:02.190860451 +0100
|
|
|
3a273b |
@@ -289,6 +289,7 @@ my %targets=(
|
|
|
3a273b |
template => 1,
|
|
|
3a273b |
cpuid_asm_src => "s390xcap.c s390xcpuid.S",
|
|
|
3a273b |
bn_asm_src => "asm/s390x.S s390x-mont.S s390x-gf2m.s",
|
|
|
3a273b |
+ ec_asm_src => "ecp_s390x_nistp.c",
|
|
|
3a273b |
aes_asm_src => "aes-s390x.S aes-ctr.fake aes-xts.fake",
|
|
|
3a273b |
sha1_asm_src => "sha1-s390x.S sha256-s390x.S sha512-s390x.S",
|
|
|
3a273b |
rc4_asm_src => "rc4-s390x.s",
|
|
|
3a273b |
diff -up openssl-1.1.1c/Configure.s390x-ecc openssl-1.1.1c/Configure
|
|
|
3a273b |
--- openssl-1.1.1c/Configure.s390x-ecc 2019-11-20 11:36:02.078862415 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/Configure 2019-11-20 11:36:02.191860433 +0100
|
|
|
3a273b |
@@ -1410,6 +1410,9 @@ unless ($disabled{asm}) {
|
|
|
3a273b |
if ($target{ec_asm_src} =~ /ecp_nistz256/) {
|
|
|
3a273b |
push @{$config{lib_defines}}, "ECP_NISTZ256_ASM";
|
|
|
3a273b |
}
|
|
|
3a273b |
+ if ($target{ec_asm_src} =~ /ecp_s390x_nistp/) {
|
|
|
3a273b |
+ push @{$config{lib_defines}}, "S390X_EC_ASM";
|
|
|
3a273b |
+ }
|
|
|
3a273b |
if ($target{ec_asm_src} =~ /x25519/) {
|
|
|
3a273b |
push @{$config{lib_defines}}, "X25519_ASM";
|
|
|
3a273b |
}
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/bn/asm/s390x.S.s390x-ecc openssl-1.1.1c/crypto/bn/asm/s390x.S
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/bn/asm/s390x.S.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/bn/asm/s390x.S 2019-11-20 11:36:02.191860433 +0100
|
|
|
3a273b |
@@ -511,7 +511,7 @@ bn_mul_comba4:
|
|
|
3a273b |
lghi zero,0
|
|
|
3a273b |
|
|
|
3a273b |
mul_add_c(0,0,c1,c2,c3);
|
|
|
3a273b |
- stg c1,0*8(%r3)
|
|
|
3a273b |
+ stg c1,0*8(%r2)
|
|
|
3a273b |
lghi c1,0
|
|
|
3a273b |
|
|
|
3a273b |
mul_add_c(0,1,c2,c3,c1);
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/cmac/cm_pmeth.c.s390x-ecc openssl-1.1.1c/crypto/cmac/cm_pmeth.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/cmac/cm_pmeth.c.s390x-ecc 2019-11-20 11:36:02.078862415 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/cmac/cm_pmeth.c 2019-11-20 11:36:02.191860433 +0100
|
|
|
3a273b |
@@ -159,3 +159,8 @@ const EVP_PKEY_METHOD cmac_pkey_meth = {
|
|
|
3a273b |
pkey_cmac_ctrl,
|
|
|
3a273b |
pkey_cmac_ctrl_str
|
|
|
3a273b |
};
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *cmac_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &cmac_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/dh/dh_pmeth.c.s390x-ecc openssl-1.1.1c/crypto/dh/dh_pmeth.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/dh/dh_pmeth.c.s390x-ecc 2019-11-20 11:36:02.079862397 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/dh/dh_pmeth.c 2019-11-20 11:36:02.191860433 +0100
|
|
|
3a273b |
@@ -512,6 +512,11 @@ const EVP_PKEY_METHOD dh_pkey_meth = {
|
|
|
3a273b |
pkey_dh_ctrl_str
|
|
|
3a273b |
};
|
|
|
3a273b |
|
|
|
3a273b |
+const EVP_PKEY_METHOD *dh_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &dh_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
const EVP_PKEY_METHOD dhx_pkey_meth = {
|
|
|
3a273b |
EVP_PKEY_DHX,
|
|
|
3a273b |
EVP_PKEY_FLAG_FIPS,
|
|
|
3a273b |
@@ -545,3 +550,8 @@ const EVP_PKEY_METHOD dhx_pkey_meth = {
|
|
|
3a273b |
pkey_dh_ctrl,
|
|
|
3a273b |
pkey_dh_ctrl_str
|
|
|
3a273b |
};
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *dhx_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &dhx_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/dsa/dsa_pmeth.c.s390x-ecc openssl-1.1.1c/crypto/dsa/dsa_pmeth.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/dsa/dsa_pmeth.c.s390x-ecc 2019-11-20 11:36:02.100862029 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/dsa/dsa_pmeth.c 2019-11-20 11:36:02.191860433 +0100
|
|
|
3a273b |
@@ -275,3 +275,8 @@ const EVP_PKEY_METHOD dsa_pkey_meth = {
|
|
|
3a273b |
pkey_dsa_ctrl,
|
|
|
3a273b |
pkey_dsa_ctrl_str
|
|
|
3a273b |
};
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *dsa_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &dsa_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/build.info.s390x-ecc openssl-1.1.1c/crypto/ec/build.info
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/build.info.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/build.info 2019-11-20 11:36:02.192860416 +0100
|
|
|
3a273b |
@@ -26,6 +26,9 @@ GENERATE[ecp_nistz256-armv8.S]=asm/ecp_n
|
|
|
3a273b |
INCLUDE[ecp_nistz256-armv8.o]=..
|
|
|
3a273b |
GENERATE[ecp_nistz256-ppc64.s]=asm/ecp_nistz256-ppc64.pl $(PERLASM_SCHEME)
|
|
|
3a273b |
|
|
|
3a273b |
+INCLUDE[ecp_s390x_nistp.o]=..
|
|
|
3a273b |
+INCLUDE[ecx_meth.o]=..
|
|
|
3a273b |
+
|
|
|
3a273b |
GENERATE[x25519-x86_64.s]=asm/x25519-x86_64.pl $(PERLASM_SCHEME)
|
|
|
3a273b |
GENERATE[x25519-ppc64.s]=asm/x25519-ppc64.pl $(PERLASM_SCHEME)
|
|
|
3a273b |
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ec_curve.c.s390x-ecc openssl-1.1.1c/crypto/ec/ec_curve.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ec_curve.c.s390x-ecc 2019-11-20 11:36:02.043863029 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ec_curve.c 2019-11-20 11:36:02.192860416 +0100
|
|
|
3a273b |
@@ -255,20 +255,29 @@ static const ec_list_element curve_list[
|
|
|
3a273b |
{NID_secp256k1, &_EC_SECG_PRIME_256K1.h, 0,
|
|
|
3a273b |
"SECG curve over a 256 bit prime field"},
|
|
|
3a273b |
/* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */
|
|
|
3a273b |
- {NID_secp384r1, &_EC_NIST_PRIME_384.h, 0,
|
|
|
3a273b |
+ {NID_secp384r1, &_EC_NIST_PRIME_384.h,
|
|
|
3a273b |
+# if defined(S390X_EC_ASM)
|
|
|
3a273b |
+ EC_GFp_s390x_nistp384_method,
|
|
|
3a273b |
+# else
|
|
|
3a273b |
+ 0,
|
|
|
3a273b |
+# endif
|
|
|
3a273b |
"NIST/SECG curve over a 384 bit prime field"},
|
|
|
3a273b |
-#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
|
|
|
3a273b |
- {NID_secp521r1, &_EC_NIST_PRIME_521.h, EC_GFp_nistp521_method,
|
|
|
3a273b |
- "NIST/SECG curve over a 521 bit prime field"},
|
|
|
3a273b |
-#else
|
|
|
3a273b |
- {NID_secp521r1, &_EC_NIST_PRIME_521.h, 0,
|
|
|
3a273b |
+ {NID_secp521r1, &_EC_NIST_PRIME_521.h,
|
|
|
3a273b |
+# if defined(S390X_EC_ASM)
|
|
|
3a273b |
+ EC_GFp_s390x_nistp521_method,
|
|
|
3a273b |
+# elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
|
|
|
3a273b |
+ EC_GFp_nistp521_method,
|
|
|
3a273b |
+# else
|
|
|
3a273b |
+ 0,
|
|
|
3a273b |
+# endif
|
|
|
3a273b |
"NIST/SECG curve over a 521 bit prime field"},
|
|
|
3a273b |
-#endif
|
|
|
3a273b |
/* X9.62 curves */
|
|
|
3a273b |
{NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,
|
|
|
3a273b |
#if defined(ECP_NISTZ256_ASM)
|
|
|
3a273b |
EC_GFp_nistz256_method,
|
|
|
3a273b |
-#elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
|
|
|
3a273b |
+# elif defined(S390X_EC_ASM)
|
|
|
3a273b |
+ EC_GFp_s390x_nistp256_method,
|
|
|
3a273b |
+# elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
|
|
|
3a273b |
EC_GFp_nistp256_method,
|
|
|
3a273b |
#else
|
|
|
3a273b |
0,
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ecdsa_ossl.c.s390x-ecc openssl-1.1.1c/crypto/ec/ecdsa_ossl.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ecdsa_ossl.c.s390x-ecc 2019-11-20 11:36:02.100862029 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ecdsa_ossl.c 2019-11-20 11:36:02.192860416 +0100
|
|
|
3a273b |
@@ -18,6 +18,41 @@
|
|
|
3a273b |
# include <openssl/fips.h>
|
|
|
3a273b |
#endif
|
|
|
3a273b |
|
|
|
3a273b |
+int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
|
|
|
3a273b |
+ BIGNUM **rp)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ if (eckey->group->meth->ecdsa_sign_setup == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_OSSL_ECDSA_SIGN_SETUP, EC_R_CURVE_DOES_NOT_SUPPORT_ECDSA);
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ return eckey->group->meth->ecdsa_sign_setup(eckey, ctx_in, kinvp, rp);
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len,
|
|
|
3a273b |
+ const BIGNUM *in_kinv, const BIGNUM *in_r,
|
|
|
3a273b |
+ EC_KEY *eckey)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ if (eckey->group->meth->ecdsa_sign_sig == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, EC_R_CURVE_DOES_NOT_SUPPORT_ECDSA);
|
|
|
3a273b |
+ return NULL;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ return eckey->group->meth->ecdsa_sign_sig(dgst, dgst_len,
|
|
|
3a273b |
+ in_kinv, in_r, eckey);
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,
|
|
|
3a273b |
+ const ECDSA_SIG *sig, EC_KEY *eckey)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ if (eckey->group->meth->ecdsa_verify_sig == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_CURVE_DOES_NOT_SUPPORT_ECDSA);
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ return eckey->group->meth->ecdsa_verify_sig(dgst, dgst_len, sig, eckey);
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
int ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen,
|
|
|
3a273b |
unsigned char *sig, unsigned int *siglen,
|
|
|
3a273b |
const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey)
|
|
|
3a273b |
@@ -145,15 +180,15 @@ static int ecdsa_sign_setup(EC_KEY *ecke
|
|
|
3a273b |
return ret;
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
-int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
|
|
|
3a273b |
- BIGNUM **rp)
|
|
|
3a273b |
+int ecdsa_simple_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
|
|
|
3a273b |
+ BIGNUM **rp)
|
|
|
3a273b |
{
|
|
|
3a273b |
return ecdsa_sign_setup(eckey, ctx_in, kinvp, rp, NULL, 0);
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
-ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len,
|
|
|
3a273b |
- const BIGNUM *in_kinv, const BIGNUM *in_r,
|
|
|
3a273b |
- EC_KEY *eckey)
|
|
|
3a273b |
+ECDSA_SIG *ecdsa_simple_sign_sig(const unsigned char *dgst, int dgst_len,
|
|
|
3a273b |
+ const BIGNUM *in_kinv, const BIGNUM *in_r,
|
|
|
3a273b |
+ EC_KEY *eckey)
|
|
|
3a273b |
{
|
|
|
3a273b |
int ok = 0, i;
|
|
|
3a273b |
BIGNUM *kinv = NULL, *s, *m = NULL;
|
|
|
3a273b |
@@ -210,25 +245,25 @@ ECDSA_SIG *ossl_ecdsa_sign_sig(const uns
|
|
|
3a273b |
if (8 * dgst_len > i)
|
|
|
3a273b |
dgst_len = (i + 7) / 8;
|
|
|
3a273b |
if (!BN_bin2bn(dgst, dgst_len, m)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
/* If still too long, truncate remaining bits with a shift */
|
|
|
3a273b |
if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
do {
|
|
|
3a273b |
if (in_kinv == NULL || in_r == NULL) {
|
|
|
3a273b |
if (!ecdsa_sign_setup(eckey, ctx, &kinv, &ret->r, dgst, dgst_len)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_ECDSA_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_SIGN_SIG, ERR_R_ECDSA_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
ckinv = kinv;
|
|
|
3a273b |
} else {
|
|
|
3a273b |
ckinv = in_kinv;
|
|
|
3a273b |
if (BN_copy(ret->r, in_r) == NULL) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_SIGN_SIG, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
}
|
|
|
3a273b |
@@ -242,11 +277,11 @@ ECDSA_SIG *ossl_ecdsa_sign_sig(const uns
|
|
|
3a273b |
*/
|
|
|
3a273b |
if (!bn_to_mont_fixed_top(s, ret->r, group->mont_data, ctx)
|
|
|
3a273b |
|| !bn_mul_mont_fixed_top(s, s, priv_key, group->mont_data, ctx)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
if (!bn_mod_add_fixed_top(s, s, m, order)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
/*
|
|
|
3a273b |
@@ -255,7 +290,7 @@ ECDSA_SIG *ossl_ecdsa_sign_sig(const uns
|
|
|
3a273b |
*/
|
|
|
3a273b |
if (!bn_to_mont_fixed_top(s, s, group->mont_data, ctx)
|
|
|
3a273b |
|| !BN_mod_mul_montgomery(s, s, ckinv, group->mont_data, ctx)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
@@ -265,7 +300,7 @@ ECDSA_SIG *ossl_ecdsa_sign_sig(const uns
|
|
|
3a273b |
* generate new kinv and r values
|
|
|
3a273b |
*/
|
|
|
3a273b |
if (in_kinv != NULL && in_r != NULL) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, EC_R_NEED_NEW_SETUP_VALUES);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_SIGN_SIG, EC_R_NEED_NEW_SETUP_VALUES);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
} else {
|
|
|
3a273b |
@@ -317,8 +352,8 @@ int ossl_ecdsa_verify(int type, const un
|
|
|
3a273b |
return ret;
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
-int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,
|
|
|
3a273b |
- const ECDSA_SIG *sig, EC_KEY *eckey)
|
|
|
3a273b |
+int ecdsa_simple_verify_sig(const unsigned char *dgst, int dgst_len,
|
|
|
3a273b |
+ const ECDSA_SIG *sig, EC_KEY *eckey)
|
|
|
3a273b |
{
|
|
|
3a273b |
int ret = -1, i;
|
|
|
3a273b |
BN_CTX *ctx;
|
|
|
3a273b |
@@ -338,18 +373,18 @@ int ossl_ecdsa_verify_sig(const unsigned
|
|
|
3a273b |
/* check input values */
|
|
|
3a273b |
if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL ||
|
|
|
3a273b |
(pub_key = EC_KEY_get0_public_key(eckey)) == NULL || sig == NULL) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_MISSING_PARAMETERS);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, EC_R_MISSING_PARAMETERS);
|
|
|
3a273b |
return -1;
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
if (!EC_KEY_can_sign(eckey)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);
|
|
|
3a273b |
return -1;
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
ctx = BN_CTX_new();
|
|
|
3a273b |
if (ctx == NULL) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
return -1;
|
|
|
3a273b |
}
|
|
|
3a273b |
BN_CTX_start(ctx);
|
|
|
3a273b |
@@ -358,26 +393,26 @@ int ossl_ecdsa_verify_sig(const unsigned
|
|
|
3a273b |
m = BN_CTX_get(ctx);
|
|
|
3a273b |
X = BN_CTX_get(ctx);
|
|
|
3a273b |
if (X == NULL) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
order = EC_GROUP_get0_order(group);
|
|
|
3a273b |
if (order == NULL) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_EC_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
if (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||
|
|
|
3a273b |
BN_ucmp(sig->r, order) >= 0 || BN_is_zero(sig->s) ||
|
|
|
3a273b |
BN_is_negative(sig->s) || BN_ucmp(sig->s, order) >= 0) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_BAD_SIGNATURE);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, EC_R_BAD_SIGNATURE);
|
|
|
3a273b |
ret = 0; /* signature is invalid */
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
/* calculate tmp1 = inv(S) mod order */
|
|
|
3a273b |
if (!ec_group_do_inverse_ord(group, u2, sig->s, ctx)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
/* digest -> m */
|
|
|
3a273b |
@@ -388,41 +423,41 @@ int ossl_ecdsa_verify_sig(const unsigned
|
|
|
3a273b |
if (8 * dgst_len > i)
|
|
|
3a273b |
dgst_len = (i + 7) / 8;
|
|
|
3a273b |
if (!BN_bin2bn(dgst, dgst_len, m)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
/* If still too long truncate remaining bits with a shift */
|
|
|
3a273b |
if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
/* u1 = m * tmp mod order */
|
|
|
3a273b |
if (!BN_mod_mul(u1, m, u2, order, ctx)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
/* u2 = r * w mod q */
|
|
|
3a273b |
if (!BN_mod_mul(u2, sig->r, u2, order, ctx)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
if ((point = EC_POINT_new(group)) == NULL) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
if (!EC_POINT_mul(group, point, u1, pub_key, u2, ctx)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_EC_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
if (!EC_POINT_get_affine_coordinates(group, point, X, NULL, ctx)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_EC_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
if (!BN_nnmod(u1, X, order, ctx)) {
|
|
|
3a273b |
- ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_SIMPLE_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
goto err;
|
|
|
3a273b |
}
|
|
|
3a273b |
/* if the signature is correct u1 is equal to sig->r */
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ec_err.c.s390x-ecc openssl-1.1.1c/crypto/ec/ec_err.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ec_err.c.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ec_err.c 2019-11-20 11:36:02.192860416 +0100
|
|
|
3a273b |
@@ -31,6 +31,11 @@ static const ERR_STRING_DATA EC_str_func
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_ECDSA_SIGN_SETUP, 0), "ECDSA_sign_setup"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_ECDSA_SIG_NEW, 0), "ECDSA_SIG_new"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_ECDSA_VERIFY, 0), "ECDSA_verify"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_ECDSA_SIMPLE_SIGN_SETUP, 0), "ecdsa_simple_sign_setup"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_ECDSA_SIMPLE_SIGN_SIG, 0), "ecdsa_simple_sign_sig"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_ECDSA_SIMPLE_VERIFY_SIG, 0), "ecdsa_simple_verify_sig"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_ECDSA_S390X_NISTP_SIGN_SIG, 0), "ecdsa_s390x_nistp_sign_sig"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_ECDSA_S390X_NISTP_VERIFY_SIG, 0), "ecdsa_s390x_nistp_verify_sig"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_ECD_ITEM_VERIFY, 0), "ecd_item_verify"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_ECKEY_PARAM2TYPE, 0), "eckey_param2type"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_ECKEY_PARAM_DECODE, 0), "eckey_param_decode"},
|
|
|
3a273b |
@@ -266,6 +271,7 @@ static const ERR_STRING_DATA EC_str_func
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_OLD_EC_PRIV_DECODE, 0), "old_ec_priv_decode"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_OSSL_ECDH_COMPUTE_KEY, 0),
|
|
|
3a273b |
"ossl_ecdh_compute_key"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_OSSL_ECDSA_SIGN_SETUP, 0), "ossl_ecdsa_sign_setup"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_OSSL_ECDSA_SIGN_SIG, 0), "ossl_ecdsa_sign_sig"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_OSSL_ECDSA_VERIFY_SIG, 0),
|
|
|
3a273b |
"ossl_ecdsa_verify_sig"},
|
|
|
3a273b |
@@ -284,6 +290,12 @@ static const ERR_STRING_DATA EC_str_func
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_PKEY_EC_KEYGEN, 0), "pkey_ec_keygen"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_PKEY_EC_PARAMGEN, 0), "pkey_ec_paramgen"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_PKEY_EC_SIGN, 0), "pkey_ec_sign"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_S390X_PKEY_ECD_DIGESTSIGN25519, 0), "s390x_pkey_ecd_digestsign25519"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_S390X_PKEY_ECD_DIGESTSIGN448, 0), "s390x_pkey_ecd_digestsign448"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_S390X_PKEY_ECD_KEYGEN25519, 0), "s390x_pkey_ecd_keygen25519"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_S390X_PKEY_ECD_KEYGEN448, 0), "s390x_pkey_ecd_keygen448"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_S390X_PKEY_ECX_KEYGEN25519, 0), "s390x_pkey_ecx_keygen25519"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, EC_F_S390X_PKEY_ECX_KEYGEN448, 0), "s390x_pkey_ecx_keygen448"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, EC_F_VALIDATE_ECX_DERIVE, 0), "validate_ecx_derive"},
|
|
|
3a273b |
{0, NULL}
|
|
|
3a273b |
};
|
|
|
3a273b |
@@ -298,6 +310,8 @@ static const ERR_STRING_DATA EC_str_reas
|
|
|
3a273b |
"coordinates out of range"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, 0, EC_R_CURVE_DOES_NOT_SUPPORT_ECDH),
|
|
|
3a273b |
"curve does not support ecdh"},
|
|
|
3a273b |
+ {ERR_PACK(ERR_LIB_EC, 0, EC_R_CURVE_DOES_NOT_SUPPORT_ECDSA),
|
|
|
3a273b |
+ "curve does not support ecdsa"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, 0, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING),
|
|
|
3a273b |
"curve does not support signing"},
|
|
|
3a273b |
{ERR_PACK(ERR_LIB_EC, 0, EC_R_D2I_ECPKPARAMETERS_FAILURE),
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ec_lcl.h.s390x-ecc openssl-1.1.1c/crypto/ec/ec_lcl.h
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ec_lcl.h.s390x-ecc 2019-11-20 11:36:01.676869466 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ec_lcl.h 2019-11-20 11:36:02.192860416 +0100
|
|
|
3a273b |
@@ -154,7 +154,7 @@ struct ec_method_st {
|
|
|
3a273b |
int (*field_div) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
|
|
|
3a273b |
const BIGNUM *b, BN_CTX *);
|
|
|
3a273b |
/*-
|
|
|
3a273b |
- * 'field_inv' computes the multipicative inverse of a in the field,
|
|
|
3a273b |
+ * 'field_inv' computes the multiplicative inverse of a in the field,
|
|
|
3a273b |
* storing the result in r.
|
|
|
3a273b |
*
|
|
|
3a273b |
* If 'a' is zero (or equivalent), you'll get an EC_R_CANNOT_INVERT error.
|
|
|
3a273b |
@@ -179,6 +179,14 @@ struct ec_method_st {
|
|
|
3a273b |
/* custom ECDH operation */
|
|
|
3a273b |
int (*ecdh_compute_key)(unsigned char **pout, size_t *poutlen,
|
|
|
3a273b |
const EC_POINT *pub_key, const EC_KEY *ecdh);
|
|
|
3a273b |
+ /* custom ECDSA */
|
|
|
3a273b |
+ int (*ecdsa_sign_setup)(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinvp,
|
|
|
3a273b |
+ BIGNUM **rp);
|
|
|
3a273b |
+ ECDSA_SIG *(*ecdsa_sign_sig)(const unsigned char *dgst, int dgstlen,
|
|
|
3a273b |
+ const BIGNUM *kinv, const BIGNUM *r,
|
|
|
3a273b |
+ EC_KEY *eckey);
|
|
|
3a273b |
+ int (*ecdsa_verify_sig)(const unsigned char *dgst, int dgstlen,
|
|
|
3a273b |
+ const ECDSA_SIG *sig, EC_KEY *eckey);
|
|
|
3a273b |
/* Inverse modulo order */
|
|
|
3a273b |
int (*field_inverse_mod_ord)(const EC_GROUP *, BIGNUM *r,
|
|
|
3a273b |
const BIGNUM *x, BN_CTX *);
|
|
|
3a273b |
@@ -587,6 +595,11 @@ int ec_group_simple_order_bits(const EC_
|
|
|
3a273b |
*/
|
|
|
3a273b |
const EC_METHOD *EC_GFp_nistz256_method(void);
|
|
|
3a273b |
#endif
|
|
|
3a273b |
+#ifdef S390X_EC_ASM
|
|
|
3a273b |
+const EC_METHOD *EC_GFp_s390x_nistp256_method(void);
|
|
|
3a273b |
+const EC_METHOD *EC_GFp_s390x_nistp384_method(void);
|
|
|
3a273b |
+const EC_METHOD *EC_GFp_s390x_nistp521_method(void);
|
|
|
3a273b |
+#endif
|
|
|
3a273b |
|
|
|
3a273b |
size_t ec_key_simple_priv2oct(const EC_KEY *eckey,
|
|
|
3a273b |
unsigned char *buf, size_t len);
|
|
|
3a273b |
@@ -649,6 +662,13 @@ int ossl_ecdsa_verify(int type, const un
|
|
|
3a273b |
const unsigned char *sigbuf, int sig_len, EC_KEY *eckey);
|
|
|
3a273b |
int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,
|
|
|
3a273b |
const ECDSA_SIG *sig, EC_KEY *eckey);
|
|
|
3a273b |
+int ecdsa_simple_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
|
|
|
3a273b |
+ BIGNUM **rp);
|
|
|
3a273b |
+ECDSA_SIG *ecdsa_simple_sign_sig(const unsigned char *dgst, int dgst_len,
|
|
|
3a273b |
+ const BIGNUM *in_kinv, const BIGNUM *in_r,
|
|
|
3a273b |
+ EC_KEY *eckey);
|
|
|
3a273b |
+int ecdsa_simple_verify_sig(const unsigned char *dgst, int dgst_len,
|
|
|
3a273b |
+ const ECDSA_SIG *sig, EC_KEY *eckey);
|
|
|
3a273b |
|
|
|
3a273b |
int ED25519_sign(uint8_t *out_sig, const uint8_t *message, size_t message_len,
|
|
|
3a273b |
const uint8_t public_key[32], const uint8_t private_key[32]);
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ec_pmeth.c.s390x-ecc openssl-1.1.1c/crypto/ec/ec_pmeth.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ec_pmeth.c.s390x-ecc 2019-11-20 11:36:02.101862012 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ec_pmeth.c 2019-11-20 11:36:02.193860398 +0100
|
|
|
3a273b |
@@ -474,3 +474,8 @@ const EVP_PKEY_METHOD ec_pkey_meth = {
|
|
|
3a273b |
pkey_ec_ctrl,
|
|
|
3a273b |
pkey_ec_ctrl_str
|
|
|
3a273b |
};
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *ec_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &ec_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ecp_mont.c.s390x-ecc openssl-1.1.1c/crypto/ec/ecp_mont.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ecp_mont.c.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ecp_mont.c 2019-11-20 11:36:02.193860398 +0100
|
|
|
3a273b |
@@ -63,6 +63,9 @@ const EC_METHOD *EC_GFp_mont_method(void
|
|
|
3a273b |
0, /* keycopy */
|
|
|
3a273b |
0, /* keyfinish */
|
|
|
3a273b |
ecdh_simple_compute_key,
|
|
|
3a273b |
+ ecdsa_simple_sign_setup,
|
|
|
3a273b |
+ ecdsa_simple_sign_sig,
|
|
|
3a273b |
+ ecdsa_simple_verify_sig,
|
|
|
3a273b |
0, /* field_inverse_mod_ord */
|
|
|
3a273b |
ec_GFp_simple_blind_coordinates,
|
|
|
3a273b |
ec_GFp_simple_ladder_pre,
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ecp_nist.c.s390x-ecc openssl-1.1.1c/crypto/ec/ecp_nist.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ecp_nist.c.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ecp_nist.c 2019-11-20 11:36:02.193860398 +0100
|
|
|
3a273b |
@@ -65,6 +65,9 @@ const EC_METHOD *EC_GFp_nist_method(void
|
|
|
3a273b |
0, /* keycopy */
|
|
|
3a273b |
0, /* keyfinish */
|
|
|
3a273b |
ecdh_simple_compute_key,
|
|
|
3a273b |
+ ecdsa_simple_sign_setup,
|
|
|
3a273b |
+ ecdsa_simple_sign_sig,
|
|
|
3a273b |
+ ecdsa_simple_verify_sig,
|
|
|
3a273b |
0, /* field_inverse_mod_ord */
|
|
|
3a273b |
ec_GFp_simple_blind_coordinates,
|
|
|
3a273b |
ec_GFp_simple_ladder_pre,
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ecp_nistp224.c.s390x-ecc openssl-1.1.1c/crypto/ec/ecp_nistp224.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ecp_nistp224.c.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ecp_nistp224.c 2019-11-20 11:36:02.193860398 +0100
|
|
|
3a273b |
@@ -292,6 +292,9 @@ const EC_METHOD *EC_GFp_nistp224_method(
|
|
|
3a273b |
0, /* keycopy */
|
|
|
3a273b |
0, /* keyfinish */
|
|
|
3a273b |
ecdh_simple_compute_key,
|
|
|
3a273b |
+ ecdsa_simple_sign_setup,
|
|
|
3a273b |
+ ecdsa_simple_sign_sig,
|
|
|
3a273b |
+ ecdsa_simple_verify_sig,
|
|
|
3a273b |
0, /* field_inverse_mod_ord */
|
|
|
3a273b |
0, /* blind_coordinates */
|
|
|
3a273b |
0, /* ladder_pre */
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ecp_nistp256.c.s390x-ecc openssl-1.1.1c/crypto/ec/ecp_nistp256.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ecp_nistp256.c.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ecp_nistp256.c 2019-11-20 11:36:02.194860380 +0100
|
|
|
3a273b |
@@ -1823,6 +1823,9 @@ const EC_METHOD *EC_GFp_nistp256_method(
|
|
|
3a273b |
0, /* keycopy */
|
|
|
3a273b |
0, /* keyfinish */
|
|
|
3a273b |
ecdh_simple_compute_key,
|
|
|
3a273b |
+ ecdsa_simple_sign_setup,
|
|
|
3a273b |
+ ecdsa_simple_sign_sig,
|
|
|
3a273b |
+ ecdsa_simple_verify_sig,
|
|
|
3a273b |
0, /* field_inverse_mod_ord */
|
|
|
3a273b |
0, /* blind_coordinates */
|
|
|
3a273b |
0, /* ladder_pre */
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ecp_nistp521.c.s390x-ecc openssl-1.1.1c/crypto/ec/ecp_nistp521.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ecp_nistp521.c.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ecp_nistp521.c 2019-11-20 11:36:02.194860380 +0100
|
|
|
3a273b |
@@ -1665,6 +1665,9 @@ const EC_METHOD *EC_GFp_nistp521_method(
|
|
|
3a273b |
0, /* keycopy */
|
|
|
3a273b |
0, /* keyfinish */
|
|
|
3a273b |
ecdh_simple_compute_key,
|
|
|
3a273b |
+ ecdsa_simple_sign_setup,
|
|
|
3a273b |
+ ecdsa_simple_sign_sig,
|
|
|
3a273b |
+ ecdsa_simple_verify_sig,
|
|
|
3a273b |
0, /* field_inverse_mod_ord */
|
|
|
3a273b |
0, /* blind_coordinates */
|
|
|
3a273b |
0, /* ladder_pre */
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ecp_nistz256.c.s390x-ecc openssl-1.1.1c/crypto/ec/ecp_nistz256.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ecp_nistz256.c.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ecp_nistz256.c 2019-11-20 11:36:02.195860363 +0100
|
|
|
3a273b |
@@ -1689,6 +1689,9 @@ const EC_METHOD *EC_GFp_nistz256_method(
|
|
|
3a273b |
0, /* keycopy */
|
|
|
3a273b |
0, /* keyfinish */
|
|
|
3a273b |
ecdh_simple_compute_key,
|
|
|
3a273b |
+ ecdsa_simple_sign_setup,
|
|
|
3a273b |
+ ecdsa_simple_sign_sig,
|
|
|
3a273b |
+ ecdsa_simple_verify_sig,
|
|
|
3a273b |
ecp_nistz256_inv_mod_ord, /* can be #define-d NULL */
|
|
|
3a273b |
0, /* blind_coordinates */
|
|
|
3a273b |
0, /* ladder_pre */
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ecp_s390x_nistp.c.s390x-ecc openssl-1.1.1c/crypto/ec/ecp_s390x_nistp.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ecp_s390x_nistp.c.s390x-ecc 2019-11-20 11:36:02.195860363 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ecp_s390x_nistp.c 2019-11-20 11:36:02.195860363 +0100
|
|
|
3a273b |
@@ -0,0 +1,394 @@
|
|
|
3a273b |
+/*
|
|
|
3a273b |
+ * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
|
|
3a273b |
+ *
|
|
|
3a273b |
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
3a273b |
+ * this file except in compliance with the License. You can obtain a copy
|
|
|
3a273b |
+ * in the file LICENSE in the source distribution or at
|
|
|
3a273b |
+ * https://www.openssl.org/source/license.html
|
|
|
3a273b |
+ */
|
|
|
3a273b |
+
|
|
|
3a273b |
+#include <stdlib.h>
|
|
|
3a273b |
+#include <string.h>
|
|
|
3a273b |
+#include <openssl/err.h>
|
|
|
3a273b |
+#include <openssl/rand.h>
|
|
|
3a273b |
+#include "ec_lcl.h"
|
|
|
3a273b |
+#include "s390x_arch.h"
|
|
|
3a273b |
+
|
|
|
3a273b |
+/* Size of parameter blocks */
|
|
|
3a273b |
+#define S390X_SIZE_PARAM 4096
|
|
|
3a273b |
+
|
|
|
3a273b |
+/* Size of fields in parameter blocks */
|
|
|
3a273b |
+#define S390X_SIZE_P256 32
|
|
|
3a273b |
+#define S390X_SIZE_P384 48
|
|
|
3a273b |
+#define S390X_SIZE_P521 80
|
|
|
3a273b |
+
|
|
|
3a273b |
+/* Offsets of fields in PCC parameter blocks */
|
|
|
3a273b |
+#define S390X_OFF_RES_X(n) (0 * n)
|
|
|
3a273b |
+#define S390X_OFF_RES_Y(n) (1 * n)
|
|
|
3a273b |
+#define S390X_OFF_SRC_X(n) (2 * n)
|
|
|
3a273b |
+#define S390X_OFF_SRC_Y(n) (3 * n)
|
|
|
3a273b |
+#define S390X_OFF_SCALAR(n) (4 * n)
|
|
|
3a273b |
+
|
|
|
3a273b |
+/* Offsets of fields in KDSA parameter blocks */
|
|
|
3a273b |
+#define S390X_OFF_R(n) (0 * n)
|
|
|
3a273b |
+#define S390X_OFF_S(n) (1 * n)
|
|
|
3a273b |
+#define S390X_OFF_H(n) (2 * n)
|
|
|
3a273b |
+#define S390X_OFF_K(n) (3 * n)
|
|
|
3a273b |
+#define S390X_OFF_X(n) (3 * n)
|
|
|
3a273b |
+#define S390X_OFF_RN(n) (4 * n)
|
|
|
3a273b |
+#define S390X_OFF_Y(n) (4 * n)
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int ec_GFp_s390x_nistp_mul(const EC_GROUP *group, EC_POINT *r,
|
|
|
3a273b |
+ const BIGNUM *scalar,
|
|
|
3a273b |
+ size_t num, const EC_POINT *points[],
|
|
|
3a273b |
+ const BIGNUM *scalars[],
|
|
|
3a273b |
+ BN_CTX *ctx, unsigned int fc, int len)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ unsigned char param[S390X_SIZE_PARAM];
|
|
|
3a273b |
+ BIGNUM *x, *y;
|
|
|
3a273b |
+ const EC_POINT *point_ptr = NULL;
|
|
|
3a273b |
+ const BIGNUM *scalar_ptr = NULL;
|
|
|
3a273b |
+ BN_CTX *new_ctx = NULL;
|
|
|
3a273b |
+ int rc = -1;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (ctx == NULL) {
|
|
|
3a273b |
+ ctx = new_ctx = BN_CTX_new();
|
|
|
3a273b |
+ if (ctx == NULL)
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ BN_CTX_start(ctx);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ x = BN_CTX_get(ctx);
|
|
|
3a273b |
+ y = BN_CTX_get(ctx);
|
|
|
3a273b |
+ if (x == NULL || y == NULL) {
|
|
|
3a273b |
+ rc = 0;
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ /*
|
|
|
3a273b |
+ * Use PCC for EC keygen and ECDH key derivation:
|
|
|
3a273b |
+ * scalar * generator and scalar * peer public key,
|
|
|
3a273b |
+ * scalar in [0,order).
|
|
|
3a273b |
+ */
|
|
|
3a273b |
+ if ((scalar != NULL && num == 0 && BN_is_negative(scalar) == 0)
|
|
|
3a273b |
+ || (scalar == NULL && num == 1 && BN_is_negative(scalars[0]) == 0)) {
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (num == 0) {
|
|
|
3a273b |
+ point_ptr = EC_GROUP_get0_generator(group);
|
|
|
3a273b |
+ scalar_ptr = scalar;
|
|
|
3a273b |
+ } else {
|
|
|
3a273b |
+ point_ptr = points[0];
|
|
|
3a273b |
+ scalar_ptr = scalars[0];
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (EC_POINT_is_at_infinity(group, point_ptr) == 1
|
|
|
3a273b |
+ || BN_is_zero(scalar_ptr)) {
|
|
|
3a273b |
+ rc = EC_POINT_set_to_infinity(group, r);
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memset(¶m, 0, sizeof(param));
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (group->meth->point_get_affine_coordinates(group, point_ptr,
|
|
|
3a273b |
+ x, y, ctx) != 1
|
|
|
3a273b |
+ || BN_bn2binpad(x, param + S390X_OFF_SRC_X(len), len) == -1
|
|
|
3a273b |
+ || BN_bn2binpad(y, param + S390X_OFF_SRC_Y(len), len) == -1
|
|
|
3a273b |
+ || BN_bn2binpad(scalar_ptr,
|
|
|
3a273b |
+ param + S390X_OFF_SCALAR(len), len) == -1
|
|
|
3a273b |
+ || s390x_pcc(fc, param) != 0
|
|
|
3a273b |
+ || BN_bin2bn(param + S390X_OFF_RES_X(len), len, x) == NULL
|
|
|
3a273b |
+ || BN_bin2bn(param + S390X_OFF_RES_Y(len), len, y) == NULL
|
|
|
3a273b |
+ || group->meth->point_set_affine_coordinates(group, r,
|
|
|
3a273b |
+ x, y, ctx) != 1)
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ rc = 1;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ret:
|
|
|
3a273b |
+ /* Otherwise use default. */
|
|
|
3a273b |
+ if (rc == -1)
|
|
|
3a273b |
+ rc = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
|
|
|
3a273b |
+ OPENSSL_cleanse(param + S390X_OFF_SCALAR(len), len);
|
|
|
3a273b |
+ BN_CTX_end(ctx);
|
|
|
3a273b |
+ BN_CTX_free(new_ctx);
|
|
|
3a273b |
+ return rc;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static ECDSA_SIG *ecdsa_s390x_nistp_sign_sig(const unsigned char *dgst,
|
|
|
3a273b |
+ int dgstlen,
|
|
|
3a273b |
+ const BIGNUM *kinv,
|
|
|
3a273b |
+ const BIGNUM *r,
|
|
|
3a273b |
+ EC_KEY *eckey,
|
|
|
3a273b |
+ unsigned int fc, int len)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ unsigned char param[S390X_SIZE_PARAM];
|
|
|
3a273b |
+ int ok = 0;
|
|
|
3a273b |
+ BIGNUM *k;
|
|
|
3a273b |
+ ECDSA_SIG *sig;
|
|
|
3a273b |
+ const EC_GROUP *group;
|
|
|
3a273b |
+ const BIGNUM *privkey;
|
|
|
3a273b |
+ int off;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ group = EC_KEY_get0_group(eckey);
|
|
|
3a273b |
+ privkey = EC_KEY_get0_private_key(eckey);
|
|
|
3a273b |
+ if (group == NULL || privkey == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_SIGN_SIG, EC_R_MISSING_PARAMETERS);
|
|
|
3a273b |
+ return NULL;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (!EC_KEY_can_sign(eckey)) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_SIGN_SIG,
|
|
|
3a273b |
+ EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);
|
|
|
3a273b |
+ return NULL;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ k = BN_secure_new();
|
|
|
3a273b |
+ sig = ECDSA_SIG_new();
|
|
|
3a273b |
+ if (k == NULL || sig == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_SIGN_SIG, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ sig->r = BN_new();
|
|
|
3a273b |
+ sig->s = BN_new();
|
|
|
3a273b |
+ if (sig->r == NULL || sig->s == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_SIGN_SIG, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memset(param, 0, sizeof(param));
|
|
|
3a273b |
+ off = len - (dgstlen > len ? len : dgstlen);
|
|
|
3a273b |
+ memcpy(param + S390X_OFF_H(len) + off, dgst, len - off);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (BN_bn2binpad(privkey, param + S390X_OFF_K(len), len) == -1) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (r == NULL || kinv == NULL) {
|
|
|
3a273b |
+ /*
|
|
|
3a273b |
+ * Generate random k and copy to param param block. RAND_priv_bytes
|
|
|
3a273b |
+ * is used instead of BN_priv_rand_range or BN_generate_dsa_nonce
|
|
|
3a273b |
+ * because kdsa instruction constructs an in-range, invertible nonce
|
|
|
3a273b |
+ * internally implementing counter-measures for RNG weakness.
|
|
|
3a273b |
+ */
|
|
|
3a273b |
+ if (RAND_priv_bytes(param + S390X_OFF_RN(len), len) != 1) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_SIGN_SIG,
|
|
|
3a273b |
+ EC_R_RANDOM_NUMBER_GENERATION_FAILED);
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+ } else {
|
|
|
3a273b |
+ /* Reconstruct k = (k^-1)^-1. */
|
|
|
3a273b |
+ if (ec_group_do_inverse_ord(group, k, kinv, NULL) == 0
|
|
|
3a273b |
+ || BN_bn2binpad(k, param + S390X_OFF_RN(len), len) == -1) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+ /* Turns KDSA internal nonce-generation off. */
|
|
|
3a273b |
+ fc |= S390X_KDSA_D;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (s390x_kdsa(fc, param, NULL, 0) != 0) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_SIGN_SIG, ERR_R_ECDSA_LIB);
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (BN_bin2bn(param + S390X_OFF_R(len), len, sig->r) == NULL
|
|
|
3a273b |
+ || BN_bin2bn(param + S390X_OFF_S(len), len, sig->s) == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_SIGN_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ ok = 1;
|
|
|
3a273b |
+ret:
|
|
|
3a273b |
+ OPENSSL_cleanse(param + S390X_OFF_K(len), 2 * len);
|
|
|
3a273b |
+ if (ok != 1) {
|
|
|
3a273b |
+ ECDSA_SIG_free(sig);
|
|
|
3a273b |
+ sig = NULL;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+ BN_clear_free(k);
|
|
|
3a273b |
+ return sig;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int ecdsa_s390x_nistp_verify_sig(const unsigned char *dgst, int dgstlen,
|
|
|
3a273b |
+ const ECDSA_SIG *sig, EC_KEY *eckey,
|
|
|
3a273b |
+ unsigned int fc, int len)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ unsigned char param[S390X_SIZE_PARAM];
|
|
|
3a273b |
+ int rc = -1;
|
|
|
3a273b |
+ BN_CTX *ctx;
|
|
|
3a273b |
+ BIGNUM *x, *y;
|
|
|
3a273b |
+ const EC_GROUP *group;
|
|
|
3a273b |
+ const EC_POINT *pubkey;
|
|
|
3a273b |
+ int off;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ group = EC_KEY_get0_group(eckey);
|
|
|
3a273b |
+ pubkey = EC_KEY_get0_public_key(eckey);
|
|
|
3a273b |
+ if (eckey == NULL || group == NULL || pubkey == NULL || sig == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_VERIFY_SIG, EC_R_MISSING_PARAMETERS);
|
|
|
3a273b |
+ return -1;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (!EC_KEY_can_sign(eckey)) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_VERIFY_SIG,
|
|
|
3a273b |
+ EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);
|
|
|
3a273b |
+ return -1;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ ctx = BN_CTX_new();
|
|
|
3a273b |
+ if (ctx == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_VERIFY_SIG, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ return -1;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ BN_CTX_start(ctx);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ x = BN_CTX_get(ctx);
|
|
|
3a273b |
+ y = BN_CTX_get(ctx);
|
|
|
3a273b |
+ if (x == NULL || y == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_VERIFY_SIG, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memset(param, 0, sizeof(param));
|
|
|
3a273b |
+ off = len - (dgstlen > len ? len : dgstlen);
|
|
|
3a273b |
+ memcpy(param + S390X_OFF_H(len) + off, dgst, len - off);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (group->meth->point_get_affine_coordinates(group, pubkey,
|
|
|
3a273b |
+ x, y, ctx) != 1
|
|
|
3a273b |
+ || BN_bn2binpad(sig->r, param + S390X_OFF_R(len), len) == -1
|
|
|
3a273b |
+ || BN_bn2binpad(sig->s, param + S390X_OFF_S(len), len) == -1
|
|
|
3a273b |
+ || BN_bn2binpad(x, param + S390X_OFF_X(len), len) == -1
|
|
|
3a273b |
+ || BN_bn2binpad(y, param + S390X_OFF_Y(len), len) == -1) {
|
|
|
3a273b |
+ ECerr(EC_F_ECDSA_S390X_NISTP_VERIFY_SIG, ERR_R_BN_LIB);
|
|
|
3a273b |
+ goto ret;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ rc = s390x_kdsa(fc, param, NULL, 0) == 0 ? 1 : 0;
|
|
|
3a273b |
+ret:
|
|
|
3a273b |
+ BN_CTX_end(ctx);
|
|
|
3a273b |
+ BN_CTX_free(ctx);
|
|
|
3a273b |
+ return rc;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+#define EC_GFP_S390X_NISTP_METHOD(bits) \
|
|
|
3a273b |
+ \
|
|
|
3a273b |
+static int ec_GFp_s390x_nistp##bits##_mul(const EC_GROUP *group, \
|
|
|
3a273b |
+ EC_POINT *r, \
|
|
|
3a273b |
+ const BIGNUM *scalar, \
|
|
|
3a273b |
+ size_t num, \
|
|
|
3a273b |
+ const EC_POINT *points[], \
|
|
|
3a273b |
+ const BIGNUM *scalars[], \
|
|
|
3a273b |
+ BN_CTX *ctx) \
|
|
|
3a273b |
+{ \
|
|
|
3a273b |
+ return ec_GFp_s390x_nistp_mul(group, r, scalar, num, points, \
|
|
|
3a273b |
+ scalars, ctx, \
|
|
|
3a273b |
+ S390X_SCALAR_MULTIPLY_P##bits, \
|
|
|
3a273b |
+ S390X_SIZE_P##bits); \
|
|
|
3a273b |
+} \
|
|
|
3a273b |
+ \
|
|
|
3a273b |
+static ECDSA_SIG *ecdsa_s390x_nistp##bits##_sign_sig(const unsigned \
|
|
|
3a273b |
+ char *dgst, \
|
|
|
3a273b |
+ int dgstlen, \
|
|
|
3a273b |
+ const BIGNUM *kinv,\
|
|
|
3a273b |
+ const BIGNUM *r, \
|
|
|
3a273b |
+ EC_KEY *eckey) \
|
|
|
3a273b |
+{ \
|
|
|
3a273b |
+ return ecdsa_s390x_nistp_sign_sig(dgst, dgstlen, kinv, r, eckey, \
|
|
|
3a273b |
+ S390X_ECDSA_SIGN_P##bits, \
|
|
|
3a273b |
+ S390X_SIZE_P##bits); \
|
|
|
3a273b |
+} \
|
|
|
3a273b |
+ \
|
|
|
3a273b |
+static int ecdsa_s390x_nistp##bits##_verify_sig(const \
|
|
|
3a273b |
+ unsigned char *dgst, \
|
|
|
3a273b |
+ int dgstlen, \
|
|
|
3a273b |
+ const ECDSA_SIG *sig, \
|
|
|
3a273b |
+ EC_KEY *eckey) \
|
|
|
3a273b |
+{ \
|
|
|
3a273b |
+ return ecdsa_s390x_nistp_verify_sig(dgst, dgstlen, sig, eckey, \
|
|
|
3a273b |
+ S390X_ECDSA_VERIFY_P##bits, \
|
|
|
3a273b |
+ S390X_SIZE_P##bits); \
|
|
|
3a273b |
+} \
|
|
|
3a273b |
+ \
|
|
|
3a273b |
+const EC_METHOD *EC_GFp_s390x_nistp##bits##_method(void) \
|
|
|
3a273b |
+{ \
|
|
|
3a273b |
+ static const EC_METHOD EC_GFp_s390x_nistp##bits##_meth = { \
|
|
|
3a273b |
+ EC_FLAGS_DEFAULT_OCT, \
|
|
|
3a273b |
+ NID_X9_62_prime_field, \
|
|
|
3a273b |
+ ec_GFp_simple_group_init, \
|
|
|
3a273b |
+ ec_GFp_simple_group_finish, \
|
|
|
3a273b |
+ ec_GFp_simple_group_clear_finish, \
|
|
|
3a273b |
+ ec_GFp_simple_group_copy, \
|
|
|
3a273b |
+ ec_GFp_simple_group_set_curve, \
|
|
|
3a273b |
+ ec_GFp_simple_group_get_curve, \
|
|
|
3a273b |
+ ec_GFp_simple_group_get_degree, \
|
|
|
3a273b |
+ ec_group_simple_order_bits, \
|
|
|
3a273b |
+ ec_GFp_simple_group_check_discriminant, \
|
|
|
3a273b |
+ ec_GFp_simple_point_init, \
|
|
|
3a273b |
+ ec_GFp_simple_point_finish, \
|
|
|
3a273b |
+ ec_GFp_simple_point_clear_finish, \
|
|
|
3a273b |
+ ec_GFp_simple_point_copy, \
|
|
|
3a273b |
+ ec_GFp_simple_point_set_to_infinity, \
|
|
|
3a273b |
+ ec_GFp_simple_set_Jprojective_coordinates_GFp, \
|
|
|
3a273b |
+ ec_GFp_simple_get_Jprojective_coordinates_GFp, \
|
|
|
3a273b |
+ ec_GFp_simple_point_set_affine_coordinates, \
|
|
|
3a273b |
+ ec_GFp_simple_point_get_affine_coordinates, \
|
|
|
3a273b |
+ NULL, /* point_set_compressed_coordinates */ \
|
|
|
3a273b |
+ NULL, /* point2oct */ \
|
|
|
3a273b |
+ NULL, /* oct2point */ \
|
|
|
3a273b |
+ ec_GFp_simple_add, \
|
|
|
3a273b |
+ ec_GFp_simple_dbl, \
|
|
|
3a273b |
+ ec_GFp_simple_invert, \
|
|
|
3a273b |
+ ec_GFp_simple_is_at_infinity, \
|
|
|
3a273b |
+ ec_GFp_simple_is_on_curve, \
|
|
|
3a273b |
+ ec_GFp_simple_cmp, \
|
|
|
3a273b |
+ ec_GFp_simple_make_affine, \
|
|
|
3a273b |
+ ec_GFp_simple_points_make_affine, \
|
|
|
3a273b |
+ ec_GFp_s390x_nistp##bits##_mul, \
|
|
|
3a273b |
+ NULL, /* precompute_mult */ \
|
|
|
3a273b |
+ NULL, /* have_precompute_mult */ \
|
|
|
3a273b |
+ ec_GFp_simple_field_mul, \
|
|
|
3a273b |
+ ec_GFp_simple_field_sqr, \
|
|
|
3a273b |
+ NULL, /* field_div */ \
|
|
|
3a273b |
+ ec_GFp_simple_field_inv, \
|
|
|
3a273b |
+ NULL, /* field_encode */ \
|
|
|
3a273b |
+ NULL, /* field_decode */ \
|
|
|
3a273b |
+ NULL, /* field_set_to_one */ \
|
|
|
3a273b |
+ ec_key_simple_priv2oct, \
|
|
|
3a273b |
+ ec_key_simple_oct2priv, \
|
|
|
3a273b |
+ NULL, /* set_private */ \
|
|
|
3a273b |
+ ec_key_simple_generate_key, \
|
|
|
3a273b |
+ ec_key_simple_check_key, \
|
|
|
3a273b |
+ ec_key_simple_generate_public_key, \
|
|
|
3a273b |
+ NULL, /* keycopy */ \
|
|
|
3a273b |
+ NULL, /* keyfinish */ \
|
|
|
3a273b |
+ ecdh_simple_compute_key, \
|
|
|
3a273b |
+ ecdsa_simple_sign_setup, \
|
|
|
3a273b |
+ ecdsa_s390x_nistp##bits##_sign_sig, \
|
|
|
3a273b |
+ ecdsa_s390x_nistp##bits##_verify_sig, \
|
|
|
3a273b |
+ NULL, /* field_inverse_mod_ord */ \
|
|
|
3a273b |
+ ec_GFp_simple_blind_coordinates, \
|
|
|
3a273b |
+ ec_GFp_simple_ladder_pre, \
|
|
|
3a273b |
+ ec_GFp_simple_ladder_step, \
|
|
|
3a273b |
+ ec_GFp_simple_ladder_post \
|
|
|
3a273b |
+ }; \
|
|
|
3a273b |
+ static const EC_METHOD *ret; \
|
|
|
3a273b |
+ \
|
|
|
3a273b |
+ if ((OPENSSL_s390xcap_P.pcc[1] \
|
|
|
3a273b |
+ & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_P##bits)) \
|
|
|
3a273b |
+ && (OPENSSL_s390xcap_P.kdsa[0] \
|
|
|
3a273b |
+ & S390X_CAPBIT(S390X_ECDSA_VERIFY_P##bits)) \
|
|
|
3a273b |
+ && (OPENSSL_s390xcap_P.kdsa[0] \
|
|
|
3a273b |
+ & S390X_CAPBIT(S390X_ECDSA_SIGN_P##bits))) \
|
|
|
3a273b |
+ ret = &EC_GFp_s390x_nistp##bits##_meth; \
|
|
|
3a273b |
+ else \
|
|
|
3a273b |
+ ret = EC_GFp_mont_method(); \
|
|
|
3a273b |
+ \
|
|
|
3a273b |
+ return ret; \
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+EC_GFP_S390X_NISTP_METHOD(256)
|
|
|
3a273b |
+EC_GFP_S390X_NISTP_METHOD(384)
|
|
|
3a273b |
+EC_GFP_S390X_NISTP_METHOD(521)
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ecp_smpl.c.s390x-ecc openssl-1.1.1c/crypto/ec/ecp_smpl.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ecp_smpl.c.s390x-ecc 2019-11-20 11:36:02.066862626 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ecp_smpl.c 2019-11-20 11:36:02.195860363 +0100
|
|
|
3a273b |
@@ -64,6 +64,9 @@ const EC_METHOD *EC_GFp_simple_method(vo
|
|
|
3a273b |
0, /* keycopy */
|
|
|
3a273b |
0, /* keyfinish */
|
|
|
3a273b |
ecdh_simple_compute_key,
|
|
|
3a273b |
+ ecdsa_simple_sign_setup,
|
|
|
3a273b |
+ ecdsa_simple_sign_sig,
|
|
|
3a273b |
+ ecdsa_simple_verify_sig,
|
|
|
3a273b |
0, /* field_inverse_mod_ord */
|
|
|
3a273b |
ec_GFp_simple_blind_coordinates,
|
|
|
3a273b |
ec_GFp_simple_ladder_pre,
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/ec/ecx_meth.c.s390x-ecc openssl-1.1.1c/crypto/ec/ecx_meth.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/ec/ecx_meth.c.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/ec/ecx_meth.c 2019-11-20 11:36:02.196860345 +0100
|
|
|
3a273b |
@@ -20,6 +20,7 @@
|
|
|
3a273b |
#define X25519_BITS 253
|
|
|
3a273b |
#define X25519_SECURITY_BITS 128
|
|
|
3a273b |
|
|
|
3a273b |
+#define ED25519_KEYLEN 32
|
|
|
3a273b |
#define ED25519_SIGSIZE 64
|
|
|
3a273b |
|
|
|
3a273b |
#define X448_BITS 448
|
|
|
3a273b |
@@ -839,3 +840,666 @@ const EVP_PKEY_METHOD ed448_pkey_meth =
|
|
|
3a273b |
pkey_ecd_digestsign448,
|
|
|
3a273b |
pkey_ecd_digestverify448
|
|
|
3a273b |
};
|
|
|
3a273b |
+
|
|
|
3a273b |
+#ifdef S390X_EC_ASM
|
|
|
3a273b |
+# include "s390x_arch.h"
|
|
|
3a273b |
+# include "internal/constant_time_locl.h"
|
|
|
3a273b |
+
|
|
|
3a273b |
+static void s390x_x25519_mod_p(unsigned char u[32])
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ unsigned char u_red[32];
|
|
|
3a273b |
+ unsigned int c = 0;
|
|
|
3a273b |
+ int i;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memcpy(u_red, u, sizeof(u_red));
|
|
|
3a273b |
+
|
|
|
3a273b |
+ c += (unsigned int)u_red[31] + 19;
|
|
|
3a273b |
+ u_red[31] = (unsigned char)c;
|
|
|
3a273b |
+ c >>= 8;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ for (i = 30; i >= 0; i--) {
|
|
|
3a273b |
+ c += (unsigned int)u_red[i];
|
|
|
3a273b |
+ u_red[i] = (unsigned char)c;
|
|
|
3a273b |
+ c >>= 8;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ c = (u_red[0] & 0x80) >> 7;
|
|
|
3a273b |
+ u_red[0] &= 0x7f;
|
|
|
3a273b |
+ constant_time_cond_swap_buff(0 - (unsigned char)c,
|
|
|
3a273b |
+ u, u_red, sizeof(u_red));
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static void s390x_x448_mod_p(unsigned char u[56])
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ unsigned char u_red[56];
|
|
|
3a273b |
+ unsigned int c = 0;
|
|
|
3a273b |
+ int i;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memcpy(u_red, u, sizeof(u_red));
|
|
|
3a273b |
+
|
|
|
3a273b |
+ c += (unsigned int)u_red[55] + 1;
|
|
|
3a273b |
+ u_red[55] = (unsigned char)c;
|
|
|
3a273b |
+ c >>= 8;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ for (i = 54; i >= 28; i--) {
|
|
|
3a273b |
+ c += (unsigned int)u_red[i];
|
|
|
3a273b |
+ u_red[i] = (unsigned char)c;
|
|
|
3a273b |
+ c >>= 8;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ c += (unsigned int)u_red[27] + 1;
|
|
|
3a273b |
+ u_red[27] = (unsigned char)c;
|
|
|
3a273b |
+ c >>= 8;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ for (i = 26; i >= 0; i--) {
|
|
|
3a273b |
+ c += (unsigned int)u_red[i];
|
|
|
3a273b |
+ u_red[i] = (unsigned char)c;
|
|
|
3a273b |
+ c >>= 8;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ constant_time_cond_swap_buff(0 - (unsigned char)c,
|
|
|
3a273b |
+ u, u_red, sizeof(u_red));
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_x25519_mul(unsigned char u_dst[32],
|
|
|
3a273b |
+ const unsigned char u_src[32],
|
|
|
3a273b |
+ const unsigned char d_src[32])
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ union {
|
|
|
3a273b |
+ struct {
|
|
|
3a273b |
+ unsigned char u_dst[32];
|
|
|
3a273b |
+ unsigned char u_src[32];
|
|
|
3a273b |
+ unsigned char d_src[32];
|
|
|
3a273b |
+ } x25519;
|
|
|
3a273b |
+ unsigned long long buff[512];
|
|
|
3a273b |
+ } param;
|
|
|
3a273b |
+ int rc;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memset(¶m, 0, sizeof(param));
|
|
|
3a273b |
+
|
|
|
3a273b |
+ s390x_flip_endian32(param.x25519.u_src, u_src);
|
|
|
3a273b |
+ param.x25519.u_src[0] &= 0x7f;
|
|
|
3a273b |
+ s390x_x25519_mod_p(param.x25519.u_src);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ s390x_flip_endian32(param.x25519.d_src, d_src);
|
|
|
3a273b |
+ param.x25519.d_src[31] &= 248;
|
|
|
3a273b |
+ param.x25519.d_src[0] &= 127;
|
|
|
3a273b |
+ param.x25519.d_src[0] |= 64;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ rc = s390x_pcc(S390X_SCALAR_MULTIPLY_X25519, ¶m.x25519) ? 0 : 1;
|
|
|
3a273b |
+ if (rc == 1)
|
|
|
3a273b |
+ s390x_flip_endian32(u_dst, param.x25519.u_dst);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ OPENSSL_cleanse(param.x25519.d_src, sizeof(param.x25519.d_src));
|
|
|
3a273b |
+ return rc;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_x448_mul(unsigned char u_dst[56],
|
|
|
3a273b |
+ const unsigned char u_src[56],
|
|
|
3a273b |
+ const unsigned char d_src[56])
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ union {
|
|
|
3a273b |
+ struct {
|
|
|
3a273b |
+ unsigned char u_dst[64];
|
|
|
3a273b |
+ unsigned char u_src[64];
|
|
|
3a273b |
+ unsigned char d_src[64];
|
|
|
3a273b |
+ } x448;
|
|
|
3a273b |
+ unsigned long long buff[512];
|
|
|
3a273b |
+ } param;
|
|
|
3a273b |
+ int rc;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memset(¶m, 0, sizeof(param));
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memcpy(param.x448.u_src, u_src, 56);
|
|
|
3a273b |
+ memcpy(param.x448.d_src, d_src, 56);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ s390x_flip_endian64(param.x448.u_src, param.x448.u_src);
|
|
|
3a273b |
+ s390x_x448_mod_p(param.x448.u_src + 8);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ s390x_flip_endian64(param.x448.d_src, param.x448.d_src);
|
|
|
3a273b |
+ param.x448.d_src[63] &= 252;
|
|
|
3a273b |
+ param.x448.d_src[8] |= 128;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ rc = s390x_pcc(S390X_SCALAR_MULTIPLY_X448, ¶m.x448) ? 0 : 1;
|
|
|
3a273b |
+ if (rc == 1) {
|
|
|
3a273b |
+ s390x_flip_endian64(param.x448.u_dst, param.x448.u_dst);
|
|
|
3a273b |
+ memcpy(u_dst, param.x448.u_dst, 56);
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ OPENSSL_cleanse(param.x448.d_src, sizeof(param.x448.d_src));
|
|
|
3a273b |
+ return rc;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_ed25519_mul(unsigned char x_dst[32],
|
|
|
3a273b |
+ unsigned char y_dst[32],
|
|
|
3a273b |
+ const unsigned char x_src[32],
|
|
|
3a273b |
+ const unsigned char y_src[32],
|
|
|
3a273b |
+ const unsigned char d_src[32])
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ union {
|
|
|
3a273b |
+ struct {
|
|
|
3a273b |
+ unsigned char x_dst[32];
|
|
|
3a273b |
+ unsigned char y_dst[32];
|
|
|
3a273b |
+ unsigned char x_src[32];
|
|
|
3a273b |
+ unsigned char y_src[32];
|
|
|
3a273b |
+ unsigned char d_src[32];
|
|
|
3a273b |
+ } ed25519;
|
|
|
3a273b |
+ unsigned long long buff[512];
|
|
|
3a273b |
+ } param;
|
|
|
3a273b |
+ int rc;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memset(¶m, 0, sizeof(param));
|
|
|
3a273b |
+
|
|
|
3a273b |
+ s390x_flip_endian32(param.ed25519.x_src, x_src);
|
|
|
3a273b |
+ s390x_flip_endian32(param.ed25519.y_src, y_src);
|
|
|
3a273b |
+ s390x_flip_endian32(param.ed25519.d_src, d_src);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ rc = s390x_pcc(S390X_SCALAR_MULTIPLY_ED25519, ¶m.ed25519) ? 0 : 1;
|
|
|
3a273b |
+ if (rc == 1) {
|
|
|
3a273b |
+ s390x_flip_endian32(x_dst, param.ed25519.x_dst);
|
|
|
3a273b |
+ s390x_flip_endian32(y_dst, param.ed25519.y_dst);
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ OPENSSL_cleanse(param.ed25519.d_src, sizeof(param.ed25519.d_src));
|
|
|
3a273b |
+ return rc;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_ed448_mul(unsigned char x_dst[57],
|
|
|
3a273b |
+ unsigned char y_dst[57],
|
|
|
3a273b |
+ const unsigned char x_src[57],
|
|
|
3a273b |
+ const unsigned char y_src[57],
|
|
|
3a273b |
+ const unsigned char d_src[57])
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ union {
|
|
|
3a273b |
+ struct {
|
|
|
3a273b |
+ unsigned char x_dst[64];
|
|
|
3a273b |
+ unsigned char y_dst[64];
|
|
|
3a273b |
+ unsigned char x_src[64];
|
|
|
3a273b |
+ unsigned char y_src[64];
|
|
|
3a273b |
+ unsigned char d_src[64];
|
|
|
3a273b |
+ } ed448;
|
|
|
3a273b |
+ unsigned long long buff[512];
|
|
|
3a273b |
+ } param;
|
|
|
3a273b |
+ int rc;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memset(¶m, 0, sizeof(param));
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memcpy(param.ed448.x_src, x_src, 57);
|
|
|
3a273b |
+ memcpy(param.ed448.y_src, y_src, 57);
|
|
|
3a273b |
+ memcpy(param.ed448.d_src, d_src, 57);
|
|
|
3a273b |
+ s390x_flip_endian64(param.ed448.x_src, param.ed448.x_src);
|
|
|
3a273b |
+ s390x_flip_endian64(param.ed448.y_src, param.ed448.y_src);
|
|
|
3a273b |
+ s390x_flip_endian64(param.ed448.d_src, param.ed448.d_src);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ rc = s390x_pcc(S390X_SCALAR_MULTIPLY_ED448, ¶m.ed448) ? 0 : 1;
|
|
|
3a273b |
+ if (rc == 1) {
|
|
|
3a273b |
+ s390x_flip_endian64(param.ed448.x_dst, param.ed448.x_dst);
|
|
|
3a273b |
+ s390x_flip_endian64(param.ed448.y_dst, param.ed448.y_dst);
|
|
|
3a273b |
+ memcpy(x_dst, param.ed448.x_dst, 57);
|
|
|
3a273b |
+ memcpy(y_dst, param.ed448.y_dst, 57);
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ OPENSSL_cleanse(param.ed448.d_src, sizeof(param.ed448.d_src));
|
|
|
3a273b |
+ return rc;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_pkey_ecx_keygen25519(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ static const unsigned char generator[] = {
|
|
|
3a273b |
+ 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
3a273b |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
3a273b |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
|
|
3a273b |
+ };
|
|
|
3a273b |
+ ECX_KEY *key;
|
|
|
3a273b |
+ unsigned char *privkey = NULL, *pubkey;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ key = OPENSSL_zalloc(sizeof(*key));
|
|
|
3a273b |
+ if (key == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_S390X_PKEY_ECX_KEYGEN25519, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ pubkey = key->pubkey;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ privkey = key->privkey = OPENSSL_secure_malloc(X25519_KEYLEN);
|
|
|
3a273b |
+ if (privkey == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_S390X_PKEY_ECX_KEYGEN25519, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (RAND_priv_bytes(privkey, X25519_KEYLEN) <= 0)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ privkey[0] &= 248;
|
|
|
3a273b |
+ privkey[31] &= 127;
|
|
|
3a273b |
+ privkey[31] |= 64;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (s390x_x25519_mul(pubkey, generator, privkey) != 1)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, key);
|
|
|
3a273b |
+ return 1;
|
|
|
3a273b |
+ err:
|
|
|
3a273b |
+ OPENSSL_secure_clear_free(privkey, X25519_KEYLEN);
|
|
|
3a273b |
+ key->privkey = NULL;
|
|
|
3a273b |
+ OPENSSL_free(key);
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_pkey_ecx_keygen448(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ static const unsigned char generator[] = {
|
|
|
3a273b |
+ 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
3a273b |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
3a273b |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
3a273b |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
3a273b |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
|
|
3a273b |
+ };
|
|
|
3a273b |
+ ECX_KEY *key;
|
|
|
3a273b |
+ unsigned char *privkey = NULL, *pubkey;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ key = OPENSSL_zalloc(sizeof(*key));
|
|
|
3a273b |
+ if (key == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_S390X_PKEY_ECX_KEYGEN448, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ pubkey = key->pubkey;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ privkey = key->privkey = OPENSSL_secure_malloc(X448_KEYLEN);
|
|
|
3a273b |
+ if (privkey == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_S390X_PKEY_ECX_KEYGEN448, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (RAND_priv_bytes(privkey, X448_KEYLEN) <= 0)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ privkey[0] &= 252;
|
|
|
3a273b |
+ privkey[55] |= 128;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (s390x_x448_mul(pubkey, generator, privkey) != 1)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, key);
|
|
|
3a273b |
+ return 1;
|
|
|
3a273b |
+ err:
|
|
|
3a273b |
+ OPENSSL_secure_clear_free(privkey, X448_KEYLEN);
|
|
|
3a273b |
+ key->privkey = NULL;
|
|
|
3a273b |
+ OPENSSL_free(key);
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_pkey_ecd_keygen25519(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ static const unsigned char generator_x[] = {
|
|
|
3a273b |
+ 0x1a, 0xd5, 0x25, 0x8f, 0x60, 0x2d, 0x56, 0xc9, 0xb2, 0xa7, 0x25, 0x95,
|
|
|
3a273b |
+ 0x60, 0xc7, 0x2c, 0x69, 0x5c, 0xdc, 0xd6, 0xfd, 0x31, 0xe2, 0xa4, 0xc0,
|
|
|
3a273b |
+ 0xfe, 0x53, 0x6e, 0xcd, 0xd3, 0x36, 0x69, 0x21
|
|
|
3a273b |
+ };
|
|
|
3a273b |
+ static const unsigned char generator_y[] = {
|
|
|
3a273b |
+ 0x58, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
|
|
|
3a273b |
+ 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
|
|
|
3a273b |
+ 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
|
|
|
3a273b |
+ };
|
|
|
3a273b |
+ unsigned char x_dst[32], buff[SHA512_DIGEST_LENGTH];
|
|
|
3a273b |
+ ECX_KEY *key;
|
|
|
3a273b |
+ unsigned char *privkey = NULL, *pubkey;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ key = OPENSSL_zalloc(sizeof(*key));
|
|
|
3a273b |
+ if (key == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_S390X_PKEY_ECD_KEYGEN25519, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ pubkey = key->pubkey;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ privkey = key->privkey = OPENSSL_secure_malloc(ED25519_KEYLEN);
|
|
|
3a273b |
+ if (privkey == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_S390X_PKEY_ECD_KEYGEN25519, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (RAND_priv_bytes(privkey, ED25519_KEYLEN) <= 0)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ SHA512(privkey, 32, buff);
|
|
|
3a273b |
+ buff[0] &= 248;
|
|
|
3a273b |
+ buff[31] &= 63;
|
|
|
3a273b |
+ buff[31] |= 64;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (s390x_ed25519_mul(x_dst, pubkey,
|
|
|
3a273b |
+ generator_x, generator_y, buff) != 1)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ pubkey[31] |= ((x_dst[0] & 0x01) << 7);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, key);
|
|
|
3a273b |
+ return 1;
|
|
|
3a273b |
+ err:
|
|
|
3a273b |
+ OPENSSL_secure_clear_free(privkey, ED25519_KEYLEN);
|
|
|
3a273b |
+ key->privkey = NULL;
|
|
|
3a273b |
+ OPENSSL_free(key);
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_pkey_ecd_keygen448(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ static const unsigned char generator_x[] = {
|
|
|
3a273b |
+ 0x5e, 0xc0, 0x0c, 0xc7, 0x2b, 0xa8, 0x26, 0x26, 0x8e, 0x93, 0x00, 0x8b,
|
|
|
3a273b |
+ 0xe1, 0x80, 0x3b, 0x43, 0x11, 0x65, 0xb6, 0x2a, 0xf7, 0x1a, 0xae, 0x12,
|
|
|
3a273b |
+ 0x64, 0xa4, 0xd3, 0xa3, 0x24, 0xe3, 0x6d, 0xea, 0x67, 0x17, 0x0f, 0x47,
|
|
|
3a273b |
+ 0x70, 0x65, 0x14, 0x9e, 0xda, 0x36, 0xbf, 0x22, 0xa6, 0x15, 0x1d, 0x22,
|
|
|
3a273b |
+ 0xed, 0x0d, 0xed, 0x6b, 0xc6, 0x70, 0x19, 0x4f, 0x00
|
|
|
3a273b |
+ };
|
|
|
3a273b |
+ static const unsigned char generator_y[] = {
|
|
|
3a273b |
+ 0x14, 0xfa, 0x30, 0xf2, 0x5b, 0x79, 0x08, 0x98, 0xad, 0xc8, 0xd7, 0x4e,
|
|
|
3a273b |
+ 0x2c, 0x13, 0xbd, 0xfd, 0xc4, 0x39, 0x7c, 0xe6, 0x1c, 0xff, 0xd3, 0x3a,
|
|
|
3a273b |
+ 0xd7, 0xc2, 0xa0, 0x05, 0x1e, 0x9c, 0x78, 0x87, 0x40, 0x98, 0xa3, 0x6c,
|
|
|
3a273b |
+ 0x73, 0x73, 0xea, 0x4b, 0x62, 0xc7, 0xc9, 0x56, 0x37, 0x20, 0x76, 0x88,
|
|
|
3a273b |
+ 0x24, 0xbc, 0xb6, 0x6e, 0x71, 0x46, 0x3f, 0x69, 0x00
|
|
|
3a273b |
+ };
|
|
|
3a273b |
+ unsigned char x_dst[57], buff[114];
|
|
|
3a273b |
+ ECX_KEY *key;
|
|
|
3a273b |
+ unsigned char *privkey = NULL, *pubkey;
|
|
|
3a273b |
+ EVP_MD_CTX *hashctx = NULL;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ key = OPENSSL_zalloc(sizeof(*key));
|
|
|
3a273b |
+ if (key == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_S390X_PKEY_ECD_KEYGEN448, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ pubkey = key->pubkey;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ privkey = key->privkey = OPENSSL_secure_malloc(ED448_KEYLEN);
|
|
|
3a273b |
+ if (privkey == NULL) {
|
|
|
3a273b |
+ ECerr(EC_F_S390X_PKEY_ECD_KEYGEN448, ERR_R_MALLOC_FAILURE);
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (RAND_priv_bytes(privkey, ED448_KEYLEN) <= 0)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ hashctx = EVP_MD_CTX_new();
|
|
|
3a273b |
+ if (hashctx == NULL)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+ if (EVP_DigestInit_ex(hashctx, EVP_shake256(), NULL) != 1)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+ if (EVP_DigestUpdate(hashctx, privkey, 57) != 1)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+ if (EVP_DigestFinalXOF(hashctx, buff, sizeof(buff)) != 1)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ buff[0] &= -4;
|
|
|
3a273b |
+ buff[55] |= 0x80;
|
|
|
3a273b |
+ buff[56] = 0;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (s390x_ed448_mul(x_dst, pubkey,
|
|
|
3a273b |
+ generator_x, generator_y, buff) != 1)
|
|
|
3a273b |
+ goto err;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ pubkey[56] |= ((x_dst[0] & 0x01) << 7);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, key);
|
|
|
3a273b |
+ EVP_MD_CTX_free(hashctx);
|
|
|
3a273b |
+ return 1;
|
|
|
3a273b |
+ err:
|
|
|
3a273b |
+ OPENSSL_secure_clear_free(privkey, ED448_KEYLEN);
|
|
|
3a273b |
+ key->privkey = NULL;
|
|
|
3a273b |
+ OPENSSL_free(key);
|
|
|
3a273b |
+ EVP_MD_CTX_free(hashctx);
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_pkey_ecx_derive25519(EVP_PKEY_CTX *ctx, unsigned char *key,
|
|
|
3a273b |
+ size_t *keylen)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ const unsigned char *privkey, *pubkey;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (!validate_ecx_derive(ctx, key, keylen, &privkey, &pubkey))
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (key != NULL)
|
|
|
3a273b |
+ return s390x_x25519_mul(key, pubkey, privkey);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ *keylen = X25519_KEYLEN;
|
|
|
3a273b |
+ return 1;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_pkey_ecx_derive448(EVP_PKEY_CTX *ctx, unsigned char *key,
|
|
|
3a273b |
+ size_t *keylen)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ const unsigned char *privkey, *pubkey;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (!validate_ecx_derive(ctx, key, keylen, &privkey, &pubkey))
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (key != NULL)
|
|
|
3a273b |
+ return s390x_x448_mul(key, pubkey, privkey);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ *keylen = X448_KEYLEN;
|
|
|
3a273b |
+ return 1;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_pkey_ecd_digestsign25519(EVP_MD_CTX *ctx,
|
|
|
3a273b |
+ unsigned char *sig, size_t *siglen,
|
|
|
3a273b |
+ const unsigned char *tbs,
|
|
|
3a273b |
+ size_t tbslen)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ union {
|
|
|
3a273b |
+ struct {
|
|
|
3a273b |
+ unsigned char sig[64];
|
|
|
3a273b |
+ unsigned char priv[32];
|
|
|
3a273b |
+ } ed25519;
|
|
|
3a273b |
+ unsigned long long buff[512];
|
|
|
3a273b |
+ } param;
|
|
|
3a273b |
+ const ECX_KEY *edkey = EVP_MD_CTX_pkey_ctx(ctx)->pkey->pkey.ecx;
|
|
|
3a273b |
+ int rc;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (sig == NULL) {
|
|
|
3a273b |
+ *siglen = ED25519_SIGSIZE;
|
|
|
3a273b |
+ return 1;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (*siglen < ED25519_SIGSIZE) {
|
|
|
3a273b |
+ ECerr(EC_F_S390X_PKEY_ECD_DIGESTSIGN25519, EC_R_BUFFER_TOO_SMALL);
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memset(¶m, 0, sizeof(param));
|
|
|
3a273b |
+ memcpy(param.ed25519.priv, edkey->privkey, sizeof(param.ed25519.priv));
|
|
|
3a273b |
+
|
|
|
3a273b |
+ rc = s390x_kdsa(S390X_EDDSA_SIGN_ED25519, ¶m.ed25519, tbs, tbslen);
|
|
|
3a273b |
+ OPENSSL_cleanse(param.ed25519.priv, sizeof(param.ed25519.priv));
|
|
|
3a273b |
+ if (rc != 0)
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ s390x_flip_endian32(sig, param.ed25519.sig);
|
|
|
3a273b |
+ s390x_flip_endian32(sig + 32, param.ed25519.sig + 32);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ *siglen = ED25519_SIGSIZE;
|
|
|
3a273b |
+ return 1;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_pkey_ecd_digestsign448(EVP_MD_CTX *ctx,
|
|
|
3a273b |
+ unsigned char *sig, size_t *siglen,
|
|
|
3a273b |
+ const unsigned char *tbs,
|
|
|
3a273b |
+ size_t tbslen)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ union {
|
|
|
3a273b |
+ struct {
|
|
|
3a273b |
+ unsigned char sig[128];
|
|
|
3a273b |
+ unsigned char priv[64];
|
|
|
3a273b |
+ } ed448;
|
|
|
3a273b |
+ unsigned long long buff[512];
|
|
|
3a273b |
+ } param;
|
|
|
3a273b |
+ const ECX_KEY *edkey = EVP_MD_CTX_pkey_ctx(ctx)->pkey->pkey.ecx;
|
|
|
3a273b |
+ int rc;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (sig == NULL) {
|
|
|
3a273b |
+ *siglen = ED448_SIGSIZE;
|
|
|
3a273b |
+ return 1;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (*siglen < ED448_SIGSIZE) {
|
|
|
3a273b |
+ ECerr(EC_F_S390X_PKEY_ECD_DIGESTSIGN448, EC_R_BUFFER_TOO_SMALL);
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memset(¶m, 0, sizeof(param));
|
|
|
3a273b |
+ memcpy(param.ed448.priv + 64 - 57, edkey->privkey, 57);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ rc = s390x_kdsa(S390X_EDDSA_SIGN_ED448, ¶m.ed448, tbs, tbslen);
|
|
|
3a273b |
+ OPENSSL_cleanse(param.ed448.priv, sizeof(param.ed448.priv));
|
|
|
3a273b |
+ if (rc != 0)
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ s390x_flip_endian64(param.ed448.sig, param.ed448.sig);
|
|
|
3a273b |
+ s390x_flip_endian64(param.ed448.sig + 64, param.ed448.sig + 64);
|
|
|
3a273b |
+ memcpy(sig, param.ed448.sig, 57);
|
|
|
3a273b |
+ memcpy(sig + 57, param.ed448.sig + 64, 57);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ *siglen = ED448_SIGSIZE;
|
|
|
3a273b |
+ return 1;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_pkey_ecd_digestverify25519(EVP_MD_CTX *ctx,
|
|
|
3a273b |
+ const unsigned char *sig,
|
|
|
3a273b |
+ size_t siglen,
|
|
|
3a273b |
+ const unsigned char *tbs,
|
|
|
3a273b |
+ size_t tbslen)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ union {
|
|
|
3a273b |
+ struct {
|
|
|
3a273b |
+ unsigned char sig[64];
|
|
|
3a273b |
+ unsigned char pub[32];
|
|
|
3a273b |
+ } ed25519;
|
|
|
3a273b |
+ unsigned long long buff[512];
|
|
|
3a273b |
+ } param;
|
|
|
3a273b |
+ const ECX_KEY *edkey = EVP_MD_CTX_pkey_ctx(ctx)->pkey->pkey.ecx;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (siglen != ED25519_SIGSIZE)
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memset(¶m, 0, sizeof(param));
|
|
|
3a273b |
+ s390x_flip_endian32(param.ed25519.sig, sig);
|
|
|
3a273b |
+ s390x_flip_endian32(param.ed25519.sig + 32, sig + 32);
|
|
|
3a273b |
+ s390x_flip_endian32(param.ed25519.pub, edkey->pubkey);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ return s390x_kdsa(S390X_EDDSA_VERIFY_ED25519,
|
|
|
3a273b |
+ ¶m.ed25519, tbs, tbslen) == 0 ? 1 : 0;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int s390x_pkey_ecd_digestverify448(EVP_MD_CTX *ctx,
|
|
|
3a273b |
+ const unsigned char *sig,
|
|
|
3a273b |
+ size_t siglen,
|
|
|
3a273b |
+ const unsigned char *tbs,
|
|
|
3a273b |
+ size_t tbslen)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ union {
|
|
|
3a273b |
+ struct {
|
|
|
3a273b |
+ unsigned char sig[128];
|
|
|
3a273b |
+ unsigned char pub[64];
|
|
|
3a273b |
+ } ed448;
|
|
|
3a273b |
+ unsigned long long buff[512];
|
|
|
3a273b |
+ } param;
|
|
|
3a273b |
+ const ECX_KEY *edkey = EVP_MD_CTX_pkey_ctx(ctx)->pkey->pkey.ecx;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ if (siglen != ED448_SIGSIZE)
|
|
|
3a273b |
+ return 0;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ memset(¶m, 0, sizeof(param));
|
|
|
3a273b |
+ memcpy(param.ed448.sig, sig, 57);
|
|
|
3a273b |
+ s390x_flip_endian64(param.ed448.sig, param.ed448.sig);
|
|
|
3a273b |
+ memcpy(param.ed448.sig + 64, sig + 57, 57);
|
|
|
3a273b |
+ s390x_flip_endian64(param.ed448.sig + 64, param.ed448.sig + 64);
|
|
|
3a273b |
+ memcpy(param.ed448.pub, edkey->pubkey, 57);
|
|
|
3a273b |
+ s390x_flip_endian64(param.ed448.pub, param.ed448.pub);
|
|
|
3a273b |
+
|
|
|
3a273b |
+ return s390x_kdsa(S390X_EDDSA_VERIFY_ED448,
|
|
|
3a273b |
+ ¶m.ed448, tbs, tbslen) == 0 ? 1 : 0;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+static const EVP_PKEY_METHOD ecx25519_s390x_pkey_meth = {
|
|
|
3a273b |
+ EVP_PKEY_X25519,
|
|
|
3a273b |
+ 0, 0, 0, 0, 0, 0, 0,
|
|
|
3a273b |
+ s390x_pkey_ecx_keygen25519,
|
|
|
3a273b |
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
3a273b |
+ s390x_pkey_ecx_derive25519,
|
|
|
3a273b |
+ pkey_ecx_ctrl,
|
|
|
3a273b |
+ 0
|
|
|
3a273b |
+};
|
|
|
3a273b |
+
|
|
|
3a273b |
+static const EVP_PKEY_METHOD ecx448_s390x_pkey_meth = {
|
|
|
3a273b |
+ EVP_PKEY_X448,
|
|
|
3a273b |
+ 0, 0, 0, 0, 0, 0, 0,
|
|
|
3a273b |
+ s390x_pkey_ecx_keygen448,
|
|
|
3a273b |
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
3a273b |
+ s390x_pkey_ecx_derive448,
|
|
|
3a273b |
+ pkey_ecx_ctrl,
|
|
|
3a273b |
+ 0
|
|
|
3a273b |
+};
|
|
|
3a273b |
+static const EVP_PKEY_METHOD ed25519_s390x_pkey_meth = {
|
|
|
3a273b |
+ EVP_PKEY_ED25519, EVP_PKEY_FLAG_SIGCTX_CUSTOM,
|
|
|
3a273b |
+ 0, 0, 0, 0, 0, 0,
|
|
|
3a273b |
+ s390x_pkey_ecd_keygen25519,
|
|
|
3a273b |
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
3a273b |
+ pkey_ecd_ctrl,
|
|
|
3a273b |
+ 0,
|
|
|
3a273b |
+ s390x_pkey_ecd_digestsign25519,
|
|
|
3a273b |
+ s390x_pkey_ecd_digestverify25519
|
|
|
3a273b |
+};
|
|
|
3a273b |
+
|
|
|
3a273b |
+static const EVP_PKEY_METHOD ed448_s390x_pkey_meth = {
|
|
|
3a273b |
+ EVP_PKEY_ED448, EVP_PKEY_FLAG_SIGCTX_CUSTOM,
|
|
|
3a273b |
+ 0, 0, 0, 0, 0, 0,
|
|
|
3a273b |
+ s390x_pkey_ecd_keygen448,
|
|
|
3a273b |
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
3a273b |
+ pkey_ecd_ctrl,
|
|
|
3a273b |
+ 0,
|
|
|
3a273b |
+ s390x_pkey_ecd_digestsign448,
|
|
|
3a273b |
+ s390x_pkey_ecd_digestverify448
|
|
|
3a273b |
+};
|
|
|
3a273b |
+#endif
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *ecx25519_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+#ifdef S390X_EC_ASM
|
|
|
3a273b |
+ if (OPENSSL_s390xcap_P.pcc[1] & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X25519))
|
|
|
3a273b |
+ return &ecx25519_s390x_pkey_meth;
|
|
|
3a273b |
+#endif
|
|
|
3a273b |
+ return &ecx25519_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *ecx448_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+#ifdef S390X_EC_ASM
|
|
|
3a273b |
+ if (OPENSSL_s390xcap_P.pcc[1] & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X448))
|
|
|
3a273b |
+ return &ecx448_s390x_pkey_meth;
|
|
|
3a273b |
+#endif
|
|
|
3a273b |
+ return &ecx448_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *ed25519_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+#ifdef S390X_EC_ASM
|
|
|
3a273b |
+ if (OPENSSL_s390xcap_P.pcc[1] & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_ED25519)
|
|
|
3a273b |
+ && OPENSSL_s390xcap_P.kdsa[0] & S390X_CAPBIT(S390X_EDDSA_SIGN_ED25519)
|
|
|
3a273b |
+ && OPENSSL_s390xcap_P.kdsa[0]
|
|
|
3a273b |
+ & S390X_CAPBIT(S390X_EDDSA_VERIFY_ED25519))
|
|
|
3a273b |
+ return &ed25519_s390x_pkey_meth;
|
|
|
3a273b |
+#endif
|
|
|
3a273b |
+ return &ed25519_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *ed448_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+#ifdef S390X_EC_ASM
|
|
|
3a273b |
+ if (OPENSSL_s390xcap_P.pcc[1] & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_ED448)
|
|
|
3a273b |
+ && OPENSSL_s390xcap_P.kdsa[0] & S390X_CAPBIT(S390X_EDDSA_SIGN_ED448)
|
|
|
3a273b |
+ && OPENSSL_s390xcap_P.kdsa[0] & S390X_CAPBIT(S390X_EDDSA_VERIFY_ED448))
|
|
|
3a273b |
+ return &ed448_s390x_pkey_meth;
|
|
|
3a273b |
+#endif
|
|
|
3a273b |
+ return &ed448_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/err/openssl.txt.s390x-ecc openssl-1.1.1c/crypto/err/openssl.txt
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/err/openssl.txt.s390x-ecc 2019-11-20 11:36:02.158861012 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/err/openssl.txt 2019-11-20 11:36:02.196860345 +0100
|
|
|
3a273b |
@@ -495,6 +495,11 @@ EC_F_ECDSA_SIGN_EX:254:ECDSA_sign_ex
|
|
|
3a273b |
EC_F_ECDSA_SIGN_SETUP:248:ECDSA_sign_setup
|
|
|
3a273b |
EC_F_ECDSA_SIG_NEW:265:ECDSA_SIG_new
|
|
|
3a273b |
EC_F_ECDSA_VERIFY:253:ECDSA_verify
|
|
|
3a273b |
+EC_F_ECDSA_SIMPLE_SIGN_SETUP:310:ecdsa_simple_sign_setup
|
|
|
3a273b |
+EC_F_ECDSA_SIMPLE_SIGN_SIG:311:ecdsa_simple_sign_sig
|
|
|
3a273b |
+EC_F_ECDSA_SIMPLE_VERIFY_SIG:312:ecdsa_simple_verify_sig
|
|
|
3a273b |
+EC_F_ECDSA_S390X_NISTP_SIGN_SIG:313:ecdsa_s390x_nistp_sign_sig
|
|
|
3a273b |
+EC_F_ECDSA_S390X_NISTP_VERIFY_SIG:314:ecdsa_s390x_nistp_verify_sig
|
|
|
3a273b |
EC_F_ECD_ITEM_VERIFY:270:ecd_item_verify
|
|
|
3a273b |
EC_F_ECKEY_PARAM2TYPE:223:eckey_param2type
|
|
|
3a273b |
EC_F_ECKEY_PARAM_DECODE:212:eckey_param_decode
|
|
|
3a273b |
@@ -656,6 +661,7 @@ EC_F_NISTP521_PRE_COMP_NEW:237:nistp521_
|
|
|
3a273b |
EC_F_O2I_ECPUBLICKEY:152:o2i_ECPublicKey
|
|
|
3a273b |
EC_F_OLD_EC_PRIV_DECODE:222:old_ec_priv_decode
|
|
|
3a273b |
EC_F_OSSL_ECDH_COMPUTE_KEY:247:ossl_ecdh_compute_key
|
|
|
3a273b |
+EC_F_OSSL_ECDSA_SIGN_SETUP:300:ossl_ecdsa_sign_setup
|
|
|
3a273b |
EC_F_OSSL_ECDSA_SIGN_SIG:249:ossl_ecdsa_sign_sig
|
|
|
3a273b |
EC_F_OSSL_ECDSA_VERIFY_SIG:250:ossl_ecdsa_verify_sig
|
|
|
3a273b |
EC_F_PKEY_ECD_CTRL:271:pkey_ecd_ctrl
|
|
|
3a273b |
@@ -671,6 +677,12 @@ EC_F_PKEY_EC_KDF_DERIVE:283:pkey_ec_kdf_
|
|
|
3a273b |
EC_F_PKEY_EC_KEYGEN:199:pkey_ec_keygen
|
|
|
3a273b |
EC_F_PKEY_EC_PARAMGEN:219:pkey_ec_paramgen
|
|
|
3a273b |
EC_F_PKEY_EC_SIGN:218:pkey_ec_sign
|
|
|
3a273b |
+EC_F_S390X_PKEY_ECD_DIGESTSIGN25519:303:s390x_pkey_ecd_digestsign25519
|
|
|
3a273b |
+EC_F_S390X_PKEY_ECD_DIGESTSIGN448:304:s390x_pkey_ecd_digestsign448
|
|
|
3a273b |
+EC_F_S390X_PKEY_ECD_KEYGEN25519:305:s390x_pkey_ecd_keygen25519
|
|
|
3a273b |
+EC_F_S390X_PKEY_ECD_KEYGEN448:306:s390x_pkey_ecd_keygen448
|
|
|
3a273b |
+EC_F_S390X_PKEY_ECX_KEYGEN25519:307:s390x_pkey_ecx_keygen25519
|
|
|
3a273b |
+EC_F_S390X_PKEY_ECX_KEYGEN448:308:s390x_pkey_ecx_keygen448
|
|
|
3a273b |
EC_F_VALIDATE_ECX_DERIVE:278:validate_ecx_derive
|
|
|
3a273b |
ENGINE_F_DIGEST_UPDATE:198:digest_update
|
|
|
3a273b |
ENGINE_F_DYNAMIC_CTRL:180:dynamic_ctrl
|
|
|
3a273b |
@@ -2149,6 +2161,7 @@ EC_R_BUFFER_TOO_SMALL:100:buffer too sma
|
|
|
3a273b |
EC_R_CANNOT_INVERT:165:cannot invert
|
|
|
3a273b |
EC_R_COORDINATES_OUT_OF_RANGE:146:coordinates out of range
|
|
|
3a273b |
EC_R_CURVE_DOES_NOT_SUPPORT_ECDH:160:curve does not support ecdh
|
|
|
3a273b |
+EC_R_CURVE_DOES_NOT_SUPPORT_ECDSA:170:curve does not support ecdsa
|
|
|
3a273b |
EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING:159:curve does not support signing
|
|
|
3a273b |
EC_R_D2I_ECPKPARAMETERS_FAILURE:117:d2i ecpkparameters failure
|
|
|
3a273b |
EC_R_DECODE_ERROR:142:decode error
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/evp/pmeth_lib.c.s390x-ecc openssl-1.1.1c/crypto/evp/pmeth_lib.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/evp/pmeth_lib.c.s390x-ecc 2019-11-20 11:36:02.105861942 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/evp/pmeth_lib.c 2019-11-20 11:36:02.197860328 +0100
|
|
|
3a273b |
@@ -17,60 +17,67 @@
|
|
|
3a273b |
#include "internal/evp_int.h"
|
|
|
3a273b |
#include "internal/numbers.h"
|
|
|
3a273b |
|
|
|
3a273b |
+typedef const EVP_PKEY_METHOD *(*pmeth_fn)(void);
|
|
|
3a273b |
typedef int sk_cmp_fn_type(const char *const *a, const char *const *b);
|
|
|
3a273b |
|
|
|
3a273b |
static STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL;
|
|
|
3a273b |
|
|
|
3a273b |
/* This array needs to be in order of NIDs */
|
|
|
3a273b |
-static const EVP_PKEY_METHOD *standard_methods[] = {
|
|
|
3a273b |
+static pmeth_fn standard_methods[] = {
|
|
|
3a273b |
#ifndef OPENSSL_NO_RSA
|
|
|
3a273b |
- &rsa_pkey_meth,
|
|
|
3a273b |
+ rsa_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
#ifndef OPENSSL_NO_DH
|
|
|
3a273b |
- &dh_pkey_meth,
|
|
|
3a273b |
+ dh_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
#ifndef OPENSSL_NO_DSA
|
|
|
3a273b |
- &dsa_pkey_meth,
|
|
|
3a273b |
+ dsa_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
#ifndef OPENSSL_NO_EC
|
|
|
3a273b |
- &ec_pkey_meth,
|
|
|
3a273b |
+ ec_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
- &hmac_pkey_meth,
|
|
|
3a273b |
+ hmac_pkey_method,
|
|
|
3a273b |
#ifndef OPENSSL_NO_CMAC
|
|
|
3a273b |
- &cmac_pkey_meth,
|
|
|
3a273b |
+ cmac_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
#ifndef OPENSSL_NO_RSA
|
|
|
3a273b |
- &rsa_pss_pkey_meth,
|
|
|
3a273b |
+ rsa_pss_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
#ifndef OPENSSL_NO_DH
|
|
|
3a273b |
- &dhx_pkey_meth,
|
|
|
3a273b |
+ dhx_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
#ifndef OPENSSL_NO_SCRYPT
|
|
|
3a273b |
- &scrypt_pkey_meth,
|
|
|
3a273b |
+ scrypt_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
- &tls1_prf_pkey_meth,
|
|
|
3a273b |
+ tls1_prf_pkey_method,
|
|
|
3a273b |
#ifndef OPENSSL_NO_EC
|
|
|
3a273b |
- &ecx25519_pkey_meth,
|
|
|
3a273b |
- &ecx448_pkey_meth,
|
|
|
3a273b |
+ ecx25519_pkey_method,
|
|
|
3a273b |
+ ecx448_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
- &hkdf_pkey_meth,
|
|
|
3a273b |
+ hkdf_pkey_method,
|
|
|
3a273b |
#ifndef OPENSSL_NO_POLY1305
|
|
|
3a273b |
- &poly1305_pkey_meth,
|
|
|
3a273b |
+ poly1305_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
#ifndef OPENSSL_NO_SIPHASH
|
|
|
3a273b |
- &siphash_pkey_meth,
|
|
|
3a273b |
+ siphash_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
#ifndef OPENSSL_NO_EC
|
|
|
3a273b |
- &ed25519_pkey_meth,
|
|
|
3a273b |
- &ed448_pkey_meth,
|
|
|
3a273b |
+ ed25519_pkey_method,
|
|
|
3a273b |
+ ed448_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
#ifndef OPENSSL_NO_SM2
|
|
|
3a273b |
- &sm2_pkey_meth,
|
|
|
3a273b |
+ sm2_pkey_method,
|
|
|
3a273b |
#endif
|
|
|
3a273b |
};
|
|
|
3a273b |
|
|
|
3a273b |
-DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
|
|
|
3a273b |
- pmeth);
|
|
|
3a273b |
+DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, pmeth_fn, pmeth_func);
|
|
|
3a273b |
+
|
|
|
3a273b |
+static int pmeth_func_cmp(const EVP_PKEY_METHOD *const *a, pmeth_fn const *b)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return ((*a)->pkey_id - ((**b)())->pkey_id);
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, pmeth_fn, pmeth_func);
|
|
|
3a273b |
|
|
|
3a273b |
static int pmeth_cmp(const EVP_PKEY_METHOD *const *a,
|
|
|
3a273b |
const EVP_PKEY_METHOD *const *b)
|
|
|
3a273b |
@@ -78,13 +85,11 @@ static int pmeth_cmp(const EVP_PKEY_METH
|
|
|
3a273b |
return ((*a)->pkey_id - (*b)->pkey_id);
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
-IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
|
|
|
3a273b |
- pmeth);
|
|
|
3a273b |
-
|
|
|
3a273b |
const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
|
|
|
3a273b |
{
|
|
|
3a273b |
+ pmeth_fn *ret;
|
|
|
3a273b |
EVP_PKEY_METHOD tmp;
|
|
|
3a273b |
- const EVP_PKEY_METHOD *t = &tmp, **ret;
|
|
|
3a273b |
+ const EVP_PKEY_METHOD *t = &tm;;
|
|
|
3a273b |
tmp.pkey_id = type;
|
|
|
3a273b |
if (app_pkey_methods) {
|
|
|
3a273b |
int idx;
|
|
|
3a273b |
@@ -92,12 +97,12 @@ const EVP_PKEY_METHOD *EVP_PKEY_meth_fin
|
|
|
3a273b |
if (idx >= 0)
|
|
|
3a273b |
return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
|
|
|
3a273b |
}
|
|
|
3a273b |
- ret = OBJ_bsearch_pmeth(&t, standard_methods,
|
|
|
3a273b |
- sizeof(standard_methods) /
|
|
|
3a273b |
- sizeof(EVP_PKEY_METHOD *));
|
|
|
3a273b |
+ ret = OBJ_bsearch_pmeth_func(&t, standard_methods,
|
|
|
3a273b |
+ sizeof(standard_methods) /
|
|
|
3a273b |
+ sizeof(pmeth_fn));
|
|
|
3a273b |
if (!ret || !*ret)
|
|
|
3a273b |
return NULL;
|
|
|
3a273b |
- return *ret;
|
|
|
3a273b |
+ return (**ret)();
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
|
|
|
3a273b |
@@ -348,7 +353,7 @@ size_t EVP_PKEY_meth_get_count(void)
|
|
|
3a273b |
const EVP_PKEY_METHOD *EVP_PKEY_meth_get0(size_t idx)
|
|
|
3a273b |
{
|
|
|
3a273b |
if (idx < OSSL_NELEM(standard_methods))
|
|
|
3a273b |
- return standard_methods[idx];
|
|
|
3a273b |
+ return (standard_methods[idx])();
|
|
|
3a273b |
if (app_pkey_methods == NULL)
|
|
|
3a273b |
return NULL;
|
|
|
3a273b |
idx -= OSSL_NELEM(standard_methods);
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/hmac/hm_pmeth.c.s390x-ecc openssl-1.1.1c/crypto/hmac/hm_pmeth.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/hmac/hm_pmeth.c.s390x-ecc 2019-11-20 11:36:02.115861766 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/hmac/hm_pmeth.c 2019-11-20 11:36:02.197860328 +0100
|
|
|
3a273b |
@@ -210,3 +210,8 @@ const EVP_PKEY_METHOD hmac_pkey_meth = {
|
|
|
3a273b |
pkey_hmac_ctrl,
|
|
|
3a273b |
pkey_hmac_ctrl_str
|
|
|
3a273b |
};
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *hmac_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &hmac_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/include/internal/evp_int.h.s390x-ecc openssl-1.1.1c/crypto/include/internal/evp_int.h
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/include/internal/evp_int.h.s390x-ecc 2019-11-20 11:36:02.158861012 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/include/internal/evp_int.h 2019-11-20 11:36:02.197860328 +0100
|
|
|
3a273b |
@@ -459,3 +459,22 @@ void evp_encode_ctx_set_flags(EVP_ENCODE
|
|
|
3a273b |
#define EVP_ENCODE_CTX_NO_NEWLINES 1
|
|
|
3a273b |
/* Use the SRP base64 alphabet instead of the standard one */
|
|
|
3a273b |
#define EVP_ENCODE_CTX_USE_SRP_ALPHABET 2
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *cmac_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *dh_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *dhx_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *dsa_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *ec_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *sm2_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *ecx25519_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *ecx448_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *ed25519_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *ed448_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *hmac_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *rsa_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *rsa_pss_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *scrypt_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *tls1_prf_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *hkdf_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *poly1305_pkey_method(void);
|
|
|
3a273b |
+const EVP_PKEY_METHOD *siphash_pkey_method(void);
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/kdf/hkdf.c.s390x-ecc openssl-1.1.1c/crypto/kdf/hkdf.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/kdf/hkdf.c.s390x-ecc 2019-11-20 11:36:02.148861187 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/kdf/hkdf.c 2019-11-20 11:36:02.198860310 +0100
|
|
|
3a273b |
@@ -233,6 +233,11 @@ const EVP_KDF_METHOD hkdf_kdf_meth = {
|
|
|
3a273b |
kdf_hkdf_derive
|
|
|
3a273b |
};
|
|
|
3a273b |
|
|
|
3a273b |
+const EVP_PKEY_METHOD *hkdf_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &hkdf_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
static int HKDF(const EVP_MD *evp_md,
|
|
|
3a273b |
const unsigned char *salt, size_t salt_len,
|
|
|
3a273b |
const unsigned char *key, size_t key_len,
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/kdf/scrypt.c.s390x-ecc openssl-1.1.1c/crypto/kdf/scrypt.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/kdf/scrypt.c.s390x-ecc 2019-11-20 11:36:02.149861170 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/kdf/scrypt.c 2019-11-20 11:36:02.198860310 +0100
|
|
|
3a273b |
@@ -503,4 +503,9 @@ static int scrypt_alg(const char *pass,
|
|
|
3a273b |
return rv;
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
+const EVP_PKEY_METHOD *scrypt_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &scrypt_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
#endif
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/kdf/tls1_prf.c.s390x-ecc openssl-1.1.1c/crypto/kdf/tls1_prf.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/kdf/tls1_prf.c.s390x-ecc 2019-11-20 11:36:02.149861170 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/kdf/tls1_prf.c 2019-11-20 11:36:02.198860310 +0100
|
|
|
3a273b |
@@ -168,6 +168,11 @@ const EVP_KDF_METHOD tls1_prf_kdf_meth =
|
|
|
3a273b |
kdf_tls1_prf_derive
|
|
|
3a273b |
};
|
|
|
3a273b |
|
|
|
3a273b |
+const EVP_PKEY_METHOD *tls1_prf_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &tls1_prf_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
static int tls1_prf_P_hash(const EVP_MD *md,
|
|
|
3a273b |
const unsigned char *sec, size_t sec_len,
|
|
|
3a273b |
const unsigned char *seed, size_t seed_len,
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/poly1305/poly1305_pmeth.c.s390x-ecc openssl-1.1.1c/crypto/poly1305/poly1305_pmeth.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/poly1305/poly1305_pmeth.c.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/poly1305/poly1305_pmeth.c 2019-11-20 11:36:02.199860293 +0100
|
|
|
3a273b |
@@ -192,3 +192,8 @@ const EVP_PKEY_METHOD poly1305_pkey_meth
|
|
|
3a273b |
pkey_poly1305_ctrl,
|
|
|
3a273b |
pkey_poly1305_ctrl_str
|
|
|
3a273b |
};
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *poly1305_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &poly1305_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/rsa/rsa_pmeth.c.s390x-ecc openssl-1.1.1c/crypto/rsa/rsa_pmeth.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/rsa/rsa_pmeth.c.s390x-ecc 2019-11-20 11:36:02.117861731 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/rsa/rsa_pmeth.c 2019-11-20 11:36:02.199860293 +0100
|
|
|
3a273b |
@@ -789,6 +789,11 @@ const EVP_PKEY_METHOD rsa_pkey_meth = {
|
|
|
3a273b |
pkey_rsa_ctrl_str
|
|
|
3a273b |
};
|
|
|
3a273b |
|
|
|
3a273b |
+const EVP_PKEY_METHOD *rsa_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &rsa_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
/*
|
|
|
3a273b |
* Called for PSS sign or verify initialisation: checks PSS parameter
|
|
|
3a273b |
* sanity and sets any restrictions on key usage.
|
|
|
3a273b |
@@ -859,3 +864,8 @@ const EVP_PKEY_METHOD rsa_pss_pkey_meth
|
|
|
3a273b |
pkey_rsa_ctrl,
|
|
|
3a273b |
pkey_rsa_ctrl_str
|
|
|
3a273b |
};
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *rsa_pss_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &rsa_pss_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/s390x_arch.h.s390x-ecc openssl-1.1.1c/crypto/s390x_arch.h
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/s390x_arch.h.s390x-ecc 2019-11-20 11:36:01.867866116 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/s390x_arch.h 2019-11-20 11:36:02.199860293 +0100
|
|
|
3a273b |
@@ -26,6 +26,12 @@ void s390x_kmf(const unsigned char *in,
|
|
|
3a273b |
unsigned int fc, void *param);
|
|
|
3a273b |
void s390x_kma(const unsigned char *aad, size_t alen, const unsigned char *in,
|
|
|
3a273b |
size_t len, unsigned char *out, unsigned int fc, void *param);
|
|
|
3a273b |
+int s390x_pcc(unsigned int fc, void *param);
|
|
|
3a273b |
+int s390x_kdsa(unsigned int fc, void *param, const unsigned char *in,
|
|
|
3a273b |
+ size_t len);
|
|
|
3a273b |
+
|
|
|
3a273b |
+void s390x_flip_endian32(unsigned char dst[32], const unsigned char src[32]);
|
|
|
3a273b |
+void s390x_flip_endian64(unsigned char dst[64], const unsigned char src[64]);
|
|
|
3a273b |
|
|
|
3a273b |
/*
|
|
|
3a273b |
* The field elements of OPENSSL_s390xcap_P are the 64-bit words returned by
|
|
|
3a273b |
@@ -45,6 +51,8 @@ struct OPENSSL_s390xcap_st {
|
|
|
3a273b |
unsigned long long kmf[2];
|
|
|
3a273b |
unsigned long long prno[2];
|
|
|
3a273b |
unsigned long long kma[2];
|
|
|
3a273b |
+ unsigned long long pcc[2];
|
|
|
3a273b |
+ unsigned long long kdsa[2];
|
|
|
3a273b |
};
|
|
|
3a273b |
|
|
|
3a273b |
extern struct OPENSSL_s390xcap_st OPENSSL_s390xcap_P;
|
|
|
3a273b |
@@ -66,11 +74,14 @@ extern struct OPENSSL_s390xcap_st OPENSS
|
|
|
3a273b |
# define S390X_KMF 0x90
|
|
|
3a273b |
# define S390X_PRNO 0xa0
|
|
|
3a273b |
# define S390X_KMA 0xb0
|
|
|
3a273b |
+# define S390X_PCC 0xc0
|
|
|
3a273b |
+# define S390X_KDSA 0xd0
|
|
|
3a273b |
|
|
|
3a273b |
/* Facility Bit Numbers */
|
|
|
3a273b |
# define S390X_VX 129
|
|
|
3a273b |
# define S390X_VXD 134
|
|
|
3a273b |
# define S390X_VXE 135
|
|
|
3a273b |
+# define S390X_MSA9 155 /* message-security-assist-ext. 9 */
|
|
|
3a273b |
|
|
|
3a273b |
/* Function Codes */
|
|
|
3a273b |
|
|
|
3a273b |
@@ -94,10 +105,32 @@ extern struct OPENSSL_s390xcap_st OPENSS
|
|
|
3a273b |
/* prno */
|
|
|
3a273b |
# define S390X_TRNG 114
|
|
|
3a273b |
|
|
|
3a273b |
+/* pcc */
|
|
|
3a273b |
+# define S390X_SCALAR_MULTIPLY_P256 64
|
|
|
3a273b |
+# define S390X_SCALAR_MULTIPLY_P384 65
|
|
|
3a273b |
+# define S390X_SCALAR_MULTIPLY_P521 66
|
|
|
3a273b |
+# define S390X_SCALAR_MULTIPLY_ED25519 72
|
|
|
3a273b |
+# define S390X_SCALAR_MULTIPLY_ED448 73
|
|
|
3a273b |
+# define S390X_SCALAR_MULTIPLY_X25519 80
|
|
|
3a273b |
+# define S390X_SCALAR_MULTIPLY_X448 81
|
|
|
3a273b |
+
|
|
|
3a273b |
+/* kdsa */
|
|
|
3a273b |
+# define S390X_ECDSA_VERIFY_P256 1
|
|
|
3a273b |
+# define S390X_ECDSA_VERIFY_P384 2
|
|
|
3a273b |
+# define S390X_ECDSA_VERIFY_P521 3
|
|
|
3a273b |
+# define S390X_ECDSA_SIGN_P256 9
|
|
|
3a273b |
+# define S390X_ECDSA_SIGN_P384 10
|
|
|
3a273b |
+# define S390X_ECDSA_SIGN_P521 11
|
|
|
3a273b |
+# define S390X_EDDSA_VERIFY_ED25519 32
|
|
|
3a273b |
+# define S390X_EDDSA_VERIFY_ED448 36
|
|
|
3a273b |
+# define S390X_EDDSA_SIGN_ED25519 40
|
|
|
3a273b |
+# define S390X_EDDSA_SIGN_ED448 44
|
|
|
3a273b |
+
|
|
|
3a273b |
/* Register 0 Flags */
|
|
|
3a273b |
# define S390X_DECRYPT 0x80
|
|
|
3a273b |
# define S390X_KMA_LPC 0x100
|
|
|
3a273b |
# define S390X_KMA_LAAD 0x200
|
|
|
3a273b |
# define S390X_KMA_HS 0x400
|
|
|
3a273b |
+# define S390X_KDSA_D 0x80
|
|
|
3a273b |
|
|
|
3a273b |
#endif
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/s390xcpuid.pl.s390x-ecc openssl-1.1.1c/crypto/s390xcpuid.pl
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/s390xcpuid.pl.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/s390xcpuid.pl 2019-11-20 11:36:02.199860293 +0100
|
|
|
3a273b |
@@ -58,6 +58,10 @@ OPENSSL_s390x_facilities:
|
|
|
3a273b |
stg %r0,S390X_PRNO+8(%r4)
|
|
|
3a273b |
stg %r0,S390X_KMA(%r4)
|
|
|
3a273b |
stg %r0,S390X_KMA+8(%r4)
|
|
|
3a273b |
+ stg %r0,S390X_PCC(%r4)
|
|
|
3a273b |
+ stg %r0,S390X_PCC+8(%r4)
|
|
|
3a273b |
+ stg %r0,S390X_KDSA(%r4)
|
|
|
3a273b |
+ stg %r0,S390X_KDSA+8(%r4)
|
|
|
3a273b |
|
|
|
3a273b |
.long 0xb2b04000 # stfle 0(%r4)
|
|
|
3a273b |
brc 8,.Ldone
|
|
|
3a273b |
@@ -68,6 +72,7 @@ OPENSSL_s390x_facilities:
|
|
|
3a273b |
.long 0xb2b04000 # stfle 0(%r4)
|
|
|
3a273b |
.Ldone:
|
|
|
3a273b |
lmg %r2,%r3,S390X_STFLE(%r4)
|
|
|
3a273b |
+
|
|
|
3a273b |
tmhl %r2,0x4000 # check for message-security-assist
|
|
|
3a273b |
jz .Lret
|
|
|
3a273b |
|
|
|
3a273b |
@@ -91,6 +96,13 @@ OPENSSL_s390x_facilities:
|
|
|
3a273b |
la %r1,S390X_KMAC(%r4)
|
|
|
3a273b |
.long 0xb91e0042 # kmac %r4,%r2
|
|
|
3a273b |
|
|
|
3a273b |
+ tmhh %r3,0x0008 # check for message-security-assist-3
|
|
|
3a273b |
+ jz .Lret
|
|
|
3a273b |
+
|
|
|
3a273b |
+ lghi %r0,S390X_QUERY # query pcc capability vector
|
|
|
3a273b |
+ la %r1,S390X_PCC(%r4)
|
|
|
3a273b |
+ .long 0xb92c0000 # pcc
|
|
|
3a273b |
+
|
|
|
3a273b |
tmhh %r3,0x0004 # check for message-security-assist-4
|
|
|
3a273b |
jz .Lret
|
|
|
3a273b |
|
|
|
3a273b |
@@ -114,6 +126,7 @@ OPENSSL_s390x_facilities:
|
|
|
3a273b |
.long 0xb93c0042 # prno %r4,%r2
|
|
|
3a273b |
|
|
|
3a273b |
lg %r2,S390X_STFLE+16(%r4)
|
|
|
3a273b |
+
|
|
|
3a273b |
tmhl %r2,0x2000 # check for message-security-assist-8
|
|
|
3a273b |
jz .Lret
|
|
|
3a273b |
|
|
|
3a273b |
@@ -121,6 +134,13 @@ OPENSSL_s390x_facilities:
|
|
|
3a273b |
la %r1,S390X_KMA(%r4)
|
|
|
3a273b |
.long 0xb9294022 # kma %r2,%r4,%r2
|
|
|
3a273b |
|
|
|
3a273b |
+ tmhl %r2,0x0010 # check for message-security-assist-9
|
|
|
3a273b |
+ jz .Lret
|
|
|
3a273b |
+
|
|
|
3a273b |
+ lghi %r0,S390X_QUERY # query kdsa capability vector
|
|
|
3a273b |
+ la %r1,S390X_KDSA(%r4)
|
|
|
3a273b |
+ .long 0xb93a0002 # kdsa %r0,%r2
|
|
|
3a273b |
+
|
|
|
3a273b |
.Lret:
|
|
|
3a273b |
br $ra
|
|
|
3a273b |
.size OPENSSL_s390x_facilities,.-OPENSSL_s390x_facilities
|
|
|
3a273b |
@@ -411,6 +431,113 @@ s390x_kma:
|
|
|
3a273b |
___
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
+################
|
|
|
3a273b |
+# int s390x_pcc(unsigned int fc, void *param)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+my ($fc,$param) = map("%r$_",(2..3));
|
|
|
3a273b |
+$code.=<<___;
|
|
|
3a273b |
+.globl s390x_pcc
|
|
|
3a273b |
+.type s390x_pcc,\@function
|
|
|
3a273b |
+.align 16
|
|
|
3a273b |
+s390x_pcc:
|
|
|
3a273b |
+ lr %r0,$fc
|
|
|
3a273b |
+ l${g}r %r1,$param
|
|
|
3a273b |
+ lhi %r2,0
|
|
|
3a273b |
+
|
|
|
3a273b |
+ .long 0xb92c0000 # pcc
|
|
|
3a273b |
+ brc 1,.-4 # pay attention to "partial completion"
|
|
|
3a273b |
+ brc 7,.Lpcc_err # if CC==0 return 0, else return 1
|
|
|
3a273b |
+.Lpcc_out:
|
|
|
3a273b |
+ br $ra
|
|
|
3a273b |
+.Lpcc_err:
|
|
|
3a273b |
+ lhi %r2,1
|
|
|
3a273b |
+ j .Lpcc_out
|
|
|
3a273b |
+.size s390x_pcc,.-s390x_pcc
|
|
|
3a273b |
+___
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+################
|
|
|
3a273b |
+# int s390x_kdsa(unsigned int fc, void *param,
|
|
|
3a273b |
+# const unsigned char *in, size_t len)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+my ($fc,$param,$in,$len) = map("%r$_",(2..5));
|
|
|
3a273b |
+$code.=<<___;
|
|
|
3a273b |
+.globl s390x_kdsa
|
|
|
3a273b |
+.type s390x_kdsa,\@function
|
|
|
3a273b |
+.align 16
|
|
|
3a273b |
+s390x_kdsa:
|
|
|
3a273b |
+ lr %r0,$fc
|
|
|
3a273b |
+ l${g}r %r1,$param
|
|
|
3a273b |
+ lhi %r2,0
|
|
|
3a273b |
+
|
|
|
3a273b |
+ .long 0xb93a0004 # kdsa %r0,$in
|
|
|
3a273b |
+ brc 1,.-4 # pay attention to "partial completion"
|
|
|
3a273b |
+ brc 7,.Lkdsa_err # if CC==0 return 0, else return 1
|
|
|
3a273b |
+.Lkdsa_out:
|
|
|
3a273b |
+ br $ra
|
|
|
3a273b |
+.Lkdsa_err:
|
|
|
3a273b |
+ lhi %r2,1
|
|
|
3a273b |
+ j .Lkdsa_out
|
|
|
3a273b |
+.size s390x_kdsa,.-s390x_kdsa
|
|
|
3a273b |
+___
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+################
|
|
|
3a273b |
+# void s390x_flip_endian32(unsigned char dst[32], const unsigned char src[32])
|
|
|
3a273b |
+{
|
|
|
3a273b |
+my ($dst,$src) = map("%r$_",(2..3));
|
|
|
3a273b |
+$code.=<<___;
|
|
|
3a273b |
+.globl s390x_flip_endian32
|
|
|
3a273b |
+.type s390x_flip_endian32,\@function
|
|
|
3a273b |
+.align 16
|
|
|
3a273b |
+s390x_flip_endian32:
|
|
|
3a273b |
+ lrvg %r0,0(%r0,$src)
|
|
|
3a273b |
+ lrvg %r1,8(%r0,$src)
|
|
|
3a273b |
+ lrvg %r4,16(%r0,$src)
|
|
|
3a273b |
+ lrvg %r5,24(%r0,$src)
|
|
|
3a273b |
+ stg %r0,24(%r0,$dst)
|
|
|
3a273b |
+ stg %r1,16(%r0,$dst)
|
|
|
3a273b |
+ stg %r4,8(%r0,$dst)
|
|
|
3a273b |
+ stg %r5,0(%r0,$dst)
|
|
|
3a273b |
+ br $ra
|
|
|
3a273b |
+.size s390x_flip_endian32,.-s390x_flip_endian32
|
|
|
3a273b |
+___
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+################
|
|
|
3a273b |
+# void s390x_flip_endian64(unsigned char dst[64], const unsigned char src[64])
|
|
|
3a273b |
+{
|
|
|
3a273b |
+my ($dst,$src) = map("%r$_",(2..3));
|
|
|
3a273b |
+$code.=<<___;
|
|
|
3a273b |
+.globl s390x_flip_endian64
|
|
|
3a273b |
+.type s390x_flip_endian64,\@function
|
|
|
3a273b |
+.align 16
|
|
|
3a273b |
+s390x_flip_endian64:
|
|
|
3a273b |
+ stmg %r6,%r9,6*$SIZE_T($sp)
|
|
|
3a273b |
+
|
|
|
3a273b |
+ lrvg %r0,0(%r0,$src)
|
|
|
3a273b |
+ lrvg %r1,8(%r0,$src)
|
|
|
3a273b |
+ lrvg %r4,16(%r0,$src)
|
|
|
3a273b |
+ lrvg %r5,24(%r0,$src)
|
|
|
3a273b |
+ lrvg %r6,32(%r0,$src)
|
|
|
3a273b |
+ lrvg %r7,40(%r0,$src)
|
|
|
3a273b |
+ lrvg %r8,48(%r0,$src)
|
|
|
3a273b |
+ lrvg %r9,56(%r0,$src)
|
|
|
3a273b |
+ stg %r0,56(%r0,$dst)
|
|
|
3a273b |
+ stg %r1,48(%r0,$dst)
|
|
|
3a273b |
+ stg %r4,40(%r0,$dst)
|
|
|
3a273b |
+ stg %r5,32(%r0,$dst)
|
|
|
3a273b |
+ stg %r6,24(%r0,$dst)
|
|
|
3a273b |
+ stg %r7,16(%r0,$dst)
|
|
|
3a273b |
+ stg %r8,8(%r0,$dst)
|
|
|
3a273b |
+ stg %r9,0(%r0,$dst)
|
|
|
3a273b |
+
|
|
|
3a273b |
+ lmg %r6,%r9,6*$SIZE_T($sp)
|
|
|
3a273b |
+ br $ra
|
|
|
3a273b |
+.size s390x_flip_endian64,.-s390x_flip_endian64
|
|
|
3a273b |
+___
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
$code.=<<___;
|
|
|
3a273b |
.section .init
|
|
|
3a273b |
brasl $ra,OPENSSL_cpuid_setup
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/siphash/siphash_pmeth.c.s390x-ecc openssl-1.1.1c/crypto/siphash/siphash_pmeth.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/siphash/siphash_pmeth.c.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/siphash/siphash_pmeth.c 2019-11-20 11:36:02.200860275 +0100
|
|
|
3a273b |
@@ -203,3 +203,8 @@ const EVP_PKEY_METHOD siphash_pkey_meth
|
|
|
3a273b |
pkey_siphash_ctrl,
|
|
|
3a273b |
pkey_siphash_ctrl_str
|
|
|
3a273b |
};
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *siphash_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &siphash_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
diff -up openssl-1.1.1c/crypto/sm2/sm2_pmeth.c.s390x-ecc openssl-1.1.1c/crypto/sm2/sm2_pmeth.c
|
|
|
3a273b |
--- openssl-1.1.1c/crypto/sm2/sm2_pmeth.c.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/crypto/sm2/sm2_pmeth.c 2019-11-20 11:36:02.200860275 +0100
|
|
|
3a273b |
@@ -323,3 +323,8 @@ const EVP_PKEY_METHOD sm2_pkey_meth = {
|
|
|
3a273b |
|
|
|
3a273b |
pkey_sm2_digest_custom
|
|
|
3a273b |
};
|
|
|
3a273b |
+
|
|
|
3a273b |
+const EVP_PKEY_METHOD *sm2_pkey_method(void)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ return &sm2_pkey_meth;
|
|
|
3a273b |
+}
|
|
|
3a273b |
diff -up openssl-1.1.1c/include/internal/constant_time_locl.h.s390x-ecc openssl-1.1.1c/include/internal/constant_time_locl.h
|
|
|
3a273b |
--- openssl-1.1.1c/include/internal/constant_time_locl.h.s390x-ecc 2019-11-20 11:36:02.176860696 +0100
|
|
|
3a273b |
+++ openssl-1.1.1c/include/internal/constant_time_locl.h 2019-11-20 11:36:02.200860275 +0100
|
|
|
3a273b |
@@ -347,6 +347,34 @@ static ossl_inline void constant_time_co
|
|
|
3a273b |
}
|
|
|
3a273b |
|
|
|
3a273b |
/*
|
|
|
3a273b |
+ * mask must be 0xFF or 0x00.
|
|
|
3a273b |
+ * "constant time" is per len.
|
|
|
3a273b |
+ *
|
|
|
3a273b |
+ * if (mask) {
|
|
|
3a273b |
+ * unsigned char tmp[len];
|
|
|
3a273b |
+ *
|
|
|
3a273b |
+ * memcpy(tmp, a, len);
|
|
|
3a273b |
+ * memcpy(a, b);
|
|
|
3a273b |
+ * memcpy(b, tmp);
|
|
|
3a273b |
+ * }
|
|
|
3a273b |
+ */
|
|
|
3a273b |
+static ossl_inline void constant_time_cond_swap_buff(unsigned char mask,
|
|
|
3a273b |
+ unsigned char *a,
|
|
|
3a273b |
+ unsigned char *b,
|
|
|
3a273b |
+ size_t len)
|
|
|
3a273b |
+{
|
|
|
3a273b |
+ size_t i;
|
|
|
3a273b |
+ unsigned char tmp;
|
|
|
3a273b |
+
|
|
|
3a273b |
+ for (i = 0; i < len; i++) {
|
|
|
3a273b |
+ tmp = a[i] ^ b[i];
|
|
|
3a273b |
+ tmp &= mask;
|
|
|
3a273b |
+ a[i] ^= tmp;
|
|
|
3a273b |
+ b[i] ^= tmp;
|
|
|
3a273b |
+ }
|
|
|
3a273b |
+}
|
|
|
3a273b |
+
|
|
|
3a273b |
+/*
|
|
|
3a273b |
* table is a two dimensional array of bytes. Each row has rowsize elements.
|
|
|
3a273b |
* Copies row number idx into out. rowsize and numrows are not considered
|
|
|
3a273b |
* private.
|
|
|
3a273b |
diff -up openssl-1.1.1c/include/openssl/ecerr.h.s390x-ecc openssl-1.1.1c/include/openssl/ecerr.h
|
|
|
3a273b |
--- openssl-1.1.1c/include/openssl/ecerr.h.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/include/openssl/ecerr.h 2019-11-20 11:36:02.200860275 +0100
|
|
|
3a273b |
@@ -38,6 +38,11 @@ int ERR_load_EC_strings(void);
|
|
|
3a273b |
# define EC_F_ECDSA_SIGN_SETUP 248
|
|
|
3a273b |
# define EC_F_ECDSA_SIG_NEW 265
|
|
|
3a273b |
# define EC_F_ECDSA_VERIFY 253
|
|
|
3a273b |
+# define EC_F_ECDSA_SIMPLE_SIGN_SETUP 310
|
|
|
3a273b |
+# define EC_F_ECDSA_SIMPLE_SIGN_SIG 311
|
|
|
3a273b |
+# define EC_F_ECDSA_SIMPLE_VERIFY_SIG 312
|
|
|
3a273b |
+# define EC_F_ECDSA_S390X_NISTP_SIGN_SIG 313
|
|
|
3a273b |
+# define EC_F_ECDSA_S390X_NISTP_VERIFY_SIG 314
|
|
|
3a273b |
# define EC_F_ECD_ITEM_VERIFY 270
|
|
|
3a273b |
# define EC_F_ECKEY_PARAM2TYPE 223
|
|
|
3a273b |
# define EC_F_ECKEY_PARAM_DECODE 212
|
|
|
3a273b |
@@ -181,6 +186,7 @@ int ERR_load_EC_strings(void);
|
|
|
3a273b |
# define EC_F_O2I_ECPUBLICKEY 152
|
|
|
3a273b |
# define EC_F_OLD_EC_PRIV_DECODE 222
|
|
|
3a273b |
# define EC_F_OSSL_ECDH_COMPUTE_KEY 247
|
|
|
3a273b |
+# define EC_F_OSSL_ECDSA_SIGN_SETUP 300
|
|
|
3a273b |
# define EC_F_OSSL_ECDSA_SIGN_SIG 249
|
|
|
3a273b |
# define EC_F_OSSL_ECDSA_VERIFY_SIG 250
|
|
|
3a273b |
# define EC_F_PKEY_ECD_CTRL 271
|
|
|
3a273b |
@@ -196,6 +202,12 @@ int ERR_load_EC_strings(void);
|
|
|
3a273b |
# define EC_F_PKEY_EC_KEYGEN 199
|
|
|
3a273b |
# define EC_F_PKEY_EC_PARAMGEN 219
|
|
|
3a273b |
# define EC_F_PKEY_EC_SIGN 218
|
|
|
3a273b |
+# define EC_F_S390X_PKEY_ECD_DIGESTSIGN25519 320
|
|
|
3a273b |
+# define EC_F_S390X_PKEY_ECD_DIGESTSIGN448 321
|
|
|
3a273b |
+# define EC_F_S390X_PKEY_ECD_KEYGEN25519 322
|
|
|
3a273b |
+# define EC_F_S390X_PKEY_ECD_KEYGEN448 323
|
|
|
3a273b |
+# define EC_F_S390X_PKEY_ECX_KEYGEN25519 324
|
|
|
3a273b |
+# define EC_F_S390X_PKEY_ECX_KEYGEN448 325
|
|
|
3a273b |
# define EC_F_VALIDATE_ECX_DERIVE 278
|
|
|
3a273b |
|
|
|
3a273b |
/*
|
|
|
3a273b |
@@ -208,6 +220,7 @@ int ERR_load_EC_strings(void);
|
|
|
3a273b |
# define EC_R_CANNOT_INVERT 165
|
|
|
3a273b |
# define EC_R_COORDINATES_OUT_OF_RANGE 146
|
|
|
3a273b |
# define EC_R_CURVE_DOES_NOT_SUPPORT_ECDH 160
|
|
|
3a273b |
+# define EC_R_CURVE_DOES_NOT_SUPPORT_ECDSA 170
|
|
|
3a273b |
# define EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING 159
|
|
|
3a273b |
# define EC_R_D2I_ECPKPARAMETERS_FAILURE 117
|
|
|
3a273b |
# define EC_R_DECODE_ERROR 142
|
|
|
3a273b |
diff -up openssl-1.1.1c/test/recipes/30-test_evp_data/evppkey.txt.s390x-ecc openssl-1.1.1c/test/recipes/30-test_evp_data/evppkey.txt
|
|
|
3a273b |
--- openssl-1.1.1c/test/recipes/30-test_evp_data/evppkey.txt.s390x-ecc 2019-05-28 15:12:21.000000000 +0200
|
|
|
3a273b |
+++ openssl-1.1.1c/test/recipes/30-test_evp_data/evppkey.txt 2019-11-20 11:36:02.203860223 +0100
|
|
|
3a273b |
@@ -814,6 +814,8 @@ PublicKeyRaw=Bob-448-PUBLIC-Raw:X448:3eb
|
|
|
3a273b |
|
|
|
3a273b |
PrivPubKeyPair = Bob-448-Raw:Bob-448-PUBLIC-Raw
|
|
|
3a273b |
|
|
|
3a273b |
+PublicKeyRaw=Bob-448-PUBLIC-Raw-NonCanonical:X448:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
|
|
3a273b |
+
|
|
|
3a273b |
Derive=Alice-448
|
|
|
3a273b |
PeerKey=Bob-448-PUBLIC
|
|
|
3a273b |
SharedSecret=07fff4181ac6cc95ec1c16a94a0f74d12da232ce40a77552281d282bb60c0b56fd2464c335543936521c24403085d59a449a5037514a879d
|
|
|
3a273b |
@@ -830,6 +832,11 @@ Derive=Bob-448-Raw
|
|
|
3a273b |
PeerKey=Alice-448-PUBLIC-Raw
|
|
|
3a273b |
SharedSecret=07fff4181ac6cc95ec1c16a94a0f74d12da232ce40a77552281d282bb60c0b56fd2464c335543936521c24403085d59a449a5037514a879d
|
|
|
3a273b |
|
|
|
3a273b |
+# Self-generated non-canonical
|
|
|
3a273b |
+Derive=Alice-448-Raw
|
|
|
3a273b |
+PeerKey=Bob-448-PUBLIC-Raw-NonCanonical
|
|
|
3a273b |
+SharedSecret=66e2e682b1f8e68c809f1bb3e406bd826921d9c1a5bfbfcbab7ae72feecee63660eabd54934f3382061d17607f581a90bdac917a064959fb
|
|
|
3a273b |
+
|
|
|
3a273b |
# Illegal sign/verify operations with X448 key
|
|
|
3a273b |
|
|
|
3a273b |
Sign=Alice-448
|