diff options
Diffstat (limited to 'src/lib/libcrypto/cms/cms_dd.c')
-rw-r--r-- | src/lib/libcrypto/cms/cms_dd.c | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/src/lib/libcrypto/cms/cms_dd.c b/src/lib/libcrypto/cms/cms_dd.c index 1f834b6efb..fcc446fa2e 100644 --- a/src/lib/libcrypto/cms/cms_dd.c +++ b/src/lib/libcrypto/cms/cms_dd.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cms_dd.c,v 1.9 2019/08/10 16:39:17 jsing Exp $ */ | 1 | /* $OpenBSD: cms_dd.c,v 1.10 2019/08/10 16:42:20 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
4 | * project. | 4 | * project. |
@@ -64,81 +64,81 @@ | |||
64 | 64 | ||
65 | CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md) | 65 | CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md) |
66 | { | 66 | { |
67 | CMS_ContentInfo *cms; | 67 | CMS_ContentInfo *cms; |
68 | CMS_DigestedData *dd; | 68 | CMS_DigestedData *dd; |
69 | cms = CMS_ContentInfo_new(); | 69 | cms = CMS_ContentInfo_new(); |
70 | if (cms == NULL) | 70 | if (cms == NULL) |
71 | return NULL; | 71 | return NULL; |
72 | 72 | ||
73 | dd = M_ASN1_new_of(CMS_DigestedData); | 73 | dd = M_ASN1_new_of(CMS_DigestedData); |
74 | 74 | ||
75 | if (dd == NULL) | 75 | if (dd == NULL) |
76 | goto err; | 76 | goto err; |
77 | 77 | ||
78 | cms->contentType = OBJ_nid2obj(NID_pkcs7_digest); | 78 | cms->contentType = OBJ_nid2obj(NID_pkcs7_digest); |
79 | cms->d.digestedData = dd; | 79 | cms->d.digestedData = dd; |
80 | 80 | ||
81 | dd->version = 0; | 81 | dd->version = 0; |
82 | dd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data); | 82 | dd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data); |
83 | 83 | ||
84 | X509_ALGOR_set_md(dd->digestAlgorithm, md); | 84 | X509_ALGOR_set_md(dd->digestAlgorithm, md); |
85 | 85 | ||
86 | return cms; | 86 | return cms; |
87 | 87 | ||
88 | err: | 88 | err: |
89 | CMS_ContentInfo_free(cms); | 89 | CMS_ContentInfo_free(cms); |
90 | return NULL; | 90 | return NULL; |
91 | } | 91 | } |
92 | 92 | ||
93 | BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms) | 93 | BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms) |
94 | { | 94 | { |
95 | CMS_DigestedData *dd; | 95 | CMS_DigestedData *dd; |
96 | dd = cms->d.digestedData; | 96 | dd = cms->d.digestedData; |
97 | return cms_DigestAlgorithm_init_bio(dd->digestAlgorithm); | 97 | return cms_DigestAlgorithm_init_bio(dd->digestAlgorithm); |
98 | } | 98 | } |
99 | 99 | ||
100 | int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify) | 100 | int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify) |
101 | { | 101 | { |
102 | EVP_MD_CTX *mctx = EVP_MD_CTX_new(); | 102 | EVP_MD_CTX *mctx = EVP_MD_CTX_new(); |
103 | unsigned char md[EVP_MAX_MD_SIZE]; | 103 | unsigned char md[EVP_MAX_MD_SIZE]; |
104 | unsigned int mdlen; | 104 | unsigned int mdlen; |
105 | int r = 0; | 105 | int r = 0; |
106 | CMS_DigestedData *dd; | 106 | CMS_DigestedData *dd; |
107 | 107 | ||
108 | if (mctx == NULL) { | 108 | if (mctx == NULL) { |
109 | CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, ERR_R_MALLOC_FAILURE); | 109 | CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, ERR_R_MALLOC_FAILURE); |
110 | goto err; | 110 | goto err; |
111 | } | 111 | } |
112 | 112 | ||
113 | dd = cms->d.digestedData; | 113 | dd = cms->d.digestedData; |
114 | 114 | ||
115 | if (!cms_DigestAlgorithm_find_ctx(mctx, chain, dd->digestAlgorithm)) | 115 | if (!cms_DigestAlgorithm_find_ctx(mctx, chain, dd->digestAlgorithm)) |
116 | goto err; | 116 | goto err; |
117 | 117 | ||
118 | if (EVP_DigestFinal_ex(mctx, md, &mdlen) <= 0) | 118 | if (EVP_DigestFinal_ex(mctx, md, &mdlen) <= 0) |
119 | goto err; | 119 | goto err; |
120 | 120 | ||
121 | if (verify) { | 121 | if (verify) { |
122 | if (mdlen != (unsigned int)dd->digest->length) { | 122 | if (mdlen != (unsigned int)dd->digest->length) { |
123 | CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, | 123 | CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, |
124 | CMS_R_MESSAGEDIGEST_WRONG_LENGTH); | 124 | CMS_R_MESSAGEDIGEST_WRONG_LENGTH); |
125 | goto err; | 125 | goto err; |
126 | } | 126 | } |
127 | 127 | ||
128 | if (memcmp(md, dd->digest->data, mdlen)) | 128 | if (memcmp(md, dd->digest->data, mdlen)) |
129 | CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, | 129 | CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, |
130 | CMS_R_VERIFICATION_FAILURE); | 130 | CMS_R_VERIFICATION_FAILURE); |
131 | else | 131 | else |
132 | r = 1; | 132 | r = 1; |
133 | } else { | 133 | } else { |
134 | if (!ASN1_STRING_set(dd->digest, md, mdlen)) | 134 | if (!ASN1_STRING_set(dd->digest, md, mdlen)) |
135 | goto err; | 135 | goto err; |
136 | r = 1; | 136 | r = 1; |
137 | } | 137 | } |
138 | 138 | ||
139 | err: | 139 | err: |
140 | EVP_MD_CTX_free(mctx); | 140 | EVP_MD_CTX_free(mctx); |
141 | 141 | ||
142 | return r; | 142 | return r; |
143 | 143 | ||
144 | } | 144 | } |