sha1.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License, version 2.1 as published by the Free Software Foundation.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20. * MA 02110-1301 USA
  21. */
  22. /*
  23. * The SHA-1 standard was published by NIST in 1993.
  24. *
  25. * http://www.itl.nist.gov/fipspubs/fip180-1.htm
  26. */
  27. #ifndef _SHA1_H
  28. #define _SHA1_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #define SHA1_SUM_POS -0x20
  33. #define SHA1_SUM_LEN 20
  34. /**
  35. * \brief SHA-1 context structure
  36. */
  37. typedef struct
  38. {
  39. unsigned long total[2]; /*!< number of bytes processed */
  40. unsigned long state[5]; /*!< intermediate digest state */
  41. unsigned char buffer[64]; /*!< data block being processed */
  42. }
  43. sha1_context;
  44. /**
  45. * \brief SHA-1 context setup
  46. *
  47. * \param ctx SHA-1 context to be initialized
  48. */
  49. void sha1_starts( sha1_context *ctx );
  50. /**
  51. * \brief SHA-1 process buffer
  52. *
  53. * \param ctx SHA-1 context
  54. * \param input buffer holding the data
  55. * \param ilen length of the input data
  56. */
  57. void sha1_update( sha1_context *ctx, unsigned char *input, int ilen );
  58. /**
  59. * \brief SHA-1 final digest
  60. *
  61. * \param ctx SHA-1 context
  62. * \param output SHA-1 checksum result
  63. */
  64. void sha1_finish( sha1_context *ctx, unsigned char output[20] );
  65. /**
  66. * \brief Output = SHA-1( input buffer )
  67. *
  68. * \param input buffer holding the data
  69. * \param ilen length of the input data
  70. * \param output SHA-1 checksum result
  71. */
  72. void sha1_csum( unsigned char *input, int ilen,
  73. unsigned char output[20] );
  74. /**
  75. * \brief Output = SHA-1( input buffer ), with watchdog triggering
  76. *
  77. * \param input buffer holding the data
  78. * \param ilen length of the input data
  79. * \param output SHA-1 checksum result
  80. * \param chunk_sz watchdog triggering period (in bytes of input processed)
  81. */
  82. void sha1_csum_wd (unsigned char *input, int ilen,
  83. unsigned char output[20], unsigned int chunk_sz);
  84. /**
  85. * \brief Output = SHA-1( file contents )
  86. *
  87. * \param path input file name
  88. * \param output SHA-1 checksum result
  89. * \return 0 if successful, or 1 if fopen failed
  90. */
  91. int sha1_file( char *path, unsigned char output[20] );
  92. /**
  93. * \brief Output = HMAC-SHA-1( input buffer, hmac key )
  94. *
  95. * \param key HMAC secret key
  96. * \param keylen length of the HMAC key
  97. * \param input buffer holding the data
  98. * \param ilen length of the input data
  99. * \param output HMAC-SHA-1 result
  100. */
  101. void sha1_hmac( unsigned char *key, int keylen,
  102. unsigned char *input, int ilen,
  103. unsigned char output[20] );
  104. /**
  105. * \brief Checkup routine
  106. *
  107. * \return 0 if successful, or 1 if the test failed
  108. */
  109. int sha1_self_test( void );
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif /* sha1.h */