diff options
author | defanor <defanor@uberspace.net> | 2023-09-28 19:19:18 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2023-09-28 19:19:18 +0300 |
commit | a7f47e7142127f54821c018b8037841cc727c00e (patch) | |
tree | a905ddbfacd9249d94413a9b6e81ec699183b41e /src/rexmpp_digest.h | |
parent | 153439d434bc914bcfaac403da84e3e9f0bf1367 (diff) |
Support Nettle and OpenSSL for hashing, in addition to Libgcrypt
Diffstat (limited to 'src/rexmpp_digest.h')
-rw-r--r-- | src/rexmpp_digest.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/rexmpp_digest.h b/src/rexmpp_digest.h new file mode 100644 index 0000000..77f198a --- /dev/null +++ b/src/rexmpp_digest.h @@ -0,0 +1,44 @@ +/** + @file rexmpp_digest.h + @brief Cryptographic functions + @author defanor <defanor@uberspace.net> + @date 2023 + @copyright MIT license. +*/ + +#ifndef REXMPP_DIGEST_H +#define REXMPP_DIGEST_H + +typedef enum { + REXMPP_DIGEST_SHA1, + REXMPP_DIGEST_SHA256, + REXMPP_DIGEST_SHA3_256 +} rexmpp_digest_algorithm; + + +#if defined(HAVE_GCRYPT) +#include <gcrypt.h> +typedef gcry_md_hd_t rexmpp_digest_t; +#elif defined(HAVE_NETTLE) +#include <nettle/nettle-meta.h> +struct rexmpp_digest { + const struct nettle_hash *nh; + void *nh_ctx; +}; +typedef struct rexmpp_digest rexmpp_digest_t; +#elif defined(HAVE_OPENSSL) +#include <openssl/evp.h> +typedef EVP_MD_CTX* rexmpp_digest_t; +#endif + +size_t rexmpp_digest_len (rexmpp_digest_algorithm algo); +int rexmpp_digest_buffer (rexmpp_digest_algorithm algo, + const void *in, + size_t in_len, + void *out, + size_t out_len); +int rexmpp_digest_init (rexmpp_digest_t *ctx, rexmpp_digest_algorithm algo); +int rexmpp_digest_update (rexmpp_digest_t *ctx, const void *in, size_t len); +int rexmpp_digest_finish (rexmpp_digest_t *ctx, void *out, size_t len); + +#endif |