summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Matuska <martin@matuska.org>2020-11-04 07:49:36 +0100
committerMartin Matuska <martin@matuska.org>2020-11-04 08:05:31 +0100
commitf6154ee30278a98279891aa6e5705196337469b2 (patch)
tree4bb62e29da59cd6a64b187eb5d4c9577a114a771
parent9a5488f08c6def7451871fd4af384c6f51d184cf (diff)
downloadlibarchive-f6154ee30278a98279891aa6e5705196337469b2.tar.gz
archive_cryptor: use new Nettle AES interface on Nettle 3.0 and higher
-rw-r--r--libarchive/archive_cryptor.c30
-rw-r--r--libarchive/archive_cryptor_private.h8
2 files changed, 21 insertions, 17 deletions
diff --git a/libarchive/archive_cryptor.c b/libarchive/archive_cryptor.c
index 486e2999..d4bca906 100644
--- a/libarchive/archive_cryptor.c
+++ b/libarchive/archive_cryptor.c
@@ -347,29 +347,25 @@ aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
static int
aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
{
-#if NETTLE_VERSION_MAJOR < 3 || \
- (NETTLE_VERSION_MAJOR == 3 && NETTLE_VERSION_MINOR < 5)
+#if NETTLE_VERSION_MAJOR < 3
aes_set_encrypt_key(&ctx->ctx, ctx->key_len, ctx->key);
aes_encrypt(&ctx->ctx, AES_BLOCK_SIZE, ctx->encr_buf, ctx->nonce);
#else
switch(ctx->key_len) {
- case 16:
- aes128_set_encrypt_key((struct aes128_ctx *)&ctx->ctx.u.ctx128,
- ctx->key);
- aes128_encrypt((struct aes128_ctx *)&ctx->ctx.u.ctx128,
- AES_BLOCK_SIZE, ctx->encr_buf, ctx->nonce);
+ case AES128_KEY_SIZE:
+ aes128_set_encrypt_key(&ctx->ctx.c128, ctx->key);
+ aes128_encrypt(&ctx->ctx.c128, AES_BLOCK_SIZE, ctx->encr_buf,
+ ctx->nonce);
break;
- case 24:
- aes192_set_encrypt_key((struct aes192_ctx *)&ctx->ctx.u.ctx192,
- ctx->key);
- aes192_encrypt((struct aes192_ctx *)&ctx->ctx.u.ctx192,
- AES_BLOCK_SIZE, ctx->encr_buf, ctx->nonce);
+ case AES192_KEY_SIZE:
+ aes192_set_encrypt_key(&ctx->ctx.c192, ctx->key);
+ aes192_encrypt(&ctx->ctx.c192, AES_BLOCK_SIZE, ctx->encr_buf,
+ ctx->nonce);
break;
- case 32:
- aes256_set_encrypt_key((struct aes256_ctx *)&ctx->ctx.u.ctx256,
- ctx->key);
- aes256_encrypt((struct aes256_ctx *)&ctx->ctx.u.ctx256,
- AES_BLOCK_SIZE, ctx->encr_buf, ctx->nonce);
+ case AES256_KEY_SIZE:
+ aes256_set_encrypt_key(&ctx->ctx.c256, ctx->key);
+ aes256_encrypt(&ctx->ctx.c256, AES_BLOCK_SIZE, ctx->encr_buf,
+ ctx->nonce);
break;
default:
return -1;
diff --git a/libarchive/archive_cryptor_private.h b/libarchive/archive_cryptor_private.h
index bcd6c583..16b6d16f 100644
--- a/libarchive/archive_cryptor_private.h
+++ b/libarchive/archive_cryptor_private.h
@@ -107,7 +107,15 @@ typedef struct {
#include <nettle/version.h>
typedef struct {
+#if NETTLE_VERSION_MAJOR < 3
struct aes_ctx ctx;
+#else
+ union {
+ struct aes128_ctx c128;
+ struct aes192_ctx c192;
+ struct aes256_ctx c256;
+ } ctx;
+#endif
uint8_t key[AES_MAX_KEY_SIZE];
unsigned key_len;
uint8_t nonce[AES_BLOCK_SIZE];