summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/cms/cms_dd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/cms/cms_dd.c')
-rw-r--r--src/lib/libcrypto/cms/cms_dd.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/src/lib/libcrypto/cms/cms_dd.c b/src/lib/libcrypto/cms/cms_dd.c
index 8919c15be1..f115d2274b 100644
--- a/src/lib/libcrypto/cms/cms_dd.c
+++ b/src/lib/libcrypto/cms/cms_dd.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -63,10 +63,12 @@ DECLARE_ASN1_ITEM(CMS_DigestedData)
63 63
64/* CMS DigestedData Utilities */ 64/* CMS DigestedData Utilities */
65 65
66CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md) 66CMS_ContentInfo *
67 { 67cms_DigestedData_create(const EVP_MD *md)
68{
68 CMS_ContentInfo *cms; 69 CMS_ContentInfo *cms;
69 CMS_DigestedData *dd; 70 CMS_DigestedData *dd;
71
70 cms = CMS_ContentInfo_new(); 72 cms = CMS_ContentInfo_new();
71 if (!cms) 73 if (!cms)
72 return NULL; 74 return NULL;
@@ -86,28 +88,30 @@ CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md)
86 88
87 return cms; 89 return cms;
88 90
89 err: 91err:
90
91 if (cms) 92 if (cms)
92 CMS_ContentInfo_free(cms); 93 CMS_ContentInfo_free(cms);
93
94 return NULL; 94 return NULL;
95 } 95}
96 96
97BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms) 97BIO *
98 { 98cms_DigestedData_init_bio(CMS_ContentInfo *cms)
99{
99 CMS_DigestedData *dd; 100 CMS_DigestedData *dd;
101
100 dd = cms->d.digestedData; 102 dd = cms->d.digestedData;
101 return cms_DigestAlgorithm_init_bio(dd->digestAlgorithm); 103 return cms_DigestAlgorithm_init_bio(dd->digestAlgorithm);
102 } 104}
103 105
104int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify) 106int
105 { 107cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify)
108{
106 EVP_MD_CTX mctx; 109 EVP_MD_CTX mctx;
107 unsigned char md[EVP_MAX_MD_SIZE]; 110 unsigned char md[EVP_MAX_MD_SIZE];
108 unsigned int mdlen; 111 unsigned int mdlen;
109 int r = 0; 112 int r = 0;
110 CMS_DigestedData *dd; 113 CMS_DigestedData *dd;
114
111 EVP_MD_CTX_init(&mctx); 115 EVP_MD_CTX_init(&mctx);
112 116
113 dd = cms->d.digestedData; 117 dd = cms->d.digestedData;
@@ -118,31 +122,26 @@ int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify)
118 if (EVP_DigestFinal_ex(&mctx, md, &mdlen) <= 0) 122 if (EVP_DigestFinal_ex(&mctx, md, &mdlen) <= 0)
119 goto err; 123 goto err;
120 124
121 if (verify) 125 if (verify) {
122 { 126 if (mdlen != (unsigned int)dd->digest->length) {
123 if (mdlen != (unsigned int)dd->digest->length)
124 {
125 CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, 127 CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL,
126 CMS_R_MESSAGEDIGEST_WRONG_LENGTH); 128 CMS_R_MESSAGEDIGEST_WRONG_LENGTH);
127 goto err; 129 goto err;
128 } 130 }
129 131
130 if (memcmp(md, dd->digest->data, mdlen)) 132 if (memcmp(md, dd->digest->data, mdlen))
131 CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, 133 CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL,
132 CMS_R_VERIFICATION_FAILURE); 134 CMS_R_VERIFICATION_FAILURE);
133 else 135 else
134 r = 1; 136 r = 1;
135 } 137 } else {
136 else
137 {
138 if (!ASN1_STRING_set(dd->digest, md, mdlen)) 138 if (!ASN1_STRING_set(dd->digest, md, mdlen))
139 goto err; 139 goto err;
140 r = 1; 140 r = 1;
141 } 141 }
142 142
143 err: 143err:
144 EVP_MD_CTX_cleanup(&mctx); 144 EVP_MD_CTX_cleanup(&mctx);
145 145
146 return r; 146 return r;
147 147}
148 }