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
7 #include "crypto_api.h"
8
9 #include <stdarg.h>
10
11 #ifdef WITH_OPENSSL
12 #include <openssl/evp.h>
13
14 int
crypto_hash_sha512(unsigned char * out,const unsigned char * in,unsigned long long inlen)15 crypto_hash_sha512(unsigned char *out, const unsigned char *in,
16 unsigned long long inlen)
17 {
18
19 if (!EVP_Digest(in, inlen, out, NULL, EVP_sha512(), NULL))
20 return -1;
21 return 0;
22 }
23
24 #else
25 #include <sha2.h>
26
27 int
crypto_hash_sha512(unsigned char * out,const unsigned char * in,unsigned long long inlen)28 crypto_hash_sha512(unsigned char *out, const unsigned char *in,
29 unsigned long long inlen)
30 {
31
32 SHA2_CTX ctx;
33
34 SHA512Init(&ctx);
35 SHA512Update(&ctx, in, inlen);
36 SHA512Final(out, &ctx);
37 return 0;
38 }
39 #endif /* WITH_OPENSSL */
40