Development discussion of WireGuard
 help / color / mirror / Atom feed
* Noise Protocol Question
@ 2023-02-11 15:39 z
  2023-02-16 15:39 ` Jason A. Donenfeld
  0 siblings, 1 reply; 2+ messages in thread
From: z @ 2023-02-11 15:39 UTC (permalink / raw)
  To: wireguard

Hi,

I was reading over the source code for wireguard-go, and I noticed something in the device/noise-protocol.go file that I didn't understand.

There are six invocations of the sharedSecret() function, which performs the X25519 operation on a local private key and a remote public key as part of an ECDH key agreement. 

The first two invocations check for an all zero ECDH result.  a.la
ss := pk.sharedSecret(pubkey)
if isZero(ss) {
    return nil, errZeroECDHResult
}

If the result is zero, the operation is aborted.  The subsequent 4 invocations, however, don't check for zero on the output of sharedSecret(), and continue processing regardless.

In two of the 4 cases, I think I get why it isn't necessary, because the sharedSecret is used as input into an aead.Open, which would simply fail if the ECDH got zero'd out somehow.

However the remaining two calls are associated with an aead.Seal, which would succeed, no matter what the shared secret is.


TL;DR  Why is wireguard go not calling isZero() on the output of the ECDH key agreement every time?

Thanks,

dzm

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Noise Protocol Question
  2023-02-11 15:39 Noise Protocol Question z
@ 2023-02-16 15:39 ` Jason A. Donenfeld
  0 siblings, 0 replies; 2+ messages in thread
From: Jason A. Donenfeld @ 2023-02-16 15:39 UTC (permalink / raw)
  To: z; +Cc: wireguard, mathias

On Sat, Feb 11, 2023 at 03:39:12PM +0000, z wrote:
> TL;DR  Why is wireguard go not calling isZero() on the output of the ECDH key agreement every time?

Good question. AFAICT, this was something I had noticed back when this
code was in development, but then zero checking only got added to the
initiation side, not the response side, in 8c34c4c ("First set of code
review patches"). I don't know whether this was a mistake or if there
was a rationale at the time.

Fortunately, there aren't really any real consequences. But I did fix it
up, so thanks very much for reporting this:
https://git.zx2c4.com/wireguard-go/commit/?id=c7b76d3d9ecdc2ffde80decadda88c0c7cdfeedf

Jason

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-16 15:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-11 15:39 Noise Protocol Question z
2023-02-16 15:39 ` Jason A. Donenfeld

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).