2017-12-14 22:07:39 +01:00
|
|
|
/* $OpenBSD: hash.c,v 1.4 2017/12/14 21:07:39 naddy Exp $ */
|
2014-01-17 02:43:43 +01:00
|
|
|
|
2019-11-29 01:11:21 +01:00
|
|
|
/* $OpenBSD: hash.c,v 1.6 2019/11/29 00:11:21 djm Exp $ */
|
2018-01-13 01:24:09 +01:00
|
|
|
/*
|
|
|
|
* Public domain. Author: Christian Weisgerber <naddy@openbsd.org>
|
|
|
|
* API compatible reimplementation of function from nacl
|
|
|
|
*/
|
2017-12-18 03:25:15 +01:00
|
|
|
|
2019-11-29 01:53:57 +01:00
|
|
|
#include "includes.h"
|
|
|
|
|
2013-12-07 01:24:01 +01:00
|
|
|
#include "crypto_api.h"
|
|
|
|
|
2017-12-14 22:07:39 +01:00
|
|
|
#include <stdarg.h>
|
2013-12-07 01:24:01 +01:00
|
|
|
|
2019-11-29 01:11:21 +01:00
|
|
|
#ifdef WITH_OPENSSL
|
|
|
|
#include <openssl/evp.h>
|
2013-12-07 01:24:01 +01:00
|
|
|
|
2017-12-14 22:07:39 +01:00
|
|
|
int
|
|
|
|
crypto_hash_sha512(unsigned char *out, const unsigned char *in,
|
|
|
|
unsigned long long inlen)
|
2013-12-07 01:24:01 +01:00
|
|
|
{
|
|
|
|
|
2019-11-29 01:11:21 +01:00
|
|
|
if (!EVP_Digest(in, inlen, out, NULL, EVP_sha512(), NULL))
|
|
|
|
return -1;
|
2017-12-14 22:07:39 +01:00
|
|
|
return 0;
|
2013-12-07 01:24:01 +01:00
|
|
|
}
|
2019-11-29 01:11:21 +01:00
|
|
|
|
|
|
|
#else
|
2019-11-29 10:21:36 +01:00
|
|
|
# ifdef HAVE_SHA2_H
|
|
|
|
# include <sha2.h>
|
|
|
|
# endif
|
2019-11-29 01:11:21 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
crypto_hash_sha512(unsigned char *out, const unsigned char *in,
|
|
|
|
unsigned long long inlen)
|
|
|
|
{
|
|
|
|
|
|
|
|
SHA2_CTX ctx;
|
|
|
|
|
|
|
|
SHA512Init(&ctx);
|
|
|
|
SHA512Update(&ctx, in, inlen);
|
|
|
|
SHA512Final(out, &ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* WITH_OPENSSL */
|