hash.c 843 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* $OpenBSD: hash.c,v 1.4 2017/12/14 21:07:39 naddy Exp $ */
  2. /* $OpenBSD: hash.c,v 1.6 2019/11/29 00:11:21 djm Exp $ */
  3. /*
  4. * Public domain. Author: Christian Weisgerber <naddy@openbsd.org>
  5. * API compatible reimplementation of function from nacl
  6. */
  7. #include "includes.h"
  8. #include "crypto_api.h"
  9. #include <stdarg.h>
  10. #ifdef WITH_OPENSSL
  11. #include <openssl/evp.h>
  12. int
  13. crypto_hash_sha512(unsigned char *out, const unsigned char *in,
  14. unsigned long long inlen)
  15. {
  16. if (!EVP_Digest(in, inlen, out, NULL, EVP_sha512(), NULL))
  17. return -1;
  18. return 0;
  19. }
  20. #else
  21. # ifdef HAVE_SHA2_H
  22. # include <sha2.h>
  23. # endif
  24. int
  25. crypto_hash_sha512(unsigned char *out, const unsigned char *in,
  26. unsigned long long inlen)
  27. {
  28. SHA2_CTX ctx;
  29. SHA512Init(&ctx);
  30. SHA512Update(&ctx, in, inlen);
  31. SHA512Final(out, &ctx);
  32. return 0;
  33. }
  34. #endif /* WITH_OPENSSL */