2
0

a_digest.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  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
  8. */
  9. #include <stdio.h>
  10. #include <time.h>
  11. #include <sys/types.h>
  12. #include "internal/cryptlib.h"
  13. #include <openssl/err.h>
  14. #include <openssl/evp.h>
  15. #include <openssl/buffer.h>
  16. #include <openssl/x509.h>
  17. #ifndef NO_ASN1_OLD
  18. int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
  19. unsigned char *md, unsigned int *len)
  20. {
  21. int inl;
  22. unsigned char *str, *p;
  23. inl = i2d(data, NULL);
  24. if (inl <= 0) {
  25. ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_INTERNAL_ERROR);
  26. return 0;
  27. }
  28. if ((str = OPENSSL_malloc(inl)) == NULL) {
  29. ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE);
  30. return 0;
  31. }
  32. p = str;
  33. i2d(data, &p);
  34. if (!EVP_Digest(str, inl, md, len, type, NULL)) {
  35. OPENSSL_free(str);
  36. return 0;
  37. }
  38. OPENSSL_free(str);
  39. return 1;
  40. }
  41. #endif
  42. int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
  43. unsigned char *md, unsigned int *len)
  44. {
  45. int i;
  46. unsigned char *str = NULL;
  47. i = ASN1_item_i2d(asn, &str, it);
  48. if (!str)
  49. return 0;
  50. if (!EVP_Digest(str, i, md, len, type, NULL)) {
  51. OPENSSL_free(str);
  52. return 0;
  53. }
  54. OPENSSL_free(str);
  55. return 1;
  56. }