diff options
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 34 |
1 files changed, 26 insertions, 8 deletions
@@ -1,27 +1,45 @@ | |||
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 |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "includes.h" | ||
10 | |||
9 | #include "crypto_api.h" | 11 | #include "crypto_api.h" |
10 | 12 | ||
11 | #include <stdarg.h> | 13 | #include <stdarg.h> |
12 | 14 | ||
13 | #include "digest.h" | 15 | #ifdef WITH_OPENSSL |
14 | #include "log.h" | 16 | #include <openssl/evp.h> |
15 | #include "ssherr.h" | ||
16 | 17 | ||
17 | int | 18 | int |
18 | crypto_hash_sha512(unsigned char *out, const unsigned char *in, | 19 | crypto_hash_sha512(unsigned char *out, const unsigned char *in, |
19 | unsigned long long inlen) | 20 | unsigned long long inlen) |
20 | { | 21 | { |
21 | int r; | ||
22 | 22 | ||
23 | if ((r = ssh_digest_memory(SSH_DIGEST_SHA512, in, inlen, out, | 23 | if (!EVP_Digest(in, inlen, out, NULL, EVP_sha512(), NULL)) |
24 | crypto_hash_sha512_BYTES)) != 0) | 24 | return -1; |
25 | fatal("%s: %s", __func__, ssh_err(r)); | 25 | return 0; |
26 | } | ||
27 | |||
28 | #else | ||
29 | # ifdef HAVE_SHA2_H | ||
30 | # include <sha2.h> | ||
31 | # endif | ||
32 | |||
33 | int | ||
34 | crypto_hash_sha512(unsigned char *out, const unsigned char *in, | ||
35 | unsigned long long inlen) | ||
36 | { | ||
37 | |||
38 | SHA2_CTX ctx; | ||
39 | |||
40 | SHA512Init(&ctx); | ||
41 | SHA512Update(&ctx, in, inlen); | ||
42 | SHA512Final(out, &ctx); | ||
26 | return 0; | 43 | return 0; |
27 | } | 44 | } |
45 | #endif /* WITH_OPENSSL */ | ||