Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/cms/cms_dd.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||
2 | * Copyright 2008-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 "internal/cryptlib.h" | - | ||||||
11 | #include <openssl/asn1t.h> | - | ||||||
12 | #include <openssl/pem.h> | - | ||||||
13 | #include <openssl/x509v3.h> | - | ||||||
14 | #include <openssl/err.h> | - | ||||||
15 | #include <openssl/cms.h> | - | ||||||
16 | #include "cms_lcl.h" | - | ||||||
17 | - | |||||||
18 | /* CMS DigestedData Utilities */ | - | ||||||
19 | - | |||||||
20 | CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md) | - | ||||||
21 | { | - | ||||||
22 | CMS_ContentInfo *cms; | - | ||||||
23 | CMS_DigestedData *dd; | - | ||||||
24 | cms = CMS_ContentInfo_new(); | - | ||||||
25 | if (cms == NULL)
| 0 | ||||||
26 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
27 | - | |||||||
28 | dd = M_ASN1_new_of(CMS_DigestedData); | - | ||||||
29 | - | |||||||
30 | if (dd == NULL)
| 0 | ||||||
31 | goto err; never executed: goto err; | 0 | ||||||
32 | - | |||||||
33 | cms->contentType = OBJ_nid2obj(NID_pkcs7_digest); | - | ||||||
34 | cms->d.digestedData = dd; | - | ||||||
35 | - | |||||||
36 | dd->version = 0; | - | ||||||
37 | dd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data); | - | ||||||
38 | - | |||||||
39 | X509_ALGOR_set_md(dd->digestAlgorithm, md); | - | ||||||
40 | - | |||||||
41 | return cms; never executed: return cms; | 0 | ||||||
42 | - | |||||||
43 | err: | - | ||||||
44 | CMS_ContentInfo_free(cms); | - | ||||||
45 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
46 | } | - | ||||||
47 | - | |||||||
48 | BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms) | - | ||||||
49 | { | - | ||||||
50 | CMS_DigestedData *dd; | - | ||||||
51 | dd = cms->d.digestedData; | - | ||||||
52 | return cms_DigestAlgorithm_init_bio(dd->digestAlgorithm); never executed: return cms_DigestAlgorithm_init_bio(dd->digestAlgorithm); | 0 | ||||||
53 | } | - | ||||||
54 | - | |||||||
55 | int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify) | - | ||||||
56 | { | - | ||||||
57 | EVP_MD_CTX *mctx = EVP_MD_CTX_new(); | - | ||||||
58 | unsigned char md[EVP_MAX_MD_SIZE]; | - | ||||||
59 | unsigned int mdlen; | - | ||||||
60 | int r = 0; | - | ||||||
61 | CMS_DigestedData *dd; | - | ||||||
62 | - | |||||||
63 | if (mctx == NULL) {
| 0 | ||||||
64 | CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, ERR_R_MALLOC_FAILURE); | - | ||||||
65 | goto err; never executed: goto err; | 0 | ||||||
66 | } | - | ||||||
67 | - | |||||||
68 | dd = cms->d.digestedData; | - | ||||||
69 | - | |||||||
70 | if (!cms_DigestAlgorithm_find_ctx(mctx, chain, dd->digestAlgorithm))
| 0 | ||||||
71 | goto err; never executed: goto err; | 0 | ||||||
72 | - | |||||||
73 | if (EVP_DigestFinal_ex(mctx, md, &mdlen) <= 0)
| 0 | ||||||
74 | goto err; never executed: goto err; | 0 | ||||||
75 | - | |||||||
76 | if (verify) {
| 0 | ||||||
77 | if (mdlen != (unsigned int)dd->digest->length) {
| 0 | ||||||
78 | CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, | - | ||||||
79 | CMS_R_MESSAGEDIGEST_WRONG_LENGTH); | - | ||||||
80 | goto err; never executed: goto err; | 0 | ||||||
81 | } | - | ||||||
82 | - | |||||||
83 | if (memcmp(md, dd->digest->data, mdlen))
| 0 | ||||||
84 | CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, never executed: ERR_put_error(46,(117),(158),__FILE__,85) ; | 0 | ||||||
85 | CMS_R_VERIFICATION_FAILURE); never executed: ERR_put_error(46,(117),(158),__FILE__,85) ; | 0 | ||||||
86 | else | - | ||||||
87 | r = 1; never executed: r = 1; | 0 | ||||||
88 | } else { | - | ||||||
89 | if (!ASN1_STRING_set(dd->digest, md, mdlen))
| 0 | ||||||
90 | goto err; never executed: goto err; | 0 | ||||||
91 | r = 1; | - | ||||||
92 | } never executed: end of block | 0 | ||||||
93 | - | |||||||
94 | err: code before this statement never executed: err: | 0 | ||||||
95 | EVP_MD_CTX_free(mctx); | - | ||||||
96 | - | |||||||
97 | return r; never executed: return r; | 0 | ||||||
98 | - | |||||||
99 | } | - | ||||||
Source code | Switch to Preprocessed file |