From 0cb266396ccf405f3465624b9f71e9d1168cb8d0 Mon Sep 17 00:00:00 2001 From: Nickolay Olshevsky Date: Tue, 28 May 2024 17:27:58 +0300 Subject: [PATCH] Be compatible with the updated botan's behaviour related to reworked botan_cipher_update() function. --- src/lib/crypto/symmetric.cpp | 2 +- src/librepgp/stream-def.h | 2 +- src/librepgp/stream-write.cpp | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/crypto/symmetric.cpp b/src/lib/crypto/symmetric.cpp index ee1531b46b..3341c65096 100644 --- a/src/lib/crypto/symmetric.cpp +++ b/src/lib/crypto/symmetric.cpp @@ -293,7 +293,7 @@ pgp_cipher_aead_update(pgp_crypt_t *crypt, uint8_t *out, const uint8_t *in, size } if ((outwr != len) || (inread != len)) { - RNP_LOG("wrong aead usage"); + RNP_LOG("wrong aead usage: %zu vs %zu, %zu vs %zu", outwr, len, inread, len); return false; } diff --git a/src/librepgp/stream-def.h b/src/librepgp/stream-def.h index 7a1108f827..583bfb4110 100644 --- a/src/librepgp/stream-def.h +++ b/src/librepgp/stream-def.h @@ -54,7 +54,7 @@ #define ST_FROM ("From") /* Preallocated cache length for AEAD encryption/decryption */ -#define PGP_AEAD_CACHE_LEN (PGP_INPUT_CACHE_SIZE + PGP_AEAD_MAX_TAG_LEN) +#define PGP_AEAD_CACHE_LEN (PGP_INPUT_CACHE_SIZE + 2 * PGP_AEAD_MAX_TAG_LEN) /* Maximum OpenPGP packet nesting level */ #define MAXIMUM_NESTING_LEVEL 32 diff --git a/src/librepgp/stream-write.cpp b/src/librepgp/stream-write.cpp index cf6d2e4d91..e438821fec 100644 --- a/src/librepgp/stream-write.cpp +++ b/src/librepgp/stream-write.cpp @@ -467,7 +467,8 @@ encrypted_dst_write_aead(pgp_dest_t *dst, const void *buf, size_t len) } while (len > 0) { - sz = std::min(sizeof(param->cache) - PGP_AEAD_MAX_TAG_LEN - param->cachelen, len); + /* 2 tags to align to the PGP_INPUT_CACHE_SIZE size */ + sz = std::min(sizeof(param->cache) - 2 * PGP_AEAD_MAX_TAG_LEN - param->cachelen, len); sz = std::min(sz, param->chunklen - param->chunkout - param->cachelen); memcpy(param->cache + param->cachelen, buf, sz); param->cachelen += sz;