From: "plaisthos (Code Review)" Date: Fri, 7 Nov 2025 12:44:40 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="mpZt/PoukgU="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Do not underestimate number of encrypted/decrypted AEAD blocks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --mpZt/PoukgU= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1358?usp=3Demail to review the following change. Change subject: Do not underestimate number of encrypted/decrypted AEAD bl= ocks ...................................................................... Do not underestimate number of encrypted/decrypted AEAD blocks Even thought 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 AES-GCM (like IPSec, MacSEC, TLS 1.2) currently do not honour these usage limits at all. So this currently not something that I consider to be security vulnerability since currently this something that enhances security but is not yet required so to say. Reported by: Change-Id: I429d768fb33ef2c58484287d4091440ad8599053 Signed-off-by: Arne Schwabe --- M src/openvpn/crypto.c 1 file changed, 6 insertions(+), 7 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/58/1358/1 diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 307d1ee..8049b3a 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -152,15 +152,15 @@ ASSERT(cipher_ctx_update(ctx->cipher, BEND(&work), &outlen, BPTR(buf),= BLEN(buf))); ASSERT(buf_inc_len(&work, outlen)); - /* update number of plaintext blocks encrypted. Use the (x + (n-1))/n = trick - * to round up the result to the number of blocks used */ - const int blocksize =3D AEAD_LIMIT_BLOCKSIZE; - opt->key_ctx_bi.encrypt.plaintext_blocks +=3D (outlen + (blocksize - 1= )) / blocksize; - /* Flush the encryption buffer */ ASSERT(cipher_ctx_final(ctx->cipher, BEND(&work), &outlen)); ASSERT(buf_inc_len(&work, outlen)); + /* update number of plaintext blocks encrypted. Use the (x + (n-1))/n = trick + * to round up the result to the number of blocks used */ + const int blocksize =3D AEAD_LIMIT_BLOCKSIZE; + opt->key_ctx_bi.encrypt.plaintext_blocks +=3D (BLEN(&work) + (blocksiz= e - 1)) / blocksize; + /* if the tag is at end the end, allocate it now */ if (use_epoch_data_format) { @@ -580,11 +580,10 @@ goto error_exit; } - /* update number of plaintext blocks decrypted. Use the (x + (n-1))/n = trick * to round up the result to the number of blocks used. */ const int blocksize =3D AEAD_LIMIT_BLOCKSIZE; - opt->key_ctx_bi.decrypt.plaintext_blocks +=3D (outlen + (blocksize - 1= )) / blocksize; + opt->key_ctx_bi.decrypt.plaintext_blocks +=3D (BLEN(&work) + (blocksiz= e - 1)) / blocksize; *buf =3D work; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1358?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I429d768fb33ef2c58484287d4091440ad8599053 Gerrit-Change-Number: 1358 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld --mpZt/PoukgU= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: flichtenheld.

plaisthos would like flichtenheld to review this change.

V= iew Change

Do not underestimate number of encrypted/de=
crypted  AEAD blocks

Even thought the current code typically counts = all the encrypted/decrypted
traffic, this is only the case because of th= e specific implementation
of OpenSSL at the moment.

Instead of co= unting the length returned by one call only, count all
the encrypted/dec= rypted bytes.

Other implementations that AES-GCM (like IPSec, MacSEC= , TLS 1.2) currently
do not honour these usage limits at all. So this cu= rrently not something
that I consider to be security vulnerability since= currently this something
that enhances security but is not yet required= so to say.

Reported by: <stephan@...2953...>

Change-Id= : I429d768fb33ef2c58484287d4091440ad8599053
Signed-off-by: Arne Schwabe = <arne@...1227...>
---
M src/openvpn/crypto.c
1 file changed,= 6 insertions(+), 7 deletions(-)

git pull ssh:=
//gerrit.openvpn.net:29418/openvpn refs/changes/58/1358/1
diff --=
git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 307= d1ee..8049b3a 100644
--- a/src/openvpn/crypto.c
<= span>+++ b/src/openvpn/crypto.c
@@ -152,15 +152,15 @@
ASSERT(cipher_ctx_update(ctx->cipher, BEND(&work), &= amp;outlen, BPTR(buf), BLEN(buf)));
ASSERT(buf_inc_len= (&work, outlen));

- /* update number of plaintext blocks encrypted. Use t= he (x + (n-1))/n trick
= - * to round up the result to the number of blocks used */
- const int blocksize =3D AEAD_L= IMIT_BLOCKSIZE;

- op= t->key_ctx_bi.encrypt.plaintext_blocks +=3D (outlen + (blocksize - 1)) /= blocksize;
- /* Flush the encryption buffer */
ASSERT(c= ipher_ctx_final(ctx->cipher, BEND(&work), &outlen));
<= span> ASSERT(buf_inc_len(&work, outlen));
<= br>+ /* update number of pla= intext blocks encrypted. Use the (x + (n-1))/n trick
+ * to round up the result to the numb= er of blocks used */
= + const int blocksize =3D AEAD_LIMIT_BLOCKSIZE;
+ opt->key_ctx_bi.encrypt.plaintext_blo= cks +=3D (BLEN(&work) + (blocksize - 1)) / blocksize;
+
/* if the tag i= s at end the end, allocate it now */
if (use_epoch_dat= a_format)
{
@@ -580,11 +580,10 @@
goto error_exit;
}

-
= /* update number of plaintext blocks decrypted. Use the (x + (n-1))/n t= rick
* to round up the result to the number of blocks= used. */
const int blocksize =3D AEAD_LIMIT_BLOCKSIZE= ;
- opt->key_ctx_= bi.decrypt.plaintext_blocks +=3D (outlen + (blocksize - 1)) / blocksize;
+ opt->key_ctx_bi= .decrypt.plaintext_blocks +=3D (BLEN(&work) + (blocksize - 1)) / blocks= ize;

*buf =3D work;
=

To view, visit change 1358. To unsubscrib= e, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I429d768fb33ef2c58484287d409= 1440ad8599053
Gerrit-Change-Number: 1358
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --mpZt/PoukgU=--