sha1.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* sha1.h */
  2. /*
  3. This file is part of the ARM-Crypto-Lib.
  4. Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /**
  17. * \file sha1.h
  18. * \author Daniel Otte
  19. * \email daniel.otte@rub.de
  20. * \date 2006-10-08
  21. * \license GPLv3 or later
  22. * \brief SHA-1 declaration.
  23. * \ingroup SHA-1
  24. *
  25. */
  26. #ifndef SHA1_H_
  27. #define SHA1_H_
  28. #include <stdint.h>
  29. /** \def SHA1_HASH_BITS
  30. * definees the size of a SHA-1 hash in bits
  31. */
  32. /** \def SHA1_HASH_BYTES
  33. * definees the size of a SHA-1 hash in bytes
  34. */
  35. /** \def SHA1_BLOCK_BITS
  36. * definees the size of a SHA-1 input block in bits
  37. */
  38. /** \def SHA1_BLOCK_BYTES
  39. * definees the size of a SHA-1 input block in bytes
  40. */
  41. #define SHA1_HASH_BITS 160
  42. #define SHA1_HASH_BYTES (SHA1_HASH_BITS/8)
  43. #define SHA1_BLOCK_BITS 512
  44. #define SHA1_BLOCK_BYTES (SHA1_BLOCK_BITS/8)
  45. /** \typedef sha1_ctx_t
  46. * \brief SHA-1 context type
  47. *
  48. * A vatiable of this type may hold the state of a SHA-1 hashing process
  49. */
  50. typedef struct {
  51. uint32_t h[5];
  52. uint64_t length;
  53. } sha1_ctx_t;
  54. /** \typedef sha1_hash_t
  55. * \brief hash value type
  56. * A variable of this type may hold a SHA-1 hash value
  57. */
  58. /*
  59. typedef uint8_t sha1_hash_t[SHA1_HASH_BITS/8];
  60. */
  61. /** \fn sha1_init(sha1_ctx_t *state)
  62. * \brief initializes a SHA-1 context
  63. * This function sets a ::sha1_ctx_t variable to the initialization vector
  64. * for SHA-1 hashing.
  65. * \param state pointer to the SHA-1 context variable
  66. */
  67. void sha1_init(sha1_ctx_t *state);
  68. /** \fn sha1_nextBlock(sha1_ctx_t *state, const void* block)
  69. * \brief process one input block
  70. * This function processes one input block and updates the hash context
  71. * accordingly
  72. * \param state pointer to the state variable to update
  73. * \param block pointer to the message block to process
  74. */
  75. void sha1_nextBlock (sha1_ctx_t *state, const void* block);
  76. /** \fn sha1_lastBlock(sha1_ctx_t *state, const void* block, uint16_t length_b)
  77. * \brief processes the given block and finalizes the context
  78. * This function processes the last block in a SHA-1 hashing process.
  79. * The block should have a maximum length of a single input block.
  80. * \param state pointer to the state variable to update and finalize
  81. * \param block pointer to themessage block to process
  82. * \param length_b length of the message block in bits
  83. */
  84. void sha1_lastBlock (sha1_ctx_t *state, const void* block, uint16_t length_b);
  85. /** \fn sha1_ctx2hash(sha1_hash_t *dest, sha1_ctx_t *state)
  86. * \brief convert a state variable into an actual hash value
  87. * Writes the hash value corresponding to the state to the memory pointed by dest.
  88. * \param dest pointer to the hash value destination
  89. * \param state pointer to the hash context
  90. */
  91. void sha1_ctx2hash (void *dest, sha1_ctx_t *state);
  92. /** \fn sha1(sha1_hash_t *dest, const void* msg, uint32_t length_b)
  93. * \brief hashing a message which in located entirely in RAM
  94. * This function automatically hashes a message which is entirely in RAM with
  95. * the SHA-1 hashing algorithm.
  96. * \param dest pointer to the hash value destination
  97. * \param msg pointer to the message which should be hashed
  98. * \param length_b length of the message in bits
  99. */
  100. void sha1(void *dest, const void* msg, uint32_t length_b);
  101. #endif /*SHA1_H_*/