aes/gcm maximum plaintext size; handling of large files

Lana Deere <[email protected]> Sun, 10 Aug 2025 17:53:42 -0700 (PDT)
Newsgroups gmane.comp.encryption.cryptopp
Message-ID <[email protected]>
------=_Part_276224_94120074.1754873622905
Content-Type: multipart/alternative; 
	boundary="----=_Part_276225_589993312.1754873622905"

------=_Part_276225_589993312.1754873622905
Content-Type: text/plain; charset="UTF-8"

Using cryptopp 8.9 on debian 12.11 with gcc 14.2 I have an AES/GCM 
encryption program which I am running on a large file (75GB).  It is 
failing with the error "AES/GCM: message length exceeds maximum".  I 
searched around and found information which suggests the maximum file size 
should be 2**39-256, which is a bit less than 550GB.  So it is not clear to 
me why I am getting this error message.  Any ideas on what kind of bug I 
should be looking for?  As a second question, anyone have any advice on 
ways to handle large files which it is desirable to encrypt?  This is not 
the largest file I would like to encrypt and it is plausible I would hit 
the 2**39-256 limit.

The relevant code looks like this:
    CryptoPP::GCM<CryptoPP::AES>::Encryption encryptor;
    encryptor.SetKeyWithIV(reinterpret_cast<const CryptoPP::byte 
*>(key.data())
                          , KeyBytes
                          , iv.bytes
                          , IVBytes
                          );

    CryptoPP::AuthenticatedEncryptionFilter filter(encryptor);

    CryptoPP::FileSource source(plainfile.c_str(), false);
    CryptoPP::FileSink sink(cipherfile.c_str());

    CryptoPP::ArraySource(iv.bytes, IVBytes, true, new 
CryptoPP::Redirector(sink));

    source.Attach(new CryptoPP::Redirector(filter));
    filter.Attach(new CryptoPP::Redirector(sink));

    while (!EndOfFile(source) && !source.SourceExhausted())
    {
        source.Pump(TransferBytes);
        filter.Flush(false);
    }
    filter.MessageEnd();


-- 
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/cryptopp-users/579512a3-7dd1-4734-be29-74920f25fa2en%40googlegroups.com.

------=_Part_276225_589993312.1754873622905
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div>Using cryptopp 8.9 on debian 12.11 with gcc 14.2 I have an AES/GCM enc=
ryption program which I am running on a large file (75GB).=C2=A0 It is fail=
ing with the error "AES/GCM: message length exceeds maximum".=C2=A0 I searc=
hed around and found information which suggests the maximum file size shoul=
d be 2**39-256, which is a bit less than 550GB.=C2=A0 So it is not clear to=
 me why I am getting this error message.=C2=A0 Any ideas on what kind of bu=
g I should be looking for?=C2=A0 As a second question, anyone have any advi=
ce on ways to handle large files which it is desirable to encrypt?=C2=A0 Th=
is is not the largest file I would like to encrypt and it is plausible I wo=
uld hit the 2**39-256 limit.<br /></div><div><br /></div><div>The relevant =
code looks like this:</div><div></div><div>=C2=A0<span style=3D"font-family=
: Courier New;"> =C2=A0 CryptoPP::GCM&lt;CryptoPP::AES&gt;::Encryption encr=
yptor;<br />=C2=A0 =C2=A0 encryptor.SetKeyWithIV(reinterpret_cast&lt;const =
CryptoPP::byte *&gt;(key.data())<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 , KeyBytes<br />=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 , iv.bytes<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 , IVBytes<br />=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 );<br /><br />=C2=A0 =C2=A0 CryptoPP::AuthenticatedEncryptionFilter fil=
ter(encryptor);<br /><br />=C2=A0 =C2=A0 CryptoPP::FileSource source(plainf=
ile.c_str(), false);<br />=C2=A0 =C2=A0 CryptoPP::FileSink sink(cipherfile.=
c_str());<br /><br />=C2=A0 =C2=A0 CryptoPP::ArraySource(iv.bytes, IVBytes,=
 true, new CryptoPP::Redirector(sink));<br /><br />=C2=A0 =C2=A0 source.Att=
ach(new CryptoPP::Redirector(filter));<br />=C2=A0 =C2=A0 filter.Attach(new=
 CryptoPP::Redirector(sink));<br /><br />=C2=A0 =C2=A0 while (!EndOfFile(so=
urce) &amp;&amp; !source.SourceExhausted())<br />=C2=A0 =C2=A0 {<br />=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 source.Pump(TransferBytes);<br />=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 filter.Flush(false);<br />=C2=A0 =C2=A0 }<br />=C2=A0 =C2=A0 fil=
ter.MessageEnd();</span></div><div><span style=3D"font-family: Courier New;=
"><br /></span></div><div><span style=3D"font-family: Courier New;"><br /><=
/span></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;Crypto++ Users&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">cryp=
[email protected]</a>.<br />
To view this discussion visit <a href=3D"https://groups.google.com/d/msgid/=
cryptopp-users/579512a3-7dd1-4734-be29-74920f25fa2en%40googlegroups.com?utm=
_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msgid/cryp=
topp-users/579512a3-7dd1-4734-be29-74920f25fa2en%40googlegroups.com</a>.<br=
 />

------=_Part_276225_589993312.1754873622905--

------=_Part_276224_94120074.1754873622905--