Add a cleanup function for MDs.
authorBen Laurie <ben@openssl.org>
Fri, 7 Sep 2001 12:03:24 +0000 (12:03 +0000)
committerBen Laurie <ben@openssl.org>
Fri, 7 Sep 2001 12:03:24 +0000 (12:03 +0000)
13 files changed:
crypto/evp/digest.c
crypto/evp/evp.h
crypto/evp/m_dss.c
crypto/evp/m_dss1.c
crypto/evp/m_md2.c
crypto/evp/m_md4.c
crypto/evp/m_md5.c
crypto/evp/m_mdc2.c
crypto/evp/m_null.c
crypto/evp/m_ripemd.c
crypto/evp/m_sha.c
crypto/evp/m_sha1.c
crypto/evp/openbsd_hw.c

index c81f6e6cf8e8410b2b7567453f9073e7d3a5fbaf..69a0bdbe3438952dcad42e5d763894b5040f1cb3 100644 (file)
@@ -165,6 +165,8 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
        /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
         * because sometimes only copies of the context are ever finalised.
         */
+       if(ctx->digest && ctx->digest->cleanup)
+               ctx->digest->cleanup(ctx);
        if(ctx->digest && ctx->digest->ctx_size && ctx->md_data)
                {
                memset(ctx->md_data,0,ctx->digest->ctx_size);
index 7f798388f0d9e16f5ac08fd76a1df170b2c5d5f8..de642c64c8546051f60748227833cfdb3bc7d114 100644 (file)
@@ -222,6 +222,7 @@ struct env_md_st
        int (*update)(EVP_MD_CTX *ctx,const void *data,unsigned long count);
        int (*final)(EVP_MD_CTX *ctx,unsigned char *md);
        int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from);
+       int (*cleanup)(EVP_MD_CTX *ctx);
 
        /* FIXME: prototype these some day */
        int (*sign)();
index f50b35b07239c0e0427302c127d4f843e601e7e8..beb8d7fc5c934b36ac26062a789e544bd3b82a6b 100644 (file)
@@ -82,6 +82,7 @@ static const EVP_MD dsa_md=
        update,
        final,
        NULL,
+       NULL,
        EVP_PKEY_DSA_method,
        SHA_CBLOCK,
        sizeof(EVP_MD *)+sizeof(SHA_CTX),
index be27d63da05946568690317fa571b210284a2fe9..f5668ebda0a0033d2d3fd581f68dc46a236a6ce5 100644 (file)
@@ -82,6 +82,7 @@ static const EVP_MD dss1_md=
        update,
        final,
        NULL,
+       NULL,
        EVP_PKEY_DSA_method,
        SHA_CBLOCK,
        sizeof(EVP_MD *)+sizeof(SHA_CTX),
index 8f95541c6a30af69cdf24574d88994ff3dc8ef37..50914c83b3afaadaef388b5a4f7bbf18fd04e441 100644 (file)
@@ -83,6 +83,7 @@ static const EVP_MD md2_md=
        update,
        final,
        NULL,
+       NULL,
        EVP_PKEY_RSA_method,
        MD2_BLOCK,
        sizeof(EVP_MD *)+sizeof(MD2_CTX),
index 11458ee1cd4d77b366d01ea0ed91aebaad1bd0ba..8565e5d529baceb0f0708e11da161a0950a689d9 100644 (file)
@@ -83,6 +83,7 @@ static const EVP_MD md4_md=
        update,
        final,
        NULL,
+       NULL,
        EVP_PKEY_RSA_method,
        MD4_CBLOCK,
        sizeof(EVP_MD *)+sizeof(MD4_CTX),
index 69ec8aa027fa13d07577b0c9cc8dba7ef7eea550..b00a03e048b605d8e4dd4f5600af3e696ddaf3a2 100644 (file)
@@ -83,6 +83,7 @@ static const EVP_MD md5_md=
        update,
        final,
        NULL,
+       NULL,
        EVP_PKEY_RSA_method,
        MD5_CBLOCK,
        sizeof(EVP_MD *)+sizeof(MD5_CTX),
index d36a6e30b9724535b079dd9c77ab2d32480451f4..9f6467c931439415774dd70f528cb34c1d528f5a 100644 (file)
@@ -83,6 +83,7 @@ static const EVP_MD mdc2_md=
        update,
        final,
        NULL,
