2016-05-18 02:51:34 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2018-12-06 20:17:34 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:51:34 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
2017-08-25 20:51:45 +08:00
|
|
|
#include <sys/types.h>
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1999-09-12 01:54:18 +08:00
|
|
|
|
2004-12-05 09:03:15 +08:00
|
|
|
#include <openssl/err.h>
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/buffer.h>
|
1999-08-08 19:25:32 +08:00
|
|
|
#include <openssl/x509.h>
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2020-02-25 05:33:52 +08:00
|
|
|
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
2000-12-29 06:24:50 +08:00
|
|
|
|
2005-03-31 21:57:54 +08:00
|
|
|
int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
|
2015-01-22 11:40:55 +08:00
|
|
|
unsigned char *md, unsigned int *len)
|
|
|
|
{
|
2018-10-01 04:39:38 +08:00
|
|
|
int inl;
|
2015-01-22 11:40:55 +08:00
|
|
|
unsigned char *str, *p;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2018-10-01 04:39:38 +08:00
|
|
|
inl = i2d(data, NULL);
|
|
|
|
if (inl <= 0) {
|
|
|
|
ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_INTERNAL_ERROR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((str = OPENSSL_malloc(inl)) == NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE);
|
2017-10-17 22:04:09 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
p = str;
|
|
|
|
i2d(data, &p);
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2018-10-01 04:39:38 +08:00
|
|
|
if (!EVP_Digest(str, inl, md, len, type, NULL)) {
|
2017-02-02 01:29:47 +08:00
|
|
|
OPENSSL_free(str);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
2017-02-02 01:29:47 +08:00
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
OPENSSL_free(str);
|
2017-10-09 19:05:58 +08:00
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-12-29 06:24:50 +08:00
|
|
|
#endif
|
|
|
|
|
2000-12-29 03:18:48 +08:00
|
|
|
int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
|
2015-01-22 11:40:55 +08:00
|
|
|
unsigned char *md, unsigned int *len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char *str = NULL;
|
2000-12-29 03:18:48 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
i = ASN1_item_i2d(asn, &str, it);
|
|
|
|
if (!str)
|
2017-10-17 22:04:09 +08:00
|
|
|
return 0;
|
2000-12-29 03:18:48 +08:00
|
|
|
|
2017-02-02 01:29:47 +08:00
|
|
|
if (!EVP_Digest(str, i, md, len, type, NULL)) {
|
|
|
|
OPENSSL_free(str);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
2017-02-02 01:29:47 +08:00
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
OPENSSL_free(str);
|
2017-10-09 19:05:58 +08:00
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|