naddy@openbsd.org | 4cdc595 | 2017-12-14 21:07:39 +0000 | [diff] [blame] | 1 | /* $OpenBSD: hash.c,v 1.4 2017/12/14 21:07:39 naddy Exp $ */ |
Darren Tucker | f45f78a | 2014-01-17 12:43:43 +1100 | [diff] [blame] | 2 | |
djm@openbsd.org | 7404b81 | 2019-11-29 00:11:21 +0000 | [diff] [blame] | 3 | /* $OpenBSD: hash.c,v 1.6 2019/11/29 00:11:21 djm Exp $ */ |
naddy@openbsd.org | a69bbb0 | 2018-01-13 00:24:09 +0000 | [diff] [blame] | 4 | /* |
| 5 | * Public domain. Author: Christian Weisgerber <naddy@openbsd.org> |
| 6 | * API compatible reimplementation of function from nacl |
| 7 | */ |
djm@openbsd.org | 04c7e28 | 2017-12-18 02:25:15 +0000 | [diff] [blame] | 8 | |
Damien Miller | 0dedb70 | 2019-11-29 11:53:57 +1100 | [diff] [blame] | 9 | #include "includes.h" |
| 10 | |
Damien Miller | 5be9d9e | 2013-12-07 11:24:01 +1100 | [diff] [blame] | 11 | #include "crypto_api.h" |
| 12 | |
naddy@openbsd.org | 4cdc595 | 2017-12-14 21:07:39 +0000 | [diff] [blame] | 13 | #include <stdarg.h> |
Damien Miller | 5be9d9e | 2013-12-07 11:24:01 +1100 | [diff] [blame] | 14 | |
djm@openbsd.org | 7404b81 | 2019-11-29 00:11:21 +0000 | [diff] [blame] | 15 | #ifdef WITH_OPENSSL |
| 16 | #include <openssl/evp.h> |
Damien Miller | 5be9d9e | 2013-12-07 11:24:01 +1100 | [diff] [blame] | 17 | |
naddy@openbsd.org | 4cdc595 | 2017-12-14 21:07:39 +0000 | [diff] [blame] | 18 | int |
| 19 | crypto_hash_sha512(unsigned char *out, const unsigned char *in, |
| 20 | unsigned long long inlen) |
Damien Miller | 5be9d9e | 2013-12-07 11:24:01 +1100 | [diff] [blame] | 21 | { |
Damien Miller | 5be9d9e | 2013-12-07 11:24:01 +1100 | [diff] [blame] | 22 | |
djm@openbsd.org | 7404b81 | 2019-11-29 00:11:21 +0000 | [diff] [blame] | 23 | if (!EVP_Digest(in, inlen, out, NULL, EVP_sha512(), NULL)) |
| 24 | return -1; |
naddy@openbsd.org | 4cdc595 | 2017-12-14 21:07:39 +0000 | [diff] [blame] | 25 | return 0; |
Damien Miller | 5be9d9e | 2013-12-07 11:24:01 +1100 | [diff] [blame] | 26 | } |
djm@openbsd.org | 7404b81 | 2019-11-29 00:11:21 +0000 | [diff] [blame] | 27 | |
| 28 | #else |
Darren Tucker | 2ff822e | 2019-11-29 20:21:36 +1100 | [diff] [blame] | 29 | # ifdef HAVE_SHA2_H |
| 30 | # include <sha2.h> |
| 31 | # endif |
djm@openbsd.org | 7404b81 | 2019-11-29 00:11:21 +0000 | [diff] [blame] | 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); |
| 43 | return 0; |
| 44 | } |
| 45 | #endif /* WITH_OPENSSL */ |