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