]> git.ipfire.org Git - thirdparty/openssl.git/blobdiff - providers/implementations/signature/eddsa.c
signature: add FIPS error state handling
[thirdparty/openssl.git] / providers / implementations / signature / eddsa.c
index 4ecc5266e2d0dddea970ab3f04095365a9d870ab..eda5ae1e60b87e19461fd64ecc52b19711f4269b 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/err.h>
 #include <openssl/params.h>
 #include <openssl/err.h>
 #include "internal/nelem.h"
 #include "internal/sizes.h"
-#include "prov/providercommonerr.h"
+#include "prov/providercommon.h"
 #include "prov/implementations.h"
 #include "prov/providercommonerr.h"
 #include "prov/provider_ctx.h"
 #include "crypto/ecx.h"
 
-static OSSL_OP_signature_newctx_fn eddsa_newctx;
-static OSSL_OP_signature_digest_sign_init_fn eddsa_digest_signverify_init;
-static OSSL_OP_signature_digest_sign_fn ed25519_digest_sign;
-static OSSL_OP_signature_digest_sign_fn ed448_digest_sign;
-static OSSL_OP_signature_digest_verify_fn ed25519_digest_verify;
-static OSSL_OP_signature_digest_verify_fn ed448_digest_verify;
-static OSSL_OP_signature_freectx_fn eddsa_freectx;
-static OSSL_OP_signature_dupctx_fn eddsa_dupctx;
+static OSSL_FUNC_signature_newctx_fn eddsa_newctx;
+static OSSL_FUNC_signature_digest_sign_init_fn eddsa_digest_signverify_init;
+static OSSL_FUNC_signature_digest_sign_fn ed25519_digest_sign;
+static OSSL_FUNC_signature_digest_sign_fn ed448_digest_sign;
+static OSSL_FUNC_signature_digest_verify_fn ed25519_digest_verify;
+static OSSL_FUNC_signature_digest_verify_fn ed448_digest_verify;
+static OSSL_FUNC_signature_freectx_fn eddsa_freectx;
+static OSSL_FUNC_signature_dupctx_fn eddsa_dupctx;
 
 typedef struct {
     OPENSSL_CTX *libctx;
@@ -38,8 +38,12 @@ typedef struct {
 
 static void *eddsa_newctx(void *provctx, const char *propq_unused)
 {
-    PROV_EDDSA_CTX *peddsactx = OPENSSL_zalloc(sizeof(PROV_EDDSA_CTX));
+    PROV_EDDSA_CTX *peddsactx;
+
+    if (!ossl_prov_is_running())
+        return NULL;
 
+    peddsactx = OPENSSL_zalloc(sizeof(PROV_EDDSA_CTX));
     if (peddsactx == NULL) {
         PROVerr(0, ERR_R_MALLOC_FAILURE);
         return NULL;
@@ -56,7 +60,10 @@ static int eddsa_digest_signverify_init(void *vpeddsactx, const char *mdname,
     PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
     ECX_KEY *edkey = (ECX_KEY *)vedkey;
 
-    if (mdname != NULL) {
+    if (!ossl_prov_is_running())
+        return 0;
+
+    if (mdname != NULL && mdname[0] != '\0') {
         PROVerr(0, PROV_R_INVALID_DIGEST);
         return 0;
     }
@@ -78,6 +85,9 @@ int ed25519_digest_sign(void *vpeddsactx, unsigned char *sigret,
     PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
     const ECX_KEY *edkey = peddsactx->key;
 
+    if (!ossl_prov_is_running())
+        return 0;
+
     if (sigret == NULL) {
         *siglen = ED25519_SIGSIZE;
         return 1;
@@ -103,6 +113,9 @@ int ed448_digest_sign(void *vpeddsactx, unsigned char *sigret,
     PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
     const ECX_KEY *edkey = peddsactx->key;
 
+    if (!ossl_prov_is_running())
+        return 0;
+
     if (sigret == NULL) {
         *siglen = ED448_SIGSIZE;
         return 1;
@@ -128,7 +141,7 @@ int ed25519_digest_verify(void *vpeddsactx, const unsigned char *sig,
     PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
     const ECX_KEY *edkey = peddsactx->key;
 
-    if (siglen != ED25519_SIGSIZE)
+    if (!ossl_prov_is_running() || siglen != ED25519_SIGSIZE)
         return 0;
 
     return ED25519_verify(tbs, tbslen, sig, edkey->pubkey, peddsactx->libctx,
@@ -142,7 +155,7 @@ int ed448_digest_verify(void *vpeddsactx, const unsigned char *sig,
     PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
     const ECX_KEY *edkey = peddsactx->key;
 
-    if (siglen != ED448_SIGSIZE)
+    if (!ossl_prov_is_running() || siglen != ED448_SIGSIZE)
         return 0;
 
     return ED448_verify(peddsactx->libctx, tbs, tbslen, sig, edkey->pubkey,
@@ -163,6 +176,9 @@ static void *eddsa_dupctx(void *vpeddsactx)
     PROV_EDDSA_CTX *srcctx = (PROV_EDDSA_CTX *)vpeddsactx;
     PROV_EDDSA_CTX *dstctx;
 
+    if (!ossl_prov_is_running())
+        return NULL;
+
     dstctx = OPENSSL_zalloc(sizeof(*srcctx));
     if (dstctx == NULL)
         return NULL;