tiny_sha1.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * \file sha1.h
  3. *
  4. * Based on TropicSSL: Copyright (C) 2017 Shanghai Real-Thread Technology Co., Ltd
  5. *
  6. * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
  7. *
  8. * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * * Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * * Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * * Neither the names of PolarSSL or XySSL nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  28. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  31. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  32. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #ifndef TINY_CRYPT_SHA1_H__
  38. #define TINY_CRYPT_SHA1_H__
  39. /**
  40. * \brief SHA-1 context structure
  41. */
  42. typedef struct {
  43. unsigned long total[2]; /*!< number of bytes processed */
  44. unsigned long state[5]; /*!< intermediate digest state */
  45. unsigned char buffer[64]; /*!< data block being processed */
  46. unsigned char ipad[64]; /*!< HMAC: inner padding */
  47. unsigned char opad[64]; /*!< HMAC: outer padding */
  48. } tiny_sha1_context;
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. /**
  53. * \brief SHA-1 context setup
  54. *
  55. * \param ctx context to be initialized
  56. */
  57. void tiny_sha1_starts(tiny_sha1_context * ctx);
  58. /**
  59. * \brief SHA-1 process buffer
  60. *
  61. * \param ctx SHA-1 context
  62. * \param input buffer holding the data
  63. * \param ilen length of the input data
  64. */
  65. void tiny_sha1_update(tiny_sha1_context * ctx, unsigned char *input, int ilen);
  66. /**
  67. * \brief SHA-1 final digest
  68. *
  69. * \param ctx SHA-1 context
  70. * \param output SHA-1 checksum result
  71. */
  72. void tiny_sha1_finish(tiny_sha1_context * ctx, unsigned char output[20]);
  73. /**
  74. * \brief Output = SHA-1( input buffer )
  75. *
  76. * \param input buffer holding the data
  77. * \param ilen length of the input data
  78. * \param output SHA-1 checksum result
  79. */
  80. void tiny_sha1(unsigned char *input, int ilen, unsigned char output[20]);
  81. /**
  82. * \brief SHA-1 HMAC context setup
  83. *
  84. * \param ctx HMAC context to be initialized
  85. * \param key HMAC secret key
  86. * \param keylen length of the HMAC key
  87. */
  88. void tiny_sha1_hmac_starts(tiny_sha1_context * ctx, unsigned char *key,
  89. int keylen);
  90. /**
  91. * \brief SHA-1 HMAC process buffer
  92. *
  93. * \param ctx HMAC context
  94. * \param input buffer holding the data
  95. * \param ilen length of the input data
  96. */
  97. void tiny_sha1_hmac_update(tiny_sha1_context * ctx, unsigned char *input,
  98. int ilen);
  99. /**
  100. * \brief SHA-1 HMAC final digest
  101. *
  102. * \param ctx HMAC context
  103. * \param output SHA-1 HMAC checksum result
  104. */
  105. void tiny_sha1_hmac_finish(tiny_sha1_context * ctx, unsigned char output[20]);
  106. /**
  107. * \brief Output = HMAC-SHA-1( hmac key, input buffer )
  108. *
  109. * \param key HMAC secret key
  110. * \param keylen length of the HMAC key
  111. * \param input buffer holding the data
  112. * \param ilen length of the input data
  113. * \param output HMAC-SHA-1 result
  114. */
  115. void tiny_sha1_hmac(unsigned char *key, int keylen,
  116. unsigned char *input, int ilen,
  117. unsigned char output[20]);
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif /* sha1.h */