sha1.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * sha1.h
  3. *
  4. * interface to the Secure Hash Algorithm v.1 (SHA-1), specified in
  5. * FIPS 180-1
  6. *
  7. * David A. McGrew
  8. * Cisco Systems, Inc.
  9. */
  10. /*
  11. *
  12. * Copyright (c) 2001-2006, Cisco Systems, Inc.
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions
  17. * are met:
  18. *
  19. * Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. *
  22. * Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials provided
  25. * with the distribution.
  26. *
  27. * Neither the name of the Cisco Systems, Inc. nor the names of its
  28. * contributors may be used to endorse or promote products derived
  29. * from this software without specific prior written permission.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  34. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  35. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  36. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  37. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  38. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42. * OF THE POSSIBILITY OF SUCH DAMAGE.
  43. *
  44. */
  45. #ifndef SHA1_H
  46. #define SHA1_H
  47. #include "err.h"
  48. #include "datatypes.h"
  49. typedef struct {
  50. uint32_t H[5]; /* state vector */
  51. uint32_t M[16]; /* message buffer */
  52. int octets_in_buffer; /* octets of message in buffer */
  53. uint32_t num_bits_in_msg; /* total number of bits in message */
  54. } sha1_ctx_t;
  55. /*
  56. * sha1(&ctx, msg, len, output) hashes the len octets starting at msg
  57. * into the SHA1 context, then writes the result to the 20 octets at
  58. * output
  59. *
  60. */
  61. void
  62. sha1(const uint8_t *message, int octets_in_msg, uint32_t output[5]);
  63. /*
  64. * sha1_init(&ctx) initializes the SHA1 context ctx
  65. *
  66. * sha1_update(&ctx, msg, len) hashes the len octets starting at msg
  67. * into the SHA1 context
  68. *
  69. * sha1_final(&ctx, output) performs the final processing of the SHA1
  70. * context and writes the result to the 20 octets at output
  71. *
  72. */
  73. void
  74. sha1_init(sha1_ctx_t *ctx);
  75. void
  76. sha1_update(sha1_ctx_t *ctx, const uint8_t *M, int octets_in_msg);
  77. void
  78. sha1_final(sha1_ctx_t *ctx, uint32_t output[5]);
  79. /*
  80. * The sha1_core function is INTERNAL to SHA-1, but it is declared
  81. * here because it is also used by the cipher SEAL 3.0 in its key
  82. * setup algorithm.
  83. */
  84. /*
  85. * sha1_core(M, H) computes the core sha1 compression function, where M is
  86. * the next part of the message and H is the intermediate state {H0,
  87. * H1, ...}
  88. *
  89. * this function does not do any of the padding required in the
  90. * complete sha1 function
  91. */
  92. void
  93. sha1_core(const uint32_t M[16], uint32_t hash_value[5]);
  94. #endif /* SHA1_H */