sha1.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* $OpenBSD: sha1.h,v 1.24 2012/12/05 23:19:57 deraadt Exp $ */
  2. /*
  3. * SHA-1 in C
  4. * By Steve Reid <steve@edmweb.com>
  5. * 100% Public Domain
  6. */
  7. #ifndef _SHA1_H
  8. #define _SHA1_H
  9. #ifndef WITH_OPENSSL
  10. #define SHA1_BLOCK_LENGTH 64
  11. #define SHA1_DIGEST_LENGTH 20
  12. #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
  13. typedef struct {
  14. u_int32_t state[5];
  15. u_int64_t count;
  16. u_int8_t buffer[SHA1_BLOCK_LENGTH];
  17. } SHA1_CTX;
  18. void SHA1Init(SHA1_CTX *);
  19. void SHA1Pad(SHA1_CTX *);
  20. void SHA1Transform(u_int32_t [5], const u_int8_t [SHA1_BLOCK_LENGTH])
  21. __attribute__((__bounded__(__minbytes__,1,5)))
  22. __attribute__((__bounded__(__minbytes__,2,SHA1_BLOCK_LENGTH)));
  23. void SHA1Update(SHA1_CTX *, const u_int8_t *, size_t)
  24. __attribute__((__bounded__(__string__,2,3)));
  25. void SHA1Final(u_int8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *)
  26. __attribute__((__bounded__(__minbytes__,1,SHA1_DIGEST_LENGTH)));
  27. char *SHA1End(SHA1_CTX *, char *)
  28. __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
  29. char *SHA1File(const char *, char *)
  30. __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
  31. char *SHA1FileChunk(const char *, char *, off_t, off_t)
  32. __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
  33. char *SHA1Data(const u_int8_t *, size_t, char *)
  34. __attribute__((__bounded__(__string__,1,2)))
  35. __attribute__((__bounded__(__minbytes__,3,SHA1_DIGEST_STRING_LENGTH)));
  36. #define HTONDIGEST(x) do { \
  37. x[0] = htonl(x[0]); \
  38. x[1] = htonl(x[1]); \
  39. x[2] = htonl(x[2]); \
  40. x[3] = htonl(x[3]); \
  41. x[4] = htonl(x[4]); } while (0)
  42. #define NTOHDIGEST(x) do { \
  43. x[0] = ntohl(x[0]); \
  44. x[1] = ntohl(x[1]); \
  45. x[2] = ntohl(x[2]); \
  46. x[3] = ntohl(x[3]); \
  47. x[4] = ntohl(x[4]); } while (0)
  48. #endif /* !WITH_OPENSSL */
  49. #endif /* _SHA1_H */