Mercurial > hg > quicktun
comparison src/proto.nacl0.c @ 41:54d28a81ca99
Small updates in preparation for stateful protocols
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Thu, 16 May 2013 01:15:01 +0200 |
parents | d9f5caa13898 |
children | 5685fad38195 |
comparison
equal
deleted
inserted
replaced
40:ed9581189d6b | 41:54d28a81ca99 |
---|---|
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; | 42 int i; |
43 if (len < crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES) { | 43 if (len < crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES) { |
44 fprintf(stderr, "Short packet received: %d\n", len); | 44 fprintf(stderr, "Short packet received: %d\n", len); |
45 return 0; | 45 return -1; |
46 } | 46 } |
47 len -= crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; | 47 len -= crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; |
48 memset(enc, 0, crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES); | 48 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)) { | 49 if (i = crypto_box_curve25519xsalsa20poly1305_open_afternm(raw, enc, len+crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cnonce, d->cbefore)) { |
50 fprintf(stderr, "Decryption failed len=%d result=%d\n", len, i); | 50 fprintf(stderr, "Decryption failed len=%d result=%d\n", len, i); |
51 return 0; | 51 return -1; |
52 } | 52 } |
53 return len; | 53 return len; |
54 } | 54 } |
55 | 55 |
56 static int init(struct qtsession* sess) { | 56 static int init(struct qtsession* sess) { |