Make the naming scheme for dispatched functions more consistent
[oweals/openssl.git] / providers / implementations / exchange / ecx_exch.c
index b7d1d9e3951247e7a94e48ac1326d429d9a373cc..4840b8802f1bcb31b353141a90104bdd36e6aaf6 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #include <openssl/crypto.h>
-#include <openssl/core_numbers.h>
+#include <openssl/core_dispatch.h>
 #include <openssl/core_names.h>
 #include <openssl/params.h>
 #include <openssl/err.h>
 #include "crypto/ecx.h"
 #include "prov/implementations.h"
 #include "prov/providercommonerr.h"
-
-static OSSL_OP_keyexch_newctx_fn x25519_newctx;
-static OSSL_OP_keyexch_newctx_fn x448_newctx;
-static OSSL_OP_keyexch_init_fn ecx_init;
-static OSSL_OP_keyexch_set_peer_fn ecx_set_peer;
-static OSSL_OP_keyexch_derive_fn ecx_derive;
-static OSSL_OP_keyexch_freectx_fn ecx_freectx;
-static OSSL_OP_keyexch_dupctx_fn ecx_dupctx;
+#ifdef S390X_EC_ASM
+# include "s390x_arch.h"
+#endif
+
+static OSSL_FUNC_keyexch_newctx_fn x25519_newctx;
+static OSSL_FUNC_keyexch_newctx_fn x448_newctx;
+static OSSL_FUNC_keyexch_init_fn ecx_init;
+static OSSL_FUNC_keyexch_set_peer_fn ecx_set_peer;
+static OSSL_FUNC_keyexch_derive_fn ecx_derive;
+static OSSL_FUNC_keyexch_freectx_fn ecx_freectx;
+static OSSL_FUNC_keyexch_dupctx_fn ecx_dupctx;
 
 /*
  * What's passed as an actual key is defined by the KEYMGMT interface.
@@ -126,11 +129,31 @@ static int ecx_derive(void *vecxctx, unsigned char *secret, size_t *secretlen,
     }
 
     if (ecxctx->keylen == X25519_KEYLEN) {
+#ifdef S390X_EC_ASM
+        if (OPENSSL_s390xcap_P.pcc[1]
+                & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X25519)) {
+            if (s390x_x25519_mul(secret, ecxctx->peerkey->pubkey,
+                                 ecxctx->key->privkey) == 0) {
+                ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
+                return 0;
+            }
+        } else
+#endif
         if (X25519(secret, ecxctx->key->privkey, ecxctx->peerkey->pubkey) == 0) {
             ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
             return 0;
         }
     } else {
+#ifdef S390X_EC_ASM
+        if (OPENSSL_s390xcap_P.pcc[1]
+                & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X448)) {
+            if (s390x_x448_mul(secret, ecxctx->peerkey->pubkey,
+                               ecxctx->key->privkey) == 0) {
+                ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
+                return 0;
+            }
+        } else
+#endif
         if (X448(secret, ecxctx->key->privkey, ecxctx->peerkey->pubkey) == 0) {
             ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
             return 0;