comparison src/proto.nacltai.c @ 25:24e09485a8a3

Clean up in build script, fixed compiler warnings in nacltai protocol debug code
author Ivo Smits <Ivo@UCIS.nl>
date Wed, 16 Mar 2011 23:18:07 +0100
parents dfac56805c77
children 68c67c6d2080
comparison
equal deleted inserted replaced
24:dfac56805c77 25:24e09485a8a3
116 t->nano = 1000 * now.tv_usec + 500; 116 t->nano = 1000 * now.tv_usec + 500;
117 t->atto = 0; 117 t->atto = 0;
118 } 118 }
119 119
120 static int encode(struct qtsession* sess, char* raw, char* enc, int len) { 120 static int encode(struct qtsession* sess, char* raw, char* enc, int len) {
121 if (debug) fprintf(stderr, "Encoding packet of %d bytes from %d to %d\n", len, raw, enc); 121 if (debug) fprintf(stderr, "Encoding packet of %d bytes from %d to %d\n", len, (int)raw, (int)enc);
122 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data; 122 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data;
123 memset(raw, 0, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES); 123 memset(raw, 0, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES);
124 taia_now(&d->cdtaic); 124 taia_now(&d->cdtaic);
125 taia_pack(d->cenonce + nonceoffset, &(d->cdtaic)); 125 taia_pack(d->cenonce + nonceoffset, &(d->cdtaic));
126 if (crypto_box_curve25519xsalsa20poly1305_afternm(enc, raw, len + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cenonce, d->cbefore)) return errorexit("Encryption failed"); 126 if (crypto_box_curve25519xsalsa20poly1305_afternm(enc, raw, len + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cenonce, d->cbefore)) return errorexit("Encryption failed");
127 memcpy((void*)(enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength), d->cenonce + nonceoffset, noncelength); 127 memcpy((void*)(enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength), d->cenonce + nonceoffset, noncelength);
128 len += overhead; 128 len += overhead;
129 if (debug) fprintf(stderr, "Encoded packet of %d bytes from %d to %d\n", len, raw, enc); 129 if (debug) fprintf(stderr, "Encoded packet of %d bytes from %d to %d\n", len, (int)raw, (int)enc);
130 return len; 130 return len;
131 } 131 }
132 132
133 static int decode(struct qtsession* sess, char* enc, char* raw, int len) { 133 static int decode(struct qtsession* sess, char* enc, char* raw, int len) {
134 if (debug) fprintf(stderr, "Decoding packet of %d bytes from %d to %d\n", len, enc, raw); 134 if (debug) fprintf(stderr, "Decoding packet of %d bytes from %d to %d\n", len, (int)enc, (int)raw);
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 int i; 136 int i;
137 if (len < overhead) { 137 if (len < overhead) {
138 fprintf(stderr, "Short packet received: %d\n", len); 138 fprintf(stderr, "Short packet received: %d\n", len);
139 return 0; 139 return 0;
140 } 140 }
141 len -= overhead; 141 len -= overhead;
142 taia_unpack((char*)(enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength), &d->cdtaic); 142 taia_unpack((char*)(enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength), &d->cdtaic);
143 if (d->cdtaic.sec.x <= d->cdtaip.sec.x && d->cdtaic.nano <= d->cdtaip.nano && d->cdtaic.atto <= d->cdtaip.atto) { 143 if (d->cdtaic.sec.x <= d->cdtaip.sec.x && d->cdtaic.nano <= d->cdtaip.nano && d->cdtaic.atto <= d->cdtaip.atto) {
144 fprintf(stderr, "Timestamp going back, ignoring packet\n"); 144 fprintf(stderr, "Timestamp going back, ignoring packet\n");
145 return 0; 145 return 0;
146 } 146 }
147 memcpy(d->cdnonce + nonceoffset, enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength, noncelength); 147 memcpy(d->cdnonce + nonceoffset, enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength, noncelength);
148 memset(enc, 0, crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES); 148 memset(enc, 0, crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES);
149 if (i = crypto_box_curve25519xsalsa20poly1305_open_afternm(raw, enc, len + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cdnonce, d->cbefore)) { 149 if (i = crypto_box_curve25519xsalsa20poly1305_open_afternm(raw, enc, len + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cdnonce, d->cbefore)) {
150 fprintf(stderr, "Decryption failed len=%d result=%d\n", len, i); 150 fprintf(stderr, "Decryption failed len=%d result=%d\n", len, i);
151 return 0; 151 return 0;
152 } 152 }
153 d->cdtaip = d->cdtaic; 153 d->cdtaip = d->cdtaic;
154 if (debug) fprintf(stderr, "Decoded packet of %d bytes from %d to %d\n", len, enc, raw); 154 if (debug) fprintf(stderr, "Decoded packet of %d bytes from %d to %d\n", len, (int)enc, (int)raw);
155 return len; 155 return len;
156 } 156 }
157 157
158 static int init(struct qtsession* sess) { 158 static int init(struct qtsession* sess) {
159 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data; 159 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data;