Changeset View
Changeset View
Standalone View
Standalone View
hash.c
/* $OpenBSD: hash.c,v 1.4 2017/12/14 21:07:39 naddy Exp $ */ | /* $OpenBSD: hash.c,v 1.4 2017/12/14 21:07:39 naddy Exp $ */ | ||||
/* $OpenBSD: hash.c,v 1.5 2018/01/13 00:24:09 naddy Exp $ */ | /* $OpenBSD: hash.c,v 1.6 2019/11/29 00:11:21 djm Exp $ */ | ||||
/* | /* | ||||
* Public domain. Author: Christian Weisgerber <naddy@openbsd.org> | * Public domain. Author: Christian Weisgerber <naddy@openbsd.org> | ||||
* API compatible reimplementation of function from nacl | * API compatible reimplementation of function from nacl | ||||
*/ | */ | ||||
#include "includes.h" | |||||
#include "crypto_api.h" | #include "crypto_api.h" | ||||
#include <stdarg.h> | #include <stdarg.h> | ||||
#include "digest.h" | #ifdef WITH_OPENSSL | ||||
#include "log.h" | #include <openssl/evp.h> | ||||
#include "ssherr.h" | |||||
int | int | ||||
crypto_hash_sha512(unsigned char *out, const unsigned char *in, | crypto_hash_sha512(unsigned char *out, const unsigned char *in, | ||||
unsigned long long inlen) | unsigned long long inlen) | ||||
{ | { | ||||
int r; | |||||
if ((r = ssh_digest_memory(SSH_DIGEST_SHA512, in, inlen, out, | if (!EVP_Digest(in, inlen, out, NULL, EVP_sha512(), NULL)) | ||||
crypto_hash_sha512_BYTES)) != 0) | return -1; | ||||
fatal("%s: %s", __func__, ssh_err(r)); | |||||
return 0; | 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); | |||||
return 0; | |||||
} | |||||
#endif /* WITH_OPENSSL */ |