/src/boringssl/crypto/x509/a_digest.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include <openssl/x509.h> |
16 | | |
17 | | #include <openssl/asn1.h> |
18 | | #include <openssl/digest.h> |
19 | | #include <openssl/err.h> |
20 | | #include <openssl/mem.h> |
21 | | |
22 | | int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data, |
23 | 0 | unsigned char *md, unsigned int *len) { |
24 | 0 | int i, ret; |
25 | 0 | unsigned char *str, *p; |
26 | |
|
27 | 0 | i = i2d(data, NULL); |
28 | 0 | if ((str = (unsigned char *)OPENSSL_malloc(i)) == NULL) { |
29 | 0 | return 0; |
30 | 0 | } |
31 | 0 | p = str; |
32 | 0 | i2d(data, &p); |
33 | |
|
34 | 0 | ret = EVP_Digest(str, i, md, len, type, NULL); |
35 | 0 | OPENSSL_free(str); |
36 | 0 | return ret; |
37 | 0 | } |
38 | | |
39 | | int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, |
40 | 0 | unsigned char *md, unsigned int *len) { |
41 | 0 | int i, ret; |
42 | 0 | unsigned char *str = NULL; |
43 | |
|
44 | 0 | i = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(asn), &str, it); |
45 | 0 | if (!str) { |
46 | 0 | return 0; |
47 | 0 | } |
48 | | |
49 | 0 | ret = EVP_Digest(str, i, md, len, type, NULL); |
50 | 0 | OPENSSL_free(str); |
51 | 0 | return ret; |
52 | 0 | } |