Update copyright year
[openssl.git] / providers / implementations / exchange / ecx_exch.c
index 4840b8802f1bcb31b353141a90104bdd36e6aaf6..17118f0e6cd5ab3f37d8182a9e5abc9aa3805f55 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
 #include <openssl/core_names.h>
 #include <openssl/params.h>
 #include <openssl/err.h>
+#include <openssl/proverr.h>
 #include "internal/cryptlib.h"
 #include "crypto/ecx.h"
 #include "prov/implementations.h"
-#include "prov/providercommonerr.h"
+#include "prov/providercommon.h"
 #ifdef S390X_EC_ASM
 # include "s390x_arch.h"
 #endif
@@ -42,8 +43,12 @@ typedef struct {
 
 static void *ecx_newctx(void *provctx, size_t keylen)
 {
-    PROV_ECX_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_ECX_CTX));
+    PROV_ECX_CTX *ctx;
 
+    if (!ossl_prov_is_running())
+        return NULL;
+
+    ctx = OPENSSL_zalloc(sizeof(PROV_ECX_CTX));
     if (ctx == NULL) {
         ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
         return NULL;
@@ -69,6 +74,9 @@ static int ecx_init(void *vecxctx, void *vkey)
     PROV_ECX_CTX *ecxctx = (PROV_ECX_CTX *)vecxctx;
     ECX_KEY *key = vkey;
 
+    if (!ossl_prov_is_running())
+        return 0;
+
     if (ecxctx == NULL
             || key == NULL
             || key->keylen != ecxctx->keylen
@@ -88,6 +96,9 @@ static int ecx_set_peer(void *vecxctx, void *vkey)
     PROV_ECX_CTX *ecxctx = (PROV_ECX_CTX *)vecxctx;
     ECX_KEY *key = vkey;
 
+    if (!ossl_prov_is_running())
+        return 0;
+
     if (ecxctx == NULL
             || key == NULL
             || key->keylen != ecxctx->keylen
@@ -106,6 +117,9 @@ static int ecx_derive(void *vecxctx, unsigned char *secret, size_t *secretlen,
 {
     PROV_ECX_CTX *ecxctx = (PROV_ECX_CTX *)vecxctx;
 
+    if (!ossl_prov_is_running())
+        return 0;
+
     if (ecxctx->key == NULL
             || ecxctx->key->privkey == NULL
             || ecxctx->peerkey == NULL) {
@@ -179,6 +193,9 @@ static void *ecx_dupctx(void *vecxctx)
     PROV_ECX_CTX *srcctx = (PROV_ECX_CTX *)vecxctx;
     PROV_ECX_CTX *dstctx;
 
+    if (!ossl_prov_is_running())
+        return NULL;
+
     dstctx = OPENSSL_zalloc(sizeof(*srcctx));
     if (dstctx == NULL) {
         ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
@@ -202,7 +219,7 @@ static void *ecx_dupctx(void *vecxctx)
     return dstctx;
 }
 
-const OSSL_DISPATCH x25519_keyexch_functions[] = {
+const OSSL_DISPATCH ossl_x25519_keyexch_functions[] = {
     { OSSL_FUNC_KEYEXCH_NEWCTX, (void (*)(void))x25519_newctx },
     { OSSL_FUNC_KEYEXCH_INIT, (void (*)(void))ecx_init },
     { OSSL_FUNC_KEYEXCH_DERIVE, (void (*)(void))ecx_derive },
@@ -212,7 +229,7 @@ const OSSL_DISPATCH x25519_keyexch_functions[] = {
     { 0, NULL }
 };
 
-const OSSL_DISPATCH x448_keyexch_functions[] = {
+const OSSL_DISPATCH ossl_x448_keyexch_functions[] = {
     { OSSL_FUNC_KEYEXCH_NEWCTX, (void (*)(void))x448_newctx },
     { OSSL_FUNC_KEYEXCH_INIT, (void (*)(void))ecx_init },
     { OSSL_FUNC_KEYEXCH_DERIVE, (void (*)(void))ecx_derive },