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