freebsd-src/crypto/openssh/hash.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
781 B
C
Raw Normal View History

2021-02-14 21:04:52 +00:00
/* $OpenBSD: hash.c,v 1.6 2019/11/29 00:11:21 djm Exp $ */
2014-01-30 10:56:49 +00:00
/*
2018-05-06 12:27:04 +00:00
* Public domain. Author: Christian Weisgerber <naddy@openbsd.org>
* API compatible reimplementation of function from nacl
*/
2014-01-30 10:56:49 +00:00
2021-02-14 21:04:52 +00:00
#include "includes.h"
2014-01-30 10:56:49 +00:00
#include "crypto_api.h"
2018-05-06 12:27:04 +00:00
#include <stdarg.h>
2014-01-30 10:56:49 +00:00
2021-02-14 21:04:52 +00:00
#ifdef WITH_OPENSSL
#include <openssl/evp.h>
2014-01-30 10:56:49 +00:00
2018-05-06 12:27:04 +00:00
int
crypto_hash_sha512(unsigned char *out, const unsigned char *in,
unsigned long long inlen)
2014-01-30 10:56:49 +00:00
{
2021-02-14 21:04:52 +00:00
if (!EVP_Digest(in, inlen, out, NULL, EVP_sha512(), NULL))
return -1;
return 0;
}
#else
# ifdef HAVE_SHA2_H
# include <sha2.h>
# endif
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);
2018-05-06 12:27:04 +00:00
return 0;
2014-01-30 10:56:49 +00:00
}
2021-02-14 21:04:52 +00:00
#endif /* WITH_OPENSSL */