+       NULL,
        EVP_PKEY_RSA_ASN1_OCTET_STRING_method,
        MDC2_BLOCK,
        sizeof(EVP_MD *)+sizeof(MDC2_CTX),
index fa3a0301d974e98c86cf6ca2206349e1cd11fd49..f6f0a1d2c05f1abdf15ec79f8e493134a7d06e6c 100644 (file)
@@ -81,6 +81,7 @@ static const EVP_MD null_md=
        update,
        final,
        NULL,
+       NULL,
        EVP_PKEY_NULL_method,
        0,
        sizeof(EVP_MD *),
index 0bfc04c12fa9042e9dfc0f886db9564b4a5831cc..64725528dcc0492c8e04fd3e83ff9fd4d0330085 100644 (file)
@@ -83,6 +83,7 @@ static const EVP_MD ripemd160_md=
        update,
        final,
        NULL,
+       NULL,
        EVP_PKEY_RSA_method,
        RIPEMD160_CBLOCK,
        sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX),
index acb7a44c5ebe49cc2b93d4fd94fe9b5fced76fc7..10697c7ed38261444f1a8e6eb91e1f76d0b347a2 100644 (file)
@@ -82,6 +82,7 @@ static const EVP_MD sha_md=
        update,
        final,
        NULL,
+       NULL,
        EVP_PKEY_RSA_method,
        SHA_CBLOCK,
        sizeof(EVP_MD *)+sizeof(SHA_CTX),
index ea54adad5b927ab63af81b6ef6bbfc73fbf68d79..d6be3502f0a2b0aa7012258a3f484533140fdb8a 100644 (file)
@@ -82,6 +82,7 @@ static const EVP_MD sha1_md=
        update,
        final,
        NULL,
+       NULL,
        EVP_PKEY_RSA_method,
        SHA_CBLOCK,
        sizeof(EVP_MD *)+sizeof(SHA_CTX),
index 550145e4948b2d1638ae842f502e5af64d08bcb9..2e4ad10560db8606e53ab5cd151e9467d4c23f20 100644 (file)
@@ -291,6 +291,17 @@ static int dev_crypto_init_digest(MD_DATA *md_data,int mac)
     return 1;
     }
 
+static int dev_crypto_cleanup_digest(MD_DATA *md_data)
+    {
+    if (ioctl(fd,CIOCFSESSION,&md_data->sess.ses) == -1)
+       {
+       err("CIOCFSESSION failed");
+       return 0;
+       }
+
+    return 1;
+    }
+
 /* FIXME: if device can do chained MACs, then don't accumulate */
 /* FIXME: move accumulation to the framework */
 static int dev_crypto_md5_init(EVP_MD_CTX *ctx)
@@ -346,7 +357,7 @@ static int do_digest(int ses,unsigned char *md,const void *data,int len)
            return 0;
            }
        }
-    printf("done\n");
+    //    printf("done\n");
 
     return 1;
     }
@@ -374,13 +385,15 @@ static int dev_crypto_md5_final(EVP_MD_CTX *ctx,unsigned char *md)
     if(ctx->flags&EVP_MD_CTX_FLAG_ONESHOT)
        {
        memcpy(md,md_data->md,MD5_DIGEST_LENGTH);
-       return 1;
+       ret=1;
+       }
+    else
+       {
+       ret=do_digest(md_data->sess.ses,md,md_data->data,md_data->len);
+       OPENSSL_free(md_data->data);
+       md_data->data=NULL;
+       md_data->len=0;
        }
-
-    ret=do_digest(md_data->sess.ses,md,md_data->data,md_data->len);
-    OPENSSL_free(md_data->data);
-    md_data->data=NULL;
-    md_data->len=0;
 
     return ret;
     }
@@ -399,6 +412,11 @@ static int dev_crypto_md5_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from)
     return 1;
     }
 
+static int dev_crypto_md5_cleanup(EVP_MD_CTX *ctx)
+    {
+    return dev_crypto_cleanup_digest(ctx->md_data);
+    }
+
 static const EVP_MD md5_md=
     {
     NID_md5,
@@ -409,6 +427,7 @@ static const EVP_MD md5_md=
     dev_crypto_md5_update,
     dev_crypto_md5_final,
     dev_crypto_md5_copy,
+    dev_crypto_md5_cleanup,
     EVP_PKEY_RSA_method,
     MD5_CBLOCK,
     sizeof(MD_DATA),