Add missing include of cryptlib.h
[openssl.git] / crypto / asn1 / a_digest.c
1 /*
2  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include <stdio.h>
11 #include <time.h>
12
13 #include "internal/cryptlib.h"
14
15 #ifndef NO_SYS_TYPES_H
16 # include <sys/types.h>
17 #endif
18
19 #include <openssl/err.h>
20 #include <openssl/evp.h>
21 #include <openssl/buffer.h>
22 #include <openssl/x509.h>
23
24 #ifndef NO_ASN1_OLD
25
26 int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
27                 unsigned char *md, unsigned int *len)
28 {
29     int i;
30     unsigned char *str, *p;
31
32     i = i2d(data, NULL);
33     if ((str = OPENSSL_malloc(i)) == NULL) {
34         ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE);
35         return (0);
36     }
37     p = str;
38     i2d(data, &p);
39
40     if (!EVP_Digest(str, i, md, len, type, NULL)) {
41         OPENSSL_free(str);
42         return 0;
43     }
44     OPENSSL_free(str);
45     return (1);
46 }
47
48 #endif
49
50 int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
51                      unsigned char *md, unsigned int *len)
52 {
53     int i;
54     unsigned char *str = NULL;
55
56     i = ASN1_item_i2d(asn, &str, it);
57     if (!str)
58         return (0);
59
60     if (!EVP_Digest(str, i, md, len, type, NULL)) {
61         OPENSSL_free(str);
62         return 0;
63     }
64     OPENSSL_free(str);
65     return (1);
66 }