diff options
-rw-r--r-- | hash.c | 30 |
1 files changed, 22 insertions, 8 deletions
@@ -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 | ||
17 | int | 16 | int |
18 | crypto_hash_sha512(unsigned char *out, const unsigned char *in, | 17 | crypto_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 | |||
29 | int | ||
30 | crypto_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 */ | ||