Re: Re: XChaCha20 decryption issue.

Jeffrey Walton <[email protected]> Sun, 5 Nov 2023 14:26:13 -0500
Newsgroups gmane.comp.encryption.cryptopp
Message-ID <CAH8yC8nsoQPBtdeHhtMTRw=B8mFBpCj2QkcrEQbSJMuLRZw98w@mail.gmail.com>
--0000000000009b151b06096cb614
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Sun, Nov 5, 2023 at 4:38=E2=80=AFAM Lucas Marchetti <lmarchetti384@gmail=
.com>
wrote:

> Sorry, seeing now that I've linked the wrong Golang library, here it is:
> https://pkg.go.dev/golang.org/x/crypto/chacha20poly1305
>
> On Sunday, November 5, 2023 at 10:10:44=E2=80=AFAM UTC+1 Lucas Marchetti =
wrote:
>
>> I've just made a test encrypting the string "Hello World!" with both
>> client and server functions and these are the results.
>>
>> [image: Screenshot 2023-11-05 100312.png]
>>
>> Both green-highlighted bytes corresponds to the input string but, as you
>> can see, there is a different padding that I'm 100% sure is the source o=
f
>> the problem.
>>
>> On Saturday, November 4, 2023 at 7:39:31=E2=80=AFPM UTC+1 Lucas Marchett=
i wrote:
>>
>>> Good evening.
>>>
>>> I'm building a client-server application and I want to implement a
>>> XChaCha20 communication over TCP after performing key exchange.
>>>
>>> What I'm issuing is a bad decryption output like the one shown in the
>>> pic.
>>>
>>> [image: Screenshot 2023-11-04 193625.png]
>>>
>>> I'm currently using crypto++ 8.9 in the client-side and
>>> https://pkg.go.dev/golang.org/x/crypto/chacha20 in the server-side.
>>>
>>> Is that something related to sealing or authentication implemented in
>>> the Golang library?
>>>
>>> Functions that I'm using:
>>>
>>> [image: Screenshot 2023-11-04 193751.png]
>>>
>>> [image: Screenshot 2023-11-04 193832.png]
>>>
>>> Thanks in advance.
>>>
>> If you want help, then you should provide source code and post a link to
a minimal reproducer. Pictures are not helpful.

The wiki is full of little working examples. For example, <
https://www.cryptopp.com/wiki/XChaCha20> and <
https://www.cryptopp.com/wiki/XChaCha20Poly1305>.

You should also probably start with test vectors, and then move onto
arbitrary messages once things work with test vectors. Here are the ones
Crypto++ uses for XChaCha: <
https://github.com/weidai11/cryptopp/blob/master/TestVectors/chacha.txt>.
And here are the ones for ChaCha20/Poly1305: <
https://github.com/weidai11/cryptopp/blob/master/TestVectors/chacha20poly13=
05.txt#L4669
>.

I'm just guessing, but the 16-bytes of garbage at the end of the
[encrypted] message may be a Poly1305 authentication tag. But it is just a
guess. The go documentation should tell you what you have.

Jeff

--=20
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 e=
mail to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/=
cryptopp-users/CAH8yC8nsoQPBtdeHhtMTRw%3DB8mFBpCj2QkcrEQbSJMuLRZw98w%40mail=
.gmail.com.

