sha1.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. ---------------------------------------------------------------------------
  3. Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved.
  4. The redistribution and use of this software (with or without changes)
  5. is allowed without the payment of fees or royalties provided that:
  6. source code distributions include the above copyright notice, this
  7. list of conditions and the following disclaimer;
  8. binary distributions include the above copyright notice, this list
  9. of conditions and the following disclaimer in their documentation.
  10. This software is provided 'as is' with no explicit or implied warranties
  11. in respect of its operation, including, but not limited to, correctness
  12. and fitness for purpose.
  13. ---------------------------------------------------------------------------
  14. Issue Date: 20/12/2007
  15. */
  16. #ifndef _SHA1_H
  17. #define _SHA1_H
  18. #define SHA_1
  19. /* define for bit or byte oriented SHA */
  20. #if 1
  21. # define SHA1_BITS 0 /* byte oriented */
  22. #else
  23. # define SHA1_BITS 1 /* bit oriented */
  24. #endif
  25. #include <stdlib.h>
  26. #include "brg_types.h"
  27. #define SHA1_BLOCK_SIZE 64
  28. #define SHA1_DIGEST_SIZE 20
  29. #if defined(__cplusplus)
  30. extern "C"
  31. {
  32. #endif
  33. /* type to hold the SHA256 context */
  34. typedef struct
  35. { uint32_t count[2];
  36. uint32_t hash[SHA1_DIGEST_SIZE >> 2];
  37. uint32_t wbuf[SHA1_BLOCK_SIZE >> 2];
  38. } sha1_ctx;
  39. /* Note that these prototypes are the same for both bit and */
  40. /* byte oriented implementations. However the length fields */
  41. /* are in bytes or bits as appropriate for the version used */
  42. /* and bit sequences are input as arrays of bytes in which */
  43. /* bit sequences run from the most to the least significant */
  44. /* end of each byte. The value 'len' in sha1_hash for the */
  45. /* byte oriented version of SHA1 is limited to 2^29 bytes, */
  46. /* but multiple calls will handle longer data blocks. */
  47. VOID_RETURN sha1_compile(sha1_ctx ctx[1]);
  48. VOID_RETURN sha1_begin(sha1_ctx ctx[1]);
  49. VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]);
  50. VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]);
  51. VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len);
  52. #if defined(__cplusplus)
  53. }
  54. #endif
  55. #endif