Mercurial > hg > quicktun
comparison src/proto.salty.c @ 53:15d651dec8e9 V2.2.3
Fixed a bug in the salty protocol encoding (prepare the buffer as expected by the encryption function)
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sat, 16 Nov 2013 14:55:14 +0100 |
parents | 3115f8af98bb |
children | 5685fad38195 |
comparison
equal
deleted
inserted
replaced
52:3115f8af98bb | 53:15d651dec8e9 |
---|---|
326 //Increment nonce in big endian | 326 //Increment nonce in big endian |
327 int i; | 327 int i; |
328 for (i = NONCEBYTES - 1; i >= 0 && ++e->nonce[i] == 0; i--) ; | 328 for (i = NONCEBYTES - 1; i >= 0 && ++e->nonce[i] == 0; i--) ; |
329 if (e->nonce[20] & 0xE0) return 0; | 329 if (e->nonce[20] & 0xE0) return 0; |
330 if (debug) dumphex("ENCODE KEY", e->sharedkey, 32); | 330 if (debug) dumphex("ENCODE KEY", e->sharedkey, 32); |
331 memset(raw, 0, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES); | |
331 if (crypto_box_curve25519xsalsa20poly1305_afternm(enc, raw, len + 32, e->nonce, e->sharedkey)) return errorexit("Encryption failed"); | 332 if (crypto_box_curve25519xsalsa20poly1305_afternm(enc, raw, len + 32, e->nonce, e->sharedkey)) return errorexit("Encryption failed"); |
332 enc[12] = (e->nonce[20] & 0x1F) | (0 << 7) | (d->datalocalkeyid << 6) | (d->dataremotekeyid << 5); | 333 enc[12] = (e->nonce[20] & 0x1F) | (0 << 7) | (d->datalocalkeyid << 6) | (d->dataremotekeyid << 5); |
333 enc[13] = e->nonce[21]; | 334 enc[13] = e->nonce[21]; |
334 enc[14] = e->nonce[22]; | 335 enc[14] = e->nonce[22]; |
335 enc[15] = e->nonce[23]; | 336 enc[15] = e->nonce[23]; |
374 } | 375 } |
375 dec->nonce[20] = enc[12] & 0x1F; | 376 dec->nonce[20] = enc[12] & 0x1F; |
376 dec->nonce[21] = enc[13]; | 377 dec->nonce[21] = enc[13]; |
377 dec->nonce[22] = enc[14]; | 378 dec->nonce[22] = enc[14]; |
378 dec->nonce[23] = enc[15]; | 379 dec->nonce[23] = enc[15]; |
379 memset(enc, 0, 16); | 380 memset(enc, 0, crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES); |
380 if (debug) dumphex("DECODE KEY", dec->sharedkey, 32); | 381 if (debug) dumphex("DECODE KEY", dec->sharedkey, 32); |
381 if (crypto_box_curve25519xsalsa20poly1305_open_afternm(raw, enc, len - 4 + 16, dec->nonce, dec->sharedkey)) { | 382 if (crypto_box_curve25519xsalsa20poly1305_open_afternm(raw, enc, len - 4 + 16, dec->nonce, dec->sharedkey)) { |
382 fprintf(stderr, "Decryption of data packet failed len=%d\n", len); | 383 fprintf(stderr, "Decryption of data packet failed len=%d\n", len); |
383 return -1; | 384 return -1; |
384 } | 385 } |