Make EVP_Encrypt*/EVP_Decrypt* and EVP_Cipher* provider aware
[openssl.git] / crypto / evp / digest.c
index 89f8e54a91b232b40e278dac7dde71b4929c2fa6..043e45629760eeba7fd24df9752fd9f4bed21269 100644 (file)
@@ -145,6 +145,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
     if (type->prov == NULL) {
         switch(type->type) {
         case NID_sha256:
+        case NID_md2:
             break;
         default:
             goto legacy;
@@ -294,6 +295,7 @@ int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *isize)
 {
     int ret;
     size_t size = 0;
+    size_t mdsize = EVP_MD_size(ctx->digest);
 
     if (ctx->digest == NULL || ctx->digest->prov == NULL)
         goto legacy;
@@ -303,7 +305,7 @@ int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *isize)
         return 0;
     }
 
-    ret = ctx->digest->dfinal(ctx->provctx, md, &size);
+    ret = ctx->digest->dfinal(ctx->provctx, md, &size, mdsize);
 
     if (isize != NULL) {
         if (size <= UINT_MAX) {
@@ -320,10 +322,10 @@ int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *isize)
 
     /* TODO(3.0): Remove legacy code below */
  legacy:
-    OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE);
+    OPENSSL_assert(mdsize <= EVP_MAX_MD_SIZE);
     ret = ctx->digest->final(ctx, md);
     if (isize != NULL)
-        *isize = ctx->digest->md_size;
+        *isize = mdsize;
     if (ctx->digest->cleanup) {
         ctx->digest->cleanup(ctx);
         EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);
@@ -515,7 +517,7 @@ static void *evp_md_from_dispatch(int mdtype, const OSSL_DISPATCH *fns,
             md->dinit = OSSL_get_OP_digest_init(fns);
             fncnt++;
             break;
-        case OSSL_FUNC_DIGEST_UPDDATE:
+        case OSSL_FUNC_DIGEST_UPDATE:
             if (md->dupdate != NULL)
                 break;
             md->dupdate = OSSL_get_OP_digest_update(fns);
@@ -549,6 +551,11 @@ static void *evp_md_from_dispatch(int mdtype, const OSSL_DISPATCH *fns,
                 break;
             md->size = OSSL_get_OP_digest_size(fns);
             break;
+        case OSSL_FUNC_DIGEST_BLOCK_SIZE:
+            if (md->dblock_size != NULL)
+                break;
+            md->dblock_size = OSSL_get_OP_digest_block_size(fns);
+            break;
         }
     }
     if ((fncnt != 0 && fncnt != 5)
@@ -580,10 +587,17 @@ static void evp_md_free(void *md)
     EVP_MD_meth_free(md);
 }
 
+static int evp_md_nid(void *vmd)
+{
+    EVP_MD *md = vmd;
+
+    return md->type;
+}
+
 EVP_MD *EVP_MD_fetch(OPENSSL_CTX *ctx, const char *algorithm,
                      const char *properties)
 {
     return evp_generic_fetch(ctx, OSSL_OP_DIGEST, algorithm, properties,
                              evp_md_from_dispatch, evp_md_upref,
-                             evp_md_free);
+                             evp_md_free, evp_md_nid);
 }