Mercurial > hg > quicktun
comparison src/proto.nacltai.c @ 22:38d495566d1c
Re-added some debugging messages to nacltai protocol code, enabled by the DEBUG environment variable
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sun, 27 Feb 2011 23:52:32 +0100 |
parents | 3400045a57b8 |
children | dfac56805c77 |
comparison
equal
deleted
inserted
replaced
21:c1e5af9329f1 | 22:38d495566d1c |
---|---|
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 // 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, 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_ZEROBYTES); | 123 memset(raw, 0, crypto_box_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_afternm(enc, raw, len + crypto_box_ZEROBYTES, d->cenonce, d->cbefore)) return errorexit("Crypto failed"); | 126 if (crypto_box_afternm(enc, raw, len + crypto_box_ZEROBYTES, d->cenonce, d->cbefore)) return errorexit("Encryption failed"); |
127 memcpy((void*)(enc + crypto_box_BOXZEROBYTES - noncelength), d->cenonce + nonceoffset, noncelength); | 127 memcpy((void*)(enc + crypto_box_BOXZEROBYTES - noncelength), d->cenonce + nonceoffset, noncelength); |
128 len += overhead; | 128 len += overhead; |
129 // 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, 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 // 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, 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 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; |
149 if (i = crypto_box_open_afternm(raw, enc, len + crypto_box_ZEROBYTES, d->cdnonce, d->cbefore)) { | 149 if (i = crypto_box_open_afternm(raw, enc, len + crypto_box_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 // 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, enc, 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; |