summaryrefslogtreecommitdiffstats
path: root/crypto/x509
diff options
context:
space:
mode:
authorRich Salz <rsalz@openssl.org>2017-01-12 16:39:41 -0500
committerRich Salz <rsalz@openssl.org>2017-01-12 16:50:54 -0500
commit550f0f99600194cacd10ca43584a9744e27dbe0f (patch)
tree74300049b9b8928032b786443b91938f6ee45f56 /crypto/x509
parentff7256e75928be74101f3ce2d1fbf62f7e10a1f3 (diff)
Make X509_Digest,others public
Also, if want SHA1 then use the pre-computed value if there. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/2223) (cherry picked from commit 3e5d9da5fc45a5d129e0daa7211125eba097c3dd)
Diffstat (limited to 'crypto/x509')
-rw-r--r--crypto/x509/x_all.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/crypto/x509/x_all.c b/crypto/x509/x_all.c
index d9f42edaab..86f4d70042 100644
--- a/crypto/x509/x_all.c
+++ b/crypto/x509/x_all.c
@@ -362,6 +362,13 @@ int X509_pubkey_digest(const X509 *data, const EVP_MD *type,
int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
unsigned int *len)
{
+ if (type == EVP_sha1() && (data->ex_flags & EXFLAG_SET) != 0) {
+ /* Asking for SHA1 and we already computed it. */
+ if (len != NULL)
+ *len = sizeof(data->sha1_hash);
+ memcpy(md, data->sha1_hash, sizeof(data->sha1_hash));
+ return 1;
+ }
return (ASN1_item_digest
(ASN1_ITEM_rptr(X509), type, (char *)data, md, len));
}
@@ -369,6 +376,13 @@ int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type,
unsigned char *md, unsigned int *len)
{
+ if (type == EVP_sha1()) {
+ /* Asking for SHA1; always computed in CRL d2i. */
+ if (len != NULL)
+ *len = sizeof(data->sha1_hash);
+ memcpy(md, data->sha1_hash, sizeof(data->sha1_hash));
+ return 1;
+ }
return (ASN1_item_digest
(ASN1_ITEM_rptr(X509_CRL), type, (char *)data, md, len));
}