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