2016-05-17 18:51:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 10:52:47 +00:00
|
|
|
*
|
2018-12-06 12:17:34 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 18:51:34 +00: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 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
2017-08-25 12:51:45 +00:00
|
|
|
#include <sys/types.h>
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
1999-09-11 17:54:18 +00:00
|
|
|
|
2004-12-05 01:03:15 +00:00
|
|
|
#include <openssl/err.h>
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/buffer.h>
|
1999-08-08 11:25:32 +00:00
|
|
|
#include <openssl/x509.h>
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2000-12-28 22:24:50 +00:00
|
|
|
#ifndef NO_ASN1_OLD
|
|
|
|
|
2005-03-31 13:57:54 +00:00
|
|
|
int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
|
2015-01-22 03:40:55 +00:00
|
|
|
unsigned char *md, unsigned int *len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char *str, *p;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
i = i2d(data, NULL);
|
2015-04-28 19:28:14 +00:00
|
|
|
if ((str = OPENSSL_malloc(i)) == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE);
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
p = str;
|
|
|
|
i2d(data, &p);
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2017-02-01 17:29:47 +00:00
|
|
|
if (!EVP_Digest(str, i, md, len, type, NULL)) {
|
|
|
|
OPENSSL_free(str);
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
2017-02-01 17:29:47 +00:00
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
OPENSSL_free(str);
|
2017-10-09 11:05:58 +00:00
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2000-12-28 22:24:50 +00:00
|
|
|
#endif
|
|
|
|
|
2000-12-28 19:18:48 +00:00
|
|
|
int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
|
2015-01-22 03:40:55 +00:00
|
|
|
unsigned char *md, unsigned int *len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char *str = NULL;
|
2000-12-28 19:18:48 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
i = ASN1_item_i2d(asn, &str, it);
|
|
|
|
if (!str)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2000-12-28 19:18:48 +00:00
|
|
|
|
2017-02-01 17:29:47 +00:00
|
|
|
if (!EVP_Digest(str, i, md, len, type, NULL)) {
|
|
|
|
OPENSSL_free(str);
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
2017-02-01 17:29:47 +00:00
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
OPENSSL_free(str);
|
2017-10-09 11:05:58 +00:00
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|