ASN1_ITEM versions of sign, verify, pack and unpack.
[openssl.git] / crypto / asn1 / a_digest.c
index 8f395d958a2c2425bc0aa541d3ede31a1071116c..fb4686fdbd17c4dfcb7bd93cadb2e377108df8bf 100644 (file)
@@ -1,5 +1,5 @@
 /* crypto/asn1/a_digest.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * This package is an SSL implementation written
 
 #include <stdio.h>
 #include <time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 
 #include "cryptlib.h"
-#include "evp.h"
-#include "x509.h"
-#include "buffer.h"
 
-int ASN1_digest(i2d,type,data,md,len)
-int (*i2d)();
-EVP_MD *type;
-char *data;
-unsigned char *md;
-unsigned int *len;
+#ifndef NO_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#include <openssl/evp.h>
+#include <openssl/buffer.h>
+#include <openssl/x509.h>
+
+int ASN1_digest(int (*i2d)(), const EVP_MD *type, char *data,
+               unsigned char *md, unsigned int *len)
        {
        EVP_MD_CTX ctx;
        int i;
        unsigned char *str,*p;
 
        i=i2d(data,NULL);
-       if ((str=(unsigned char *)Malloc(i)) == NULL) return(0);
+       if ((str=(unsigned char *)OPENSSL_malloc(i)) == NULL) return(0);
        p=str;
        i2d(data,&p);
 
        EVP_DigestInit(&ctx,type);
        EVP_DigestUpdate(&ctx,str,i);
        EVP_DigestFinal(&ctx,md,len);
-       Free(str);
+       OPENSSL_free(str);
+       return(1);
+       }
+
+
+int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
+               unsigned char *md, unsigned int *len)
+       {
+       EVP_MD_CTX ctx;
+       int i;
+       unsigned char *str = NULL;
+
+       i=ASN1_item_i2d(asn,&str, it);
+       if (!str) return(0);
+
+       EVP_DigestInit(&ctx,type);
+       EVP_DigestUpdate(&ctx,str,i);
+       EVP_DigestFinal(&ctx,md,len);
+       OPENSSL_free(str);
        return(1);
        }