Mercurial > hg > quicktun
comparison src/proto.nacltai.c @ 62:5b9e742bb704
Fixed compiler warnings, removed redundant version dependencies in debian package
author | Ivo Smits <Ivo@UFO-Net.nl> |
---|---|
date | Sat, 07 Jan 2017 15:47:19 +0100 |
parents | 66d9d80215f0 |
children |
comparison
equal
deleted
inserted
replaced
61:66d9d80215f0 | 62:5b9e742bb704 |
---|---|
32 struct packedtaia { | 32 struct packedtaia { |
33 unsigned char buffer[16]; | 33 unsigned char buffer[16]; |
34 }; | 34 }; |
35 | 35 |
36 struct qt_proto_data_nacltai { | 36 struct qt_proto_data_nacltai { |
37 unsigned char cenonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES], cdnonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES]; | 37 unsigned char cenonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES]; |
38 unsigned char cdnonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES]; | |
38 unsigned char cbefore[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES]; | 39 unsigned char cbefore[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES]; |
39 struct packedtaia cdtailog[5]; | 40 struct packedtaia cdtailog[5]; |
40 }; | 41 }; |
41 | 42 |
42 #define noncelength 16 | 43 #define noncelength 16 |
43 #define nonceoffset (crypto_box_curve25519xsalsa20poly1305_NONCEBYTES - noncelength) | 44 #define nonceoffset (crypto_box_curve25519xsalsa20poly1305_NONCEBYTES - noncelength) |
44 static const int overhead = crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES + noncelength; | 45 static const int overhead = crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES + noncelength; |
45 | 46 |
46 static void taia_now_packed(unsigned char* b, int secoffset) { | 47 static void taia_now_packed(unsigned char* b, int secoffset) { |
47 struct timeval now; | 48 struct timeval now; |
48 gettimeofday(&now, NULL); | 49 gettimeofday(&now, NULL); |
49 u_int64_t sec = 4611686018427387914ULL + (u_int64_t)now.tv_sec + secoffset; | 50 u_int64_t sec = 4611686018427387914ULL + (u_int64_t)now.tv_sec + secoffset; |
68 static int encode(struct qtsession* sess, char* raw, char* enc, int len) { | 69 static int encode(struct qtsession* sess, char* raw, char* enc, int len) { |
69 if (debug) fprintf(stderr, "Encoding packet of %d bytes from %p to %p\n", len, raw, enc); | 70 if (debug) fprintf(stderr, "Encoding packet of %d bytes from %p to %p\n", len, raw, enc); |
70 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data; | 71 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data; |
71 memset(raw, 0, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES); | 72 memset(raw, 0, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES); |
72 taia_now_packed(d->cenonce + nonceoffset, 0); | 73 taia_now_packed(d->cenonce + nonceoffset, 0); |
73 if (crypto_box_curve25519xsalsa20poly1305_afternm((unsigned char*)enc, (unsigned char*)raw, len + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cenonce, d->cbefore)) return errorexit("Encryption failed"); | 74 if (crypto_box_curve25519xsalsa20poly1305_afternm((unsigned char*)enc, (unsigned char*)raw, len + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cenonce, d->cbefore)) |
75 return errorexit("Encryption failed"); | |
74 memcpy((void*)(enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength), d->cenonce + nonceoffset, noncelength); | 76 memcpy((void*)(enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength), d->cenonce + nonceoffset, noncelength); |
75 len += overhead; | 77 len += overhead; |
76 if (debug) fprintf(stderr, "Encoded packet of %d bytes from %p to %p\n", len, raw, enc); | 78 if (debug) fprintf(stderr, "Encoded packet of %d bytes from %p to %p\n", len, raw, enc); |
77 return len; | 79 return len; |
78 } | 80 } |
136 } | 138 } |
137 fclose(pkfile); | 139 fclose(pkfile); |
138 } else { | 140 } else { |
139 return errorexit("Missing PRIVATE_KEY"); | 141 return errorexit("Missing PRIVATE_KEY"); |
140 } | 142 } |
141 crypto_box_curve25519xsalsa20poly1305_beforenm(d->cbefore, cpublickey, csecretkey); | 143 if (crypto_box_curve25519xsalsa20poly1305_beforenm(d->cbefore, cpublickey, csecretkey)) |
144 return errorexit("Encryption key calculation failed"); | |
142 | 145 |
143 memset(d->cenonce, 0, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES); | 146 memset(d->cenonce, 0, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES); |
144 memset(d->cdnonce, 0, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES); | 147 memset(d->cdnonce, 0, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES); |
145 memset(d->cdtailog, 0, 5 * 16); | 148 memset(d->cdtailog, 0, 5 * 16); |
146 | 149 |