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