sha1.h 2.5 KB

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