sha1.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* $OpenBSD: sha1.h,v 1.22 2004/05/05 17:09:45 millert Exp $ */
  2. /*
  3. * SHA-1 in C
  4. * By Steve Reid <[email protected]>
  5. * 100% Public Domain
  6. */
  7. #ifndef _SHA1_H
  8. #define _SHA1_H
  9. #include <sys/types.h>
  10. #include <stdint.h>
  11. #define SHA1_BLOCK_LENGTH 64
  12. #define SHA1_DIGEST_LENGTH 20
  13. #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
  14. typedef struct {
  15. uint32_t state[5];
  16. uint64_t count;
  17. uint8_t buffer[SHA1_BLOCK_LENGTH];
  18. } SHA1_CTX;
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. void SHA1Init(SHA1_CTX *);
  23. void SHA1Pad(SHA1_CTX *);
  24. void SHA1Transform(uint32_t [5], const uint8_t [SHA1_BLOCK_LENGTH]);
  25. void SHA1Update(SHA1_CTX *, const uint8_t *, size_t);
  26. void SHA1Final(uint8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *);
  27. char *SHA1End(SHA1_CTX *, char *);
  28. char *SHA1File(const char *, char *);
  29. char *SHA1FileChunk(const char *, char *, off_t, off_t);
  30. char *SHA1Data(const uint8_t *, size_t, char *);
  31. #ifdef __cplusplus
  32. }
  33. #endif
  34. #define HTONDIGEST(x) do { \
  35. x[0] = htonl(x[0]); \
  36. x[1] = htonl(x[1]); \
  37. x[2] = htonl(x[2]); \
  38. x[3] = htonl(x[3]); \
  39. x[4] = htonl(x[4]); } while (0)
  40. #define NTOHDIGEST(x) do { \
  41. x[0] = ntohl(x[0]); \
  42. x[1] = ntohl(x[1]); \
  43. x[2] = ntohl(x[2]); \
  44. x[3] = ntohl(x[3]); \
  45. x[4] = ntohl(x[4]); } while (0)
  46. #endif /* _SHA1_H */