summaryrefslogtreecommitdiffstats
path: root/Utilities/cmlibarchive/libarchive/archive_hmac.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-02-13 14:30:35 (GMT)
committerBrad King <brad.king@kitware.com>2020-02-13 17:57:52 (GMT)
commit5d8b3aec0cb8652ae867ff08d2e7bfa2060138dd (patch)
tree3d39cf776650ac89bedec4fc1d251ff70e6fc8d7 /Utilities/cmlibarchive/libarchive/archive_hmac.c
parent9a27ecd4162aebfb595b7a02b958b7dfb95256d8 (diff)
parent8cce62295a5ddca3e0d1fd7cff0229054972dfe3 (diff)
downloadCMake-5d8b3aec0cb8652ae867ff08d2e7bfa2060138dd.zip
CMake-5d8b3aec0cb8652ae867ff08d2e7bfa2060138dd.tar.gz
CMake-5d8b3aec0cb8652ae867ff08d2e7bfa2060138dd.tar.bz2
Merge branch 'upstream-LibArchive' into update-libarchive
* upstream-LibArchive: LibArchive 2020-02-11 (3288ebb0) Also manually restore content from upstream libarchive's main `CMakeLists.txt` file that was removed by previous commits and exclude it with `IF(0)` blocks. Do this as an evil merge so that `git blame -C` can follow the content to upstream.
Diffstat (limited to 'Utilities/cmlibarchive/libarchive/archive_hmac.c')
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_hmac.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/Utilities/cmlibarchive/libarchive/archive_hmac.c b/Utilities/cmlibarchive/libarchive/archive_hmac.c
index f299655..2a9d04c 100644
--- a/Utilities/cmlibarchive/libarchive/archive_hmac.c
+++ b/Utilities/cmlibarchive/libarchive/archive_hmac.c
@@ -83,6 +83,9 @@ __hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx)
static int
__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len)
{
+#ifdef __GNUC__
+#pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
BCRYPT_ALG_HANDLE hAlg;
BCRYPT_HASH_HANDLE hHash;
DWORD hash_len;
@@ -147,6 +150,53 @@ __hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx)
}
}
+#elif defined(HAVE_LIBMBEDCRYPTO) && defined(HAVE_MBEDTLS_MD_H)
+
+static int
+__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len)
+{
+ const mbedtls_md_info_t *info;
+ int ret;
+
+ mbedtls_md_init(ctx);
+ info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA1);
+ if (info == NULL) {
+ mbedtls_md_free(ctx);
+ return (-1);
+ }
+ ret = mbedtls_md_setup(ctx, info, 1);
+ if (ret != 0) {
+ mbedtls_md_free(ctx);
+ return (-1);
+ }
+ ret = mbedtls_md_hmac_starts(ctx, key, key_len);
+ if (ret != 0) {
+ mbedtls_md_free(ctx);
+ return (-1);
+ }
+ return 0;
+}
+
+static void
+__hmac_sha1_update(archive_hmac_sha1_ctx *ctx, const uint8_t *data,
+ size_t data_len)
+{
+ mbedtls_md_hmac_update(ctx, data, data_len);
+}
+
+static void __hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len)
+{
+ (void)out_len; /* UNUSED */
+
+ mbedtls_md_hmac_finish(ctx, out);
+}
+
+static void __hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx)
+{
+ mbedtls_md_free(ctx);
+ memset(ctx, 0, sizeof(*ctx));
+}
+
#elif defined(HAVE_LIBNETTLE) && defined(HAVE_NETTLE_HMAC_H)
static int
@@ -198,6 +248,7 @@ static void
__hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len)
{
unsigned int len = (unsigned int)*out_len;
+
HMAC_Final(*ctx, out, &len);
*out_len = len;
}