crypto_hash_sha512.h 1.6 KB

1234567891011121314151617181920212223242526272829303132
  1. /* Added for Tor. */
  2. #include "crypto.h"
  3. /* Set 'out' to the 512-bit SHA512 hash of the 'len'-byte string in 'inp' */
  4. #define crypto_hash_sha512(out, inp, len) \
  5. crypto_digest512((char *)(out), (const char *)(inp), (len), DIGEST_SHA512)
  6. /* Set 'out' to the 512-bit SHA512 hash of the 'len1'-byte string in 'inp1',
  7. * concatenated with the 'len2'-byte string in 'inp2'. */
  8. #define crypto_hash_sha512_2(out, inp1, len1, inp2, len2) \
  9. do { \
  10. crypto_digest_t *sha_ctx_; \
  11. sha_ctx_ = crypto_digest512_new(DIGEST_SHA512); \
  12. crypto_digest_add_bytes(sha_ctx_, (const char *)(inp1), (len1)); \
  13. crypto_digest_add_bytes(sha_ctx_, (const char *)(inp2), (len2)); \
  14. crypto_digest_get_digest(sha_ctx_, (char *)out, 64); \
  15. crypto_digest_free(sha_ctx_); \
  16. } while (0)
  17. /* Set 'out' to the 512-bit SHA512 hash of the 'len1'-byte string in 'inp1',
  18. * concatenated with the 'len2'-byte string in 'inp2', concatenated with
  19. * the 'len3'-byte string in 'len3'. */
  20. #define crypto_hash_sha512_3(out, inp1, len1, inp2, len2, inp3, len3) \
  21. do { \
  22. crypto_digest_t *sha_ctx_; \
  23. sha_ctx_ = crypto_digest512_new(DIGEST_SHA512); \
  24. crypto_digest_add_bytes(sha_ctx_, (const char *)(inp1), (len1)); \
  25. crypto_digest_add_bytes(sha_ctx_, (const char *)(inp2), (len2)); \
  26. crypto_digest_add_bytes(sha_ctx_, (const char *)(inp3), (len3)); \
  27. crypto_digest_get_digest(sha_ctx_, (char *)out, 64); \
  28. crypto_digest_free(sha_ctx_); \
  29. } while(0)