]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/asn1/a_digest.c
2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
10 /* We need to use some engine deprecated APIs */
11 #define OPENSSL_SUPPRESS_DEPRECATED
15 #include <sys/types.h>
17 #include "internal/cryptlib.h"
19 #include <openssl/engine.h>
20 #include <openssl/err.h>
21 #include <openssl/evp.h>
22 #include <openssl/buffer.h>
23 #include <openssl/x509.h>
24 #include "crypto/x509.h"
26 #ifndef OPENSSL_NO_DEPRECATED_3_0
28 int ASN1_digest(i2d_of_void
*i2d
, const EVP_MD
*type
, char *data
,
29 unsigned char *md
, unsigned int *len
)
32 unsigned char *str
, *p
;
34 inl
= i2d(data
, NULL
);
36 ASN1err(ASN1_F_ASN1_DIGEST
, ERR_R_INTERNAL_ERROR
);
39 if ((str
= OPENSSL_malloc(inl
)) == NULL
) {
40 ASN1err(ASN1_F_ASN1_DIGEST
, ERR_R_MALLOC_FAILURE
);
46 if (!EVP_Digest(str
, inl
, md
, len
, type
, NULL
)) {
56 int asn1_item_digest_ex(const ASN1_ITEM
*it
, const EVP_MD
*md
, void *asn
,
57 unsigned char *data
, unsigned int *len
,
58 OSSL_LIB_CTX
*libctx
, const char *propq
)
61 unsigned char *str
= NULL
;
62 EVP_MD
*fetched_md
= (EVP_MD
*)md
;
64 i
= ASN1_item_i2d(asn
, &str
, it
);
65 if (i
< 0 || str
== NULL
)
68 if (EVP_MD_provider(md
) == NULL
) {
69 #if !defined(OPENSSL_NO_ENGINE)
70 ENGINE
*tmpeng
= ENGINE_get_digest_engine(EVP_MD_type(md
));
73 ENGINE_finish(tmpeng
);
76 fetched_md
= EVP_MD_fetch(libctx
, EVP_MD_name(md
), propq
);
78 if (fetched_md
== NULL
)
81 ret
= EVP_Digest(str
, i
, data
, len
, fetched_md
, NULL
);
85 EVP_MD_free(fetched_md
);
89 int ASN1_item_digest(const ASN1_ITEM
*it
, const EVP_MD
*md
, void *asn
,
90 unsigned char *data
, unsigned int *len
)
92 return asn1_item_digest_ex(it
, md
, asn
, data
, len
, NULL
, NULL
);