Skip to content

Commit 5e6d478

Browse files
schwabecron2
authored andcommitted
Do not underestimate number of encrypted/decrypted AEAD blocks
Even though the current code typically counts all the encrypted/decrypted traffic, this is only the case because of the specific implementation of OpenSSL at the moment. Instead of counting the length returned by one call only, count all the encrypted/decrypted bytes. Other implementations that use AES-GCM (like IPSec, MacSEC, TLS 1.2) (currently) do not honour these usage limits at all. This is the reason that I also currently do not consider the lack/improper validation in our code to be a security vulnerability. In the current state implementations/protocol that lack this feature altogether are not considered vulnerable. Reported by: <[email protected]> Change-Id: I429d768fb33ef2c58484287d4091440ad8599053 Signed-off-by: Arne Schwabe <[email protected]> Acked-by: Gert Doering <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1358 Message-Id: <[email protected]> Signed-off-by: Gert Doering <[email protected]>
1 parent 985f4ea commit 5e6d478

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/openvpn/crypto.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ openvpn_encrypt_aead(struct buffer *buf, struct buffer work, struct crypto_optio
152152
ASSERT(cipher_ctx_update(ctx->cipher, BEND(&work), &outlen, BPTR(buf), BLEN(buf)));
153153
ASSERT(buf_inc_len(&work, outlen));
154154

155-
/* update number of plaintext blocks encrypted. Use the (x + (n-1))/n trick
156-
* to round up the result to the number of blocks used */
157-
const int blocksize = AEAD_LIMIT_BLOCKSIZE;
158-
opt->key_ctx_bi.encrypt.plaintext_blocks += (outlen + (blocksize - 1)) / blocksize;
159-
160155
/* Flush the encryption buffer */
161156
ASSERT(cipher_ctx_final(ctx->cipher, BEND(&work), &outlen));
162157
ASSERT(buf_inc_len(&work, outlen));
163158

159+
/* update number of plaintext blocks encrypted. Use the (x + (n-1))/n trick
160+
* to round up the result to the number of blocks used */
161+
const int blocksize = AEAD_LIMIT_BLOCKSIZE;
162+
opt->key_ctx_bi.encrypt.plaintext_blocks += (BLEN(&work) + (blocksize - 1)) / blocksize;
163+
164164
/* if the tag is at end the end, allocate it now */
165165
if (use_epoch_data_format)
166166
{
@@ -580,11 +580,10 @@ openvpn_decrypt_aead(struct buffer *buf, struct buffer work, struct crypto_optio
580580
goto error_exit;
581581
}
582582

583-
584583
/* update number of plaintext blocks decrypted. Use the (x + (n-1))/n trick
585584
* to round up the result to the number of blocks used. */
586585
const int blocksize = AEAD_LIMIT_BLOCKSIZE;
587-
opt->key_ctx_bi.decrypt.plaintext_blocks += (outlen + (blocksize - 1)) / blocksize;
586+
opt->key_ctx_bi.decrypt.plaintext_blocks += (BLEN(&work) + (blocksize - 1)) / blocksize;
588587

589588
*buf = work;
590589

0 commit comments

Comments
 (0)