diff options
author | David Macek <david.macek.0@gmail.com> | 2022-04-17 19:52:25 +0200 |
---|---|---|
committer | David Macek <david.macek.0@gmail.com> | 2022-04-17 19:52:25 +0200 |
commit | b55a9d14721832ae9f03746836ca24a230c5c2f1 (patch) | |
tree | 2a996b4e8d317232bffab5922d1f7c2c1b5c8ab4 | |
parent | b1aa465b21fce2e4a0108360ba9b19e1e1aff02b (diff) | |
download | libarchive-b55a9d14721832ae9f03746836ca24a230c5c2f1.tar.gz |
archive_digest: Use correct providers with Windows Crypto
Trying to use SHA256, SHA384 or SHA512 with mtree when linked against
Windows Crypto would result in silent failure. The call to
`CryptCreateHash` would fail with 0x80090008. The docs[1] say that
these algorithms require a different crypto provider, so let's make
that a parameter for `win_crypto_init` and choose at the call site along
with the algorithm.
[1] https://docs.microsoft.com/en-us/windows/win32/seccrypto/alg-id
Signed-off-by: David Macek <david.macek.0@gmail.com>
-rw-r--r-- | libarchive/archive_digest.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/libarchive/archive_digest.c b/libarchive/archive_digest.c index a7bd5f02..3361b19a 100644 --- a/libarchive/archive_digest.c +++ b/libarchive/archive_digest.c @@ -49,16 +49,16 @@ * Initialize a Message digest. */ static int -win_crypto_init(Digest_CTX *ctx, ALG_ID algId) +win_crypto_init(Digest_CTX *ctx, DWORD prov, ALG_ID algId) { ctx->valid = 0; if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { + prov, CRYPT_VERIFYCONTEXT)) { if (GetLastError() != (DWORD)NTE_BAD_KEYSET) return (ARCHIVE_FAILED); if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, - PROV_RSA_FULL, CRYPT_NEWKEYSET)) + prov, CRYPT_NEWKEYSET)) return (ARCHIVE_FAILED); } @@ -276,7 +276,7 @@ __archive_md5final(archive_md5_ctx *ctx, void *md) static int __archive_md5init(archive_md5_ctx *ctx) { - return (win_crypto_init(ctx, CALG_MD5)); + return (win_crypto_init(ctx, PROV_RSA_FULL, CALG_MD5)); } static int @@ -659,7 +659,7 @@ __archive_sha1final(archive_sha1_ctx *ctx, void *md) static int __archive_sha1init(archive_sha1_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA1)); + return (win_crypto_init(ctx, PROV_RSA_FULL, CALG_SHA1)); } static int @@ -919,7 +919,7 @@ __archive_sha256final(archive_sha256_ctx *ctx, void *md) static int __archive_sha256init(archive_sha256_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA_256)); + return (win_crypto_init(ctx, PROV_RSA_AES, CALG_SHA_256)); } static int @@ -1155,7 +1155,7 @@ __archive_sha384final(archive_sha384_ctx *ctx, void *md) static int __archive_sha384init(archive_sha384_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA_384)); + return (win_crypto_init(ctx, PROV_RSA_AES, CALG_SHA_384)); } static int @@ -1415,7 +1415,7 @@ __archive_sha512final(archive_sha512_ctx *ctx, void *md) static int __archive_sha512init(archive_sha512_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA_512)); + return (win_crypto_init(ctx, PROV_RSA_AES, CALG_SHA_512)); } static int |