Mercurial > hg > quicktun
comparison src/proto.nacl0.c @ 27:5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sat, 09 Apr 2011 17:36:48 +0200 |
parents | dfac56805c77 |
children | bb4bbf380938 |
comparison
equal
deleted
inserted
replaced
26:68c67c6d2080 | 27:5ba185ca7102 |
---|---|
27 #include "crypto_box_curve25519xsalsa20poly1305.h" | 27 #include "crypto_box_curve25519xsalsa20poly1305.h" |
28 | 28 |
29 struct qt_proto_data_nacl0 { | 29 struct qt_proto_data_nacl0 { |
30 unsigned char cnonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES], cbefore[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES]; | 30 unsigned char cnonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES], cbefore[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES]; |
31 }; | 31 }; |
32 | |
33 /*static unsigned char cnonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES], cbefore[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES]; | |
34 static unsigned char buffer1[MAX_PACKET_LEN+crypto_box_curve25519xsalsa20poly1305_ZEROBYTES], buffer2[MAX_PACKET_LEN+crypto_box_curve25519xsalsa20poly1305_ZEROBYTES]; | |
35 static const unsigned char* buffer1offset = buffer1 + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES; | |
36 static const unsigned char* buffer2offset = buffer2 + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; | |
37 static const int overhead = crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES;*/ | |
38 | 32 |
39 static int encode(struct qtsession* sess, char* raw, char* enc, int len) { | 33 static int encode(struct qtsession* sess, char* raw, char* enc, int len) { |
40 struct qt_proto_data_nacl0* d = (struct qt_proto_data_nacl0*)sess->protocol_data; | 34 struct qt_proto_data_nacl0* d = (struct qt_proto_data_nacl0*)sess->protocol_data; |
41 memset(raw, 0, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES); | 35 memset(raw, 0, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES); |
42 if (crypto_box_curve25519xsalsa20poly1305_afternm(enc, raw, len+crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cnonce, d->cbefore)) return errorexit("Crypto failed"); | 36 if (crypto_box_curve25519xsalsa20poly1305_afternm(enc, raw, len+crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cnonce, d->cbefore)) return errorexit("Crypto failed"); |
73 hex2bin(csecretkey, envval, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); | 67 hex2bin(csecretkey, envval, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); |
74 crypto_box_curve25519xsalsa20poly1305_beforenm(d->cbefore, cpublickey, csecretkey); | 68 crypto_box_curve25519xsalsa20poly1305_beforenm(d->cbefore, cpublickey, csecretkey); |
75 return 0; | 69 return 0; |
76 } | 70 } |
77 | 71 |
78 #ifdef COMBINED_BINARY | 72 struct qtproto qtproto_nacl0 = { |
79 int tunmain_nacl0() { | 73 1, |
80 #else | 74 MAX_PACKET_LEN + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, |
81 int tunmain() { | 75 MAX_PACKET_LEN + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES, |
82 #endif | 76 crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, |
83 struct qtproto p = { | 77 crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES, |
84 1, | 78 encode, |
85 MAX_PACKET_LEN + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, | 79 decode, |
86 MAX_PACKET_LEN + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES, | 80 init, |
87 crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, | 81 sizeof(struct qt_proto_data_nacl0), |
88 crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES, | 82 }; |
89 encode, | |
90 decode, | |
91 init, | |
92 sizeof(struct qt_proto_data_nacl0), | |
93 }; | |
94 return qtrun(&p); | |
95 } | |
96 | 83 |
97 #ifndef COMBINED_BINARY | 84 #ifndef COMBINED_BINARY |
98 int main() { | 85 int main() { |
99 print_header(); | 86 print_header(); |
100 return tunmain(); | 87 return qtrun(&qtproto_nacl0); |
101 } | 88 } |
102 #endif | 89 #endif |