summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-11-29 00:11:21 +0000
committerDamien Miller <djm@mindrot.org>2019-11-29 11:17:39 +1100
commit7404b81f25a4a7847380c0f0cf7f1bea5f0a5cd3 (patch)
tree16f7be2097be01c679494731ac3694ac9a42d87e /hash.c
parentd39a865b7af93a7a9b5a64cf7cf0ef4396c80ba3 (diff)
upstream: perform hashing directly in crypto_hash_sha512() using
libcrypto or libc SHA512 functions rather than calling ssh_digest_memory(); avoids many dependencies on ssh code that complicate standalone use of ed25519, as we want to do in sk-dummy.so OpenBSD-Commit-ID: 5a3c37593d3ba7add037b587cec44aaea088496d
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/hash.c b/hash.c
index 5875d41fa..a35027870 100644
--- a/hash.c
+++ b/hash.c
@@ -1,6 +1,6 @@
1/* $OpenBSD: hash.c,v 1.4 2017/12/14 21:07:39 naddy Exp $ */ 1/* $OpenBSD: hash.c,v 1.4 2017/12/14 21:07:39 naddy Exp $ */
2 2
3/* $OpenBSD: hash.c,v 1.5 2018/01/13 00:24:09 naddy Exp $ */ 3/* $OpenBSD: hash.c,v 1.6 2019/11/29 00:11:21 djm Exp $ */
4/* 4/*
5 * Public domain. Author: Christian Weisgerber <naddy@openbsd.org> 5 * Public domain. Author: Christian Weisgerber <naddy@openbsd.org>
6 * API compatible reimplementation of function from nacl 6 * API compatible reimplementation of function from nacl
@@ -10,18 +10,32 @@
10 10
11#include <stdarg.h> 11#include <stdarg.h>
12 12
13#include "digest.h" 13#ifdef WITH_OPENSSL
14#include "log.h" 14#include <openssl/evp.h>
15#include "ssherr.h"
16 15
17int 16int
18crypto_hash_sha512(unsigned char *out, const unsigned char *in, 17crypto_hash_sha512(unsigned char *out, const unsigned char *in,
19 unsigned long long inlen) 18 unsigned long long inlen)
20{ 19{
21 int r;
22 20
23 if ((r = ssh_digest_memory(SSH_DIGEST_SHA512, in, inlen, out, 21 if (!EVP_Digest(in, inlen, out, NULL, EVP_sha512(), NULL))
24 crypto_hash_sha512_BYTES)) != 0) 22 return -1;
25 fatal("%s: %s", __func__, ssh_err(r));
26 return 0; 23 return 0;
27} 24}
25
26#else
27#include <sha2.h>
28
29int
30crypto_hash_sha512(unsigned char *out, const unsigned char *in,
31 unsigned long long inlen)
32{
33
34 SHA2_CTX ctx;
35
36 SHA512Init(&ctx);
37 SHA512Update(&ctx, in, inlen);
38 SHA512Final(out, &ctx);
39 return 0;
40}
41#endif /* WITH_OPENSSL */