SHA1.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*******************************************************************************
  2. * Copyright (c) 2018 Wind River Systems, Inc. All Rights Reserved.
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * and Eclipse Distribution License v1.0 which accompany this distribution.
  7. *
  8. * The Eclipse Public License is available at
  9. * http://www.eclipse.org/legal/epl-v10.html
  10. * and the Eclipse Distribution License is available at
  11. * http://www.eclipse.org/org/documents/edl-v10.php.
  12. *
  13. * Contributors:
  14. * Keith Holman - initial implementation and documentation
  15. *******************************************************************************/
  16. #if !defined(SHA1_H)
  17. #define SHA1_H
  18. #if defined(OPENSSL)
  19. #include <openssl/sha.h>
  20. /** SHA-1 Digest Length */
  21. #define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
  22. #else /* if defined(OPENSSL) */
  23. #if defined(WIN32) || defined(WIN64)
  24. #include <Windows.h>
  25. #include <WinCrypt.h>
  26. typedef struct SHA_CTX_S
  27. {
  28. HCRYPTPROV hProv;
  29. HCRYPTHASH hHash;
  30. } SHA_CTX;
  31. #else /* if defined(WIN32) || defined(WIN64) */
  32. #include <stdint.h>
  33. typedef struct SHA_CTX_S {
  34. uint32_t h[5];
  35. union {
  36. uint32_t w[16];
  37. uint8_t buffer[64];
  38. };
  39. unsigned int size;
  40. unsigned int total;
  41. } SHA_CTX;
  42. #endif /* else if defined(WIN32) || defined(WIN64) */
  43. #include <stddef.h>
  44. /** SHA-1 Digest Length (number of bytes in SHA1) */
  45. #define SHA1_DIGEST_LENGTH (160/8)
  46. /**
  47. * Initializes the SHA1 hashing algorithm
  48. *
  49. * @param[in,out] ctx hashing context structure
  50. *
  51. * @see SHA1_Update
  52. * @see SHA1_Final
  53. */
  54. int SHA1_Init(SHA_CTX *ctx);
  55. /**
  56. * Updates a block to the SHA1 hash
  57. *
  58. * @param[in,out] ctx hashing context structure
  59. * @param[in] data block of data to hash
  60. * @param[in] len length of block to hash
  61. *
  62. * @see SHA1_Init
  63. * @see SHA1_Final
  64. */
  65. int SHA1_Update(SHA_CTX *ctx, const void *data, size_t len);
  66. /**
  67. * Produce final SHA1 hash
  68. *
  69. * @param[out] md SHA1 hash produced (must be atleast
  70. * @p SHA1_DIGEST_LENGTH in length)
  71. * @param[in,out] ctx hashing context structure
  72. *
  73. * @see SHA1_Init
  74. * @see SHA1_Final
  75. */
  76. int SHA1_Final(unsigned char *md, SHA_CTX *ctx);
  77. #endif /* if defined(OPENSSL) */
  78. #endif /* SHA1_H */