]>
Commit | Line | Data |
---|---|---|
2039c421 RS |
1 | /* |
2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. | |
d02b48c6 | 3 | * |
2039c421 RS |
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 | |
d02b48c6 RE |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
11 | #include <time.h> | |
d02b48c6 | 12 | |
b39fc560 | 13 | #include "internal/cryptlib.h" |
17f389bb AP |
14 | |
15 | #ifndef NO_SYS_TYPES_H | |
16 | # include <sys/types.h> | |
17 | #endif | |
18 | ||
a0e7c8ee | 19 | #include <openssl/err.h> |
ec577822 | 20 | #include <openssl/evp.h> |
ec577822 | 21 | #include <openssl/buffer.h> |
1d5edd08 | 22 | #include <openssl/x509.h> |
d02b48c6 | 23 | |
73e92de5 DSH |
24 | #ifndef NO_ASN1_OLD |
25 | ||
8bb826ee | 26 | int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data, |
0f113f3e MC |
27 | unsigned char *md, unsigned int *len) |
28 | { | |
29 | int i; | |
30 | unsigned char *str, *p; | |
d02b48c6 | 31 | |
0f113f3e | 32 | i = i2d(data, NULL); |
b196e7d9 | 33 | if ((str = OPENSSL_malloc(i)) == NULL) { |
0f113f3e MC |
34 | ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE); |
35 | return (0); | |
36 | } | |
37 | p = str; | |
38 | i2d(data, &p); | |
d02b48c6 | 39 | |
0f113f3e MC |
40 | if (!EVP_Digest(str, i, md, len, type, NULL)) |
41 | return 0; | |
42 | OPENSSL_free(str); | |
43 | return (1); | |
44 | } | |
d02b48c6 | 45 | |
73e92de5 DSH |
46 | #endif |
47 | ||
09ab755c | 48 | int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, |
0f113f3e MC |
49 | unsigned char *md, unsigned int *len) |
50 | { | |
51 | int i; | |
52 | unsigned char *str = NULL; | |
09ab755c | 53 | |
0f113f3e MC |
54 | i = ASN1_item_i2d(asn, &str, it); |
55 | if (!str) | |
56 | return (0); | |
09ab755c | 57 | |
0f113f3e MC |
58 | if (!EVP_Digest(str, i, md, len, type, NULL)) |
59 | return 0; | |
60 | OPENSSL_free(str); | |
61 | return (1); | |
62 | } |