blob: fb81e4786945bdc6f60e0e3ccf3ecb7569b222e8 [file] [log] [blame]
naddy@openbsd.org4cdc5952017-12-14 21:07:39 +00001/* $OpenBSD: hash.c,v 1.4 2017/12/14 21:07:39 naddy Exp $ */
Darren Tuckerf45f78a2014-01-17 12:43:43 +11002
djm@openbsd.org7404b812019-11-29 00:11:21 +00003/* $OpenBSD: hash.c,v 1.6 2019/11/29 00:11:21 djm Exp $ */
naddy@openbsd.orga69bbb02018-01-13 00:24:09 +00004/*
5 * Public domain. Author: Christian Weisgerber <naddy@openbsd.org>
6 * API compatible reimplementation of function from nacl
7 */
djm@openbsd.org04c7e282017-12-18 02:25:15 +00008
Damien Miller0dedb702019-11-29 11:53:57 +11009#include "includes.h"
10
Damien Miller5be9d9e2013-12-07 11:24:01 +110011#include "crypto_api.h"
12
naddy@openbsd.org4cdc5952017-12-14 21:07:39 +000013#include <stdarg.h>
Damien Miller5be9d9e2013-12-07 11:24:01 +110014
djm@openbsd.org7404b812019-11-29 00:11:21 +000015#ifdef WITH_OPENSSL
16#include <openssl/evp.h>
Damien Miller5be9d9e2013-12-07 11:24:01 +110017
naddy@openbsd.org4cdc5952017-12-14 21:07:39 +000018int
19crypto_hash_sha512(unsigned char *out, const unsigned char *in,
20 unsigned long long inlen)
Damien Miller5be9d9e2013-12-07 11:24:01 +110021{
Damien Miller5be9d9e2013-12-07 11:24:01 +110022
djm@openbsd.org7404b812019-11-29 00:11:21 +000023 if (!EVP_Digest(in, inlen, out, NULL, EVP_sha512(), NULL))
24 return -1;
naddy@openbsd.org4cdc5952017-12-14 21:07:39 +000025 return 0;
Damien Miller5be9d9e2013-12-07 11:24:01 +110026}
djm@openbsd.org7404b812019-11-29 00:11:21 +000027
28#else
Darren Tucker2ff822e2019-11-29 20:21:36 +110029# ifdef HAVE_SHA2_H
30# include <sha2.h>
31# endif
djm@openbsd.org7404b812019-11-29 00:11:21 +000032
33int
34crypto_hash_sha512(unsigned char *out, const unsigned char *in,
35 unsigned long long inlen)
36{
37
38 SHA2_CTX ctx;
39
40 SHA512Init(&ctx);
41 SHA512Update(&ctx, in, inlen);
42 SHA512Final(out, &ctx);
43 return 0;
44}
45#endif /* WITH_OPENSSL */