Mercurial > hg > quicktun
comparison src/proto.nacltai.c @ 30:6f0e6b7dc088
Fixed build script to support multiple abis on one machine, bugfix in code, minor improvements
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Thu, 04 Aug 2011 18:17:06 +0200 |
parents | 5ba185ca7102 |
children | 51c6d2fc712f |
comparison
equal
deleted
inserted
replaced
29:7c5e5be876bb | 30:6f0e6b7dc088 |
---|---|
116 t->nano = 1000 * now.tv_usec + 500; | 116 t->nano = 1000 * now.tv_usec + 500; |
117 t->atto++; | 117 t->atto++; |
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, (int)raw, (int)enc); | 121 if (debug) fprintf(stderr, "Encoding packet of %d bytes from %p to %p\n", len, raw, 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->cdtaie); | 124 taia_now(&d->cdtaie); |
125 taia_pack(d->cenonce + nonceoffset, &(d->cdtaie)); | 125 taia_pack(d->cenonce + nonceoffset, &(d->cdtaie)); |
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, (int)raw, (int)enc); | 129 if (debug) fprintf(stderr, "Encoded packet of %d bytes from %p to %p\n", len, raw, 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, (int)enc, (int)raw); | 134 if (debug) fprintf(stderr, "Decoding packet of %d bytes from %p to %p\n", len, enc, 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 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); |
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 0; |
153 } | 153 } |
154 d->cdtaip = cdtaic; | 154 d->cdtaip = cdtaic; |
155 if (debug) fprintf(stderr, "Decoded packet of %d bytes from %d to %d\n", len, (int)enc, (int)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 } |
158 | 158 |
159 static int init(struct qtsession* sess) { | 159 static int init(struct qtsession* sess) { |
160 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data; | 160 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data; |