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