sha256.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * SHA-256 implementation.
  3. *
  4. * Copyright (c) 2010 Ilya O. Levin, http://www.literatecode.com
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifdef _MSC_VER
  19. #ifndef uint8_t
  20. typedef unsigned __int8 uint8_t;
  21. #endif
  22. #ifndef uint32_t
  23. typedef unsigned __int32 uint32_t;
  24. #endif
  25. #ifndef uint64_t
  26. typedef __int64 int64_t;
  27. typedef unsigned __int64 uint64_t;
  28. #endif
  29. #else
  30. #include <stdint.h>
  31. #endif
  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #endif
  36. typedef struct {
  37. uint32_t buf[16];
  38. uint32_t hash[8];
  39. uint32_t len[2];
  40. } sha256_context;
  41. void sha256_init(sha256_context *);
  42. void sha256_hash(sha256_context *, uint8_t * /* data */, uint32_t /* len */);
  43. void sha256_done(sha256_context *, uint8_t * /* hash */);
  44. #ifdef __cplusplus
  45. }
  46. #endif