xref: /dragonfly/crypto/openssh/hash.c (revision 50a69bb5)
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 "includes.h"
8 
9 #include "crypto_api.h"
10 
11 #include <stdarg.h>
12 
13 #ifdef WITH_OPENSSL
14 #include <openssl/evp.h>
15 
16 int
crypto_hash_sha512(unsigned char * out,const unsigned char * in,unsigned long long inlen)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 # ifdef HAVE_SHA2_H
28 #  include <sha2.h>
29 # endif
30 
31 int
crypto_hash_sha512(unsigned char * out,const unsigned char * in,unsigned long long inlen)32 crypto_hash_sha512(unsigned char *out, const unsigned char *in,
33     unsigned long long inlen)
34 {
35 
36 	SHA2_CTX ctx;
37 
38 	SHA512Init(&ctx);
39 	SHA512Update(&ctx, in, inlen);
40 	SHA512Final(out, &ctx);
41 	return 0;
42 }
43 #endif /* WITH_OPENSSL */
44