X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsptps.c;h=9017656a353802bd6deeb4e656407a1a9f05971a;hb=c023ad12147aa88810629c110ea6b1ab94267196;hp=3bc811ed207e3f80da255e7c85d375d431804b62;hpb=b67296418c51784d39a24c3041e2cb199bee06f2;p=meshlink diff --git a/src/sptps.c b/src/sptps.c index 3bc811ed..9017656a 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -27,8 +27,6 @@ #include "prf.h" #include "sptps.h" -unsigned int sptps_replaywin = 32; - /* Nonce MUST be exchanged first (done) Signatures MUST be done over both nonces, to guarantee the signature is fresh @@ -63,7 +61,7 @@ void sptps_log_stderr(sptps_t *s, int s_errno, const char *format, va_list ap) { fputc('\n', stderr); } -void (*sptps_log)(sptps_t *s, int s_errno, const char *format, va_list ap) = sptps_log_stderr; +void (*sptps_log)(sptps_t *s, int s_errno, const char *format, va_list ap) = sptps_log_quiet; // Log an error message. static bool error(sptps_t *s, int s_errno, const char *format, ...) { @@ -447,7 +445,7 @@ bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len) { char buffer[len]; size_t outlen; - return chacha_poly1305_decrypt(s->incipher, seqno, data + 4, len - 4, buffer, &outlen); + return chacha_poly1305_decrypt(s->incipher, seqno, (const char *)data + 4, len - 4, buffer, &outlen); } // Receive incoming data, datagram version. @@ -561,6 +559,8 @@ bool sptps_receive_data(sptps_t *s, const void *data, size_t len) { return sptps_receive_data_datagram(s, data, len); } + const char *ptr = data; + while(len) { // First read the 2 length bytes. if(s->buflen < 2) { @@ -570,11 +570,11 @@ bool sptps_receive_data(sptps_t *s, const void *data, size_t len) { toread = len; } - memcpy(s->inbuf + s->buflen, data, toread); + memcpy(s->inbuf + s->buflen, ptr, toread); s->buflen += toread; len -= toread; - data += toread; + ptr += toread; // Exit early if we don't have the full length. if(s->buflen < 2) { @@ -606,10 +606,10 @@ bool sptps_receive_data(sptps_t *s, const void *data, size_t len) { toread = len; } - memcpy(s->inbuf + s->buflen, data, toread); + memcpy(s->inbuf + s->buflen, ptr, toread); s->buflen += toread; len -= toread; - data += toread; + ptr += toread; // If we don't have a whole record, exit. if(s->buflen < s->reclen + (s->instate ? 19UL : 3UL)) { @@ -668,7 +668,7 @@ bool sptps_start(sptps_t *s, void *handle, bool initiator, bool datagram, ecdsa_ s->datagram = datagram; s->mykey = mykey; s->hiskey = hiskey; - s->replaywin = sptps_replaywin; + s->replaywin = 32; if(s->replaywin) { s->late = malloc(s->replaywin);