Mercurial > hg > quicktun
diff src/proto.nacltai.c @ 43:4adbd9b67fe2
Fix nonce calculation when both sides use the same key in nacltai and salty protocols
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Thu, 16 May 2013 01:35:26 +0200 |
parents | 54d28a81ca99 |
children | 55f379f0a650 |
line wrap: on
line diff
--- a/src/proto.nacltai.c Thu May 16 01:19:12 2013 +0200 +++ b/src/proto.nacltai.c Thu May 16 01:35:26 2013 +0200 @@ -196,12 +196,11 @@ } else { fprintf(stderr, "Warning: TIME_WINDOW not set, risking an initial replay attack\n"); } - if (envval = getconf("ROLE")) { - d->cenonce[nonceoffset-1] = atoi(envval) ? 1 : 0; - } else { - d->cenonce[nonceoffset-1] = memcmp(cownpublickey, cpublickey, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) > 0 ? 1 : 0; - } - d->cdnonce[nonceoffset-1] = d->cenonce[nonceoffset-1] ? 0 : 1; + int role = memcmp(cownpublickey, cpublickey, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES); + if (envval = getconf("ROLE")) role = atoi(envval) ? 1 : -1; + role = (role == 0) ? 0 : ((role > 0) ? 1 : 2); + d->cenonce[nonceoffset-1] = role & 1; + d->cdnonce[nonceoffset-1] = (role >> 1) & 1; return 0; }