--0000000000009b151b06096cb614
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Sun, Nov 5, 2023 at 4:38=E2=80=AFA=
M Lucas Marchetti &lt;<a href=3D"mailto:[email protected]">lmarchetti=
[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" sty=
le=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddi=
ng-left:1ex">Sorry, seeing now that I&#39;ve linked the wrong Golang librar=
y, here it is:=C2=A0<a href=3D"https://pkg.go.dev/golang.org/x/crypto/chach=
a20poly1305" target=3D"_blank">https://pkg.go.dev/golang.org/x/crypto/chach=
a20poly1305</a><br><br><div class=3D"gmail_quote"><div dir=3D"auto" class=
=3D"gmail_attr">On Sunday, November 5, 2023 at 10:10:44=E2=80=AFAM UTC+1 Lu=
cas Marchetti wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:=
1ex">I&#39;ve just made a test encrypting the string &quot;Hello World!&quo=
t; with both client and server functions and these are the results.<div><br=
></div><div><img alt=3D"Screenshot 2023-11-05 100312.png" width=3D"726px" h=
eight=3D"111px" src=3D"https://groups.google.com/group/cryptopp-users/attac=
h/5b1bbc5faec59/Screenshot%202023-11-05%20100312.png?part=3D0.1&amp;view=3D=
1"></div><div><br></div><div>Both green-highlighted bytes corresponds to th=
e input string but, as you can see, there is a different padding that I&#39=
;m 100% sure is the source of the problem.<br><br></div><div class=3D"gmail=
_quote"><div dir=3D"auto" class=3D"gmail_attr">On Saturday, November 4, 202=
3 at 7:39:31=E2=80=AFPM UTC+1 Lucas Marchetti wrote:<br></div><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px soli=
d rgb(204,204,204);padding-left:1ex">Good evening.<br><br>I&#39;m building =
a client-server application and I want to implement a XChaCha20 communicati=
on over TCP after performing key exchange.<br><br>What I&#39;m issuing is a=
 bad decryption output like the one shown in the pic.<br><br><img alt=3D"Sc=
reenshot 2023-11-04 193625.png" width=3D"266px" height=3D"19px" src=3D"http=
s://groups.google.com/group/cryptopp-users/attach/58230e8ec9c5a/Screenshot%=
202023-11-04%20193625.png?part=3D0.1&amp;view=3D1"><br><div><br></div><div>=
I&#39;m currently using crypto++ 8.9 in the client-side and=C2=A0<a href=3D=
"https://pkg.go.dev/golang.org/x/crypto/chacha20" rel=3D"nofollow" target=
=3D"_blank">https://pkg.go.dev/golang.org/x/crypto/chacha20</a> in the serv=
er-side.<div><br></div><div>Is that something related to sealing or authent=
ication implemented in the Golang library?</div></div><div><br></div><div>F=
unctions that I&#39;m using:</div><div><br></div><div><img alt=3D"Screensho=
t 2023-11-04 193751.png" width=3D"534px" height=3D"197px" src=3D"https://gr=
oups.google.com/group/cryptopp-users/attach/58230e8ec9c5a/Screenshot%202023=
-11-04%20193751.png?part=3D0.3&amp;view=3D1"><br></div><div><br></div><div>=
<img alt=3D"Screenshot 2023-11-04 193832.png" width=3D"534px" height=3D"197=
px" src=3D"https://groups.google.com/group/cryptopp-users/attach/58230e8ec9=
c5a/Screenshot%202023-11-04%20193832.png?part=3D0.2&amp;view=3D1"><br></div=
><div><br></div><div>Thanks in advance.</div></blockquote></div></blockquot=
e></div>

<p></p></blockquote><div>If you want help, then you should provide source c=
ode and post a link to a minimal reproducer. Pictures are not helpful.</div=
><div><br></div><div>The wiki is full of little working examples. For examp=
le, &lt;<a href=3D"https://www.cryptopp.com/wiki/XChaCha20">https://www.cry=
ptopp.com/wiki/XChaCha20</a>&gt; and &lt;<a href=3D"https://www.cryptopp.co=
m/wiki/XChaCha20Poly1305">https://www.cryptopp.com/wiki/XChaCha20Poly1305</=
a>&gt;.</div><div><br></div><div>You should also probably start with test v=
ectors, and then move onto arbitrary messages once things work with test ve=
ctors. Here are the ones Crypto++ uses for XChaCha: &lt;<a href=3D"https://=
github.com/weidai11/cryptopp/blob/master/TestVectors/chacha.txt">https://gi=
thub.com/weidai11/cryptopp/blob/master/TestVectors/chacha.txt</a>&gt;. And =
here are the ones for ChaCha20/Poly1305: &lt;<a href=3D"https://github.com/=
weidai11/cryptopp/blob/master/TestVectors/chacha20poly1305.txt#L4669">https=
://github.com/weidai11/cryptopp/blob/master/TestVectors/chacha20poly1305.tx=
t#L4669</a>&gt;.</div><div><br></div><div>I&#39;m just guessing, but the 16=
-bytes of garbage at the end of the=20
[encrypted] message may be a Poly1305 authentication tag. But it is just
 a guess. The go documentation should tell you what you have.</div><div><br=
></div><div>Jeff<br></div></div></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 on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/cryptopp-users/CAH8yC8nsoQPBtdeHhtMTRw%3DB8mFBpCj2QkcrEQbSJMuLRZ=
w98w%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://group=
s.google.com/d/msgid/cryptopp-users/CAH8yC8nsoQPBtdeHhtMTRw%3DB8mFBpCj2Qkcr=
EQbSJMuLRZw98w%40mail.gmail.com</a>.<br />

--0000000000009b151b06096cb614--