sha1.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. ---------------------------------------------------------------------------
  3. Copyright (c) 2002, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK.
  4. All rights reserved.
  5. LICENSE TERMS
  6. The free distribution and use of this software in both source and binary
  7. form is allowed (with or without changes) provided that:
  8. 1. distributions of this source code include the above copyright
  9. notice, this list of conditions and the following disclaimer;
  10. 2. distributions in binary form include the above copyright
  11. notice, this list of conditions and the following disclaimer
  12. in the documentation and/or other associated materials;
  13. 3. the copyright holder's name is not used to endorse products
  14. built using this software without specific written permission.
  15. ALTERNATIVELY, provided that this notice is retained in full, this product
  16. may be distributed under the terms of the GNU General Public License (GPL),
  17. in which case the provisions of the GPL apply INSTEAD OF those given above.
  18. DISCLAIMER
  19. This software is provided 'as is' with no explicit or implied warranties
  20. in respect of its properties, including, but not limited to, correctness
  21. and/or fitness for purpose.
  22. ---------------------------------------------------------------------------
  23. Issue Date: 30/11/2002
  24. */
  25. #ifndef _SHA1_H
  26. #define _SHA1_H
  27. #include <limits.h>
  28. /* define an unsigned 32-bit type */
  29. #if UINT_MAX == 0xffffffff
  30. typedef unsigned int sha1_32t;
  31. #elif ULONG_MAX == 0xffffffff
  32. typedef unsigned long sha1_32t;
  33. #else
  34. #error Please define sha1_32t as an unsigned 32 bit type in sha2.h
  35. #endif
  36. #if defined(__cplusplus)
  37. extern "C"
  38. {
  39. #endif
  40. #define SHA1_BLOCK_SIZE 64
  41. #define SHA1_DIGEST_SIZE 20
  42. #define SHA2_GOOD 0
  43. #define SHA2_BAD 1
  44. /* type to hold the SHA256 context */
  45. typedef struct
  46. { sha1_32t count[2];
  47. sha1_32t hash[5];
  48. sha1_32t wbuf[16];
  49. } sha1_ctx;
  50. void sha1_compile(sha1_ctx ctx[1]);
  51. void sha1_begin(sha1_ctx ctx[1]);
  52. void sha1_hash(const unsigned char data[], unsigned int len, sha1_ctx ctx[1]);
  53. void sha1_end(unsigned char hval[], sha1_ctx ctx[1]);
  54. void sha1(unsigned char hval[], const unsigned char data[], unsigned int len);
  55. #if defined(__cplusplus)
  56. }
  57. #endif
  58. #endif