sha1.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * \file sha1.h
  3. * based from http://xyssl.org/code/source/sha1/
  4. * FIPS-180-1 compliant SHA-1 implementation
  5. *
  6. * Copyright (C) 2003-2006 Christophe Devine
  7. *
  8. * SPDX-License-Identifier: LGPL-2.1
  9. */
  10. /*
  11. * The SHA-1 standard was published by NIST in 1993.
  12. *
  13. * http://www.itl.nist.gov/fipspubs/fip180-1.htm
  14. */
  15. #ifndef _SHA1_H
  16. #define _SHA1_H
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #define SHA1_SUM_POS -0x20
  21. #define SHA1_SUM_LEN 20
  22. #define SHA1_DER_LEN 15
  23. extern const uint8_t sha1_der_prefix[];
  24. /**
  25. * \brief SHA-1 context structure
  26. */
  27. typedef struct
  28. {
  29. unsigned long total[2]; /*!< number of bytes processed */
  30. unsigned long state[5]; /*!< intermediate digest state */
  31. unsigned char buffer[64]; /*!< data block being processed */
  32. }
  33. sha1_context;
  34. /**
  35. * \brief SHA-1 context setup
  36. *
  37. * \param ctx SHA-1 context to be initialized
  38. */
  39. void sha1_starts( sha1_context *ctx );
  40. /**
  41. * \brief SHA-1 process buffer
  42. *
  43. * \param ctx SHA-1 context
  44. * \param input buffer holding the data
  45. * \param ilen length of the input data
  46. */
  47. void sha1_update(sha1_context *ctx, const unsigned char *input,
  48. unsigned int ilen);
  49. /**
  50. * \brief SHA-1 final digest
  51. *
  52. * \param ctx SHA-1 context
  53. * \param output SHA-1 checksum result
  54. */
  55. void sha1_finish( sha1_context *ctx, unsigned char output[20] );
  56. /**
  57. * \brief Output = SHA-1( input buffer )
  58. *
  59. * \param input buffer holding the data
  60. * \param ilen length of the input data
  61. * \param output SHA-1 checksum result
  62. */
  63. void sha1_csum(const unsigned char *input, unsigned int ilen,
  64. unsigned char *output);
  65. /**
  66. * \brief Output = SHA-1( input buffer ), with watchdog triggering
  67. *
  68. * \param input buffer holding the data
  69. * \param ilen length of the input data
  70. * \param output SHA-1 checksum result
  71. * \param chunk_sz watchdog triggering period (in bytes of input processed)
  72. */
  73. void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
  74. unsigned char *output, unsigned int chunk_sz);
  75. /**
  76. * \brief Output = HMAC-SHA-1( input buffer, hmac key )
  77. *
  78. * \param key HMAC secret key
  79. * \param keylen length of the HMAC key
  80. * \param input buffer holding the data
  81. * \param ilen length of the input data
  82. * \param output HMAC-SHA-1 result
  83. */
  84. void sha1_hmac(const unsigned char *key, int keylen,
  85. const unsigned char *input, unsigned int ilen,
  86. unsigned char *output);
  87. /**
  88. * \brief Checkup routine
  89. *
  90. * \return 0 if successful, or 1 if the test failed
  91. */
  92. int sha1_self_test( void );
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif /* sha1.h */