Mercurial > hg > quicktun
comparison src/proto.nacl0.c @ 55:5685fad38195
Fixed compiler warnings from clang (including small bug in private key loading)
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Fri, 31 Jan 2014 22:52:46 +0100 |
parents | 54d28a81ca99 |
children | 66d9d80215f0 |
comparison
equal
deleted
inserted
replaced
54:4ff8003d0973 | 55:5685fad38195 |
---|---|
31 }; | 31 }; |
32 | 32 |
33 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) { |
34 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; |
35 memset(raw, 0, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES); | 35 memset(raw, 0, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES); |
36 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((unsigned char*)enc, (unsigned char*)raw, len+crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cnonce, d->cbefore)) return errorexit("Crypto failed"); |
37 return len + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; | 37 return len + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; |
38 } | 38 } |
39 | 39 |
40 static int decode(struct qtsession* sess, char* enc, char* raw, int len) { | 40 static int decode(struct qtsession* sess, char* enc, char* raw, int len) { |
41 struct qt_proto_data_nacl0* d = (struct qt_proto_data_nacl0*)sess->protocol_data; | 41 struct qt_proto_data_nacl0* d = (struct qt_proto_data_nacl0*)sess->protocol_data; |
42 int i; | |
43 if (len < crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES) { | 42 if (len < crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES) { |
44 fprintf(stderr, "Short packet received: %d\n", len); | 43 fprintf(stderr, "Short packet received: %d\n", len); |
45 return -1; | 44 return -1; |
46 } | 45 } |
47 len -= crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; | 46 len -= crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; |
48 memset(enc, 0, crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES); | 47 memset(enc, 0, crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES); |
49 if (i = crypto_box_curve25519xsalsa20poly1305_open_afternm(raw, enc, len+crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cnonce, d->cbefore)) { | 48 if (crypto_box_curve25519xsalsa20poly1305_open_afternm((unsigned char*)raw, (unsigned char*)enc, len+crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cnonce, d->cbefore)) { |
50 fprintf(stderr, "Decryption failed len=%d result=%d\n", len, i); | 49 fprintf(stderr, "Decryption failed len=%d\n", len); |
51 return -1; | 50 return -1; |
52 } | 51 } |
53 return len; | 52 return len; |
54 } | 53 } |
55 | 54 |
60 memset(d->cnonce, 0, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES); | 59 memset(d->cnonce, 0, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES); |
61 unsigned char cpublickey[crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES], csecretkey[crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES]; | 60 unsigned char cpublickey[crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES], csecretkey[crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES]; |
62 if (!(envval = getconf("PUBLIC_KEY"))) return errorexit("Missing PUBLIC_KEY"); | 61 if (!(envval = getconf("PUBLIC_KEY"))) return errorexit("Missing PUBLIC_KEY"); |
63 if (strlen(envval) != 2*crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) return errorexit("PUBLIC_KEY length"); | 62 if (strlen(envval) != 2*crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) return errorexit("PUBLIC_KEY length"); |
64 hex2bin(cpublickey, envval, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES); | 63 hex2bin(cpublickey, envval, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES); |
65 if (envval = getconf("PRIVATE_KEY")) { | 64 if ((envval = getconf("PRIVATE_KEY"))) { |
66 if (strlen(envval) != 2*crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) return errorexit("PRIVATE_KEY length"); | 65 if (strlen(envval) != 2*crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) return errorexit("PRIVATE_KEY length"); |
67 hex2bin(csecretkey, envval, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); | 66 hex2bin(csecretkey, envval, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); |
68 } else if (envval = getconf("PRIVATE_KEY_FILE")) { | 67 } else if ((envval = getconf("PRIVATE_KEY_FILE"))) { |
69 FILE* pkfile = fopen(envval, "rb"); | 68 FILE* pkfile = fopen(envval, "rb"); |
70 if (!pkfile) return errorexitp("Could not open PRIVATE_KEY_FILE"); | 69 if (!pkfile) return errorexitp("Could not open PRIVATE_KEY_FILE"); |
71 char pktextbuf[crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES * 2]; | 70 char pktextbuf[crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES * 2]; |
72 size_t pktextsize = fread(pktextbuf, 1, sizeof(pktextbuf), pkfile); | 71 const size_t pktextsize = fread(pktextbuf, 1, sizeof(pktextbuf), pkfile); |
73 if (pktextsize == crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) { | 72 if (pktextsize == crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) { |
74 memcpy(csecretkey, pktextbuf, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); | 73 memcpy(csecretkey, pktextbuf, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); |
75 } else if (pktextsize = 2 * crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) { | 74 } else if (pktextsize == 2 * crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) { |
76 hex2bin(csecretkey, pktextbuf, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); | 75 hex2bin(csecretkey, pktextbuf, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); |
77 } else { | 76 } else { |
78 return errorexit("PRIVATE_KEY length"); | 77 return errorexit("PRIVATE_KEY length"); |
79 } | 78 } |
80 fclose(pkfile); | 79 fclose(pkfile); |