comparison src/proto.nacltai.c @ 41:54d28a81ca99

Small updates in preparation for stateful protocols
author Ivo Smits <Ivo@UCIS.nl>
date Thu, 16 May 2013 01:15:01 +0200
parents d9f5caa13898
children 4adbd9b67fe2
comparison
equal deleted inserted replaced
40:ed9581189d6b 41:54d28a81ca99
135 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data; 135 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data;
136 struct taia cdtaic; 136 struct taia cdtaic;
137 int i; 137 int i;
138 if (len < overhead) { 138 if (len < overhead) {
139 fprintf(stderr, "Short packet received: %d\n", len); 139 fprintf(stderr, "Short packet received: %d\n", len);
140 return 0; 140 return -1;
141 } 141 }
142 len -= overhead; 142 len -= overhead;
143 taia_unpack((char*)(enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength), &cdtaic); 143 taia_unpack((char*)(enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength), &cdtaic);
144 if (cdtaic.sec.x <= d->cdtaip.sec.x && cdtaic.nano <= d->cdtaip.nano && cdtaic.atto <= d->cdtaip.atto) { 144 if (cdtaic.sec.x <= d->cdtaip.sec.x && cdtaic.nano <= d->cdtaip.nano && cdtaic.atto <= d->cdtaip.atto) {
145 fprintf(stderr, "Timestamp going back, ignoring packet\n"); 145 fprintf(stderr, "Timestamp going back, ignoring packet\n");
146 return 0; 146 return -1;
147 } 147 }
148 memcpy(d->cdnonce + nonceoffset, enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength, noncelength); 148 memcpy(d->cdnonce + nonceoffset, enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength, noncelength);
149 memset(enc, 0, crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES); 149 memset(enc, 0, crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES);
150 if (i = crypto_box_curve25519xsalsa20poly1305_open_afternm(raw, enc, len + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cdnonce, d->cbefore)) { 150 if (i = crypto_box_curve25519xsalsa20poly1305_open_afternm(raw, enc, len + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cdnonce, d->cbefore)) {
151 fprintf(stderr, "Decryption failed len=%d result=%d\n", len, i); 151 fprintf(stderr, "Decryption failed len=%d result=%d\n", len, i);
152 return 0; 152 return -1;
153 } 153 }
154 d->cdtaip = cdtaic; 154 d->cdtaip = cdtaic;
155 if (debug) fprintf(stderr, "Decoded packet of %d bytes from %p to %p\n", len, enc, raw); 155 if (debug) fprintf(stderr, "Decoded packet of %d bytes from %p to %p\n", len, enc, raw);
156 return len; 156 return len;
157 } 157 }