From be6fed13fa53601aab04338f45770318efd35940 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 8 Jun 2018 19:07:47 +0100 Subject: [PATCH] Further void * / const fixes. Yet more of these that commits 7babe66a8 and 8d882756b didn't spot. I bet these still aren't the last, either. --- misc.c | 2 +- misc.h | 2 +- ssh.h | 6 +++--- sshccp.c | 12 ++++++++---- sshmd5.c | 8 +++++--- sshsh256.c | 13 ++++++++----- sshsha.c | 20 ++++++++++++-------- 7 files changed, 38 insertions(+), 25 deletions(-) diff --git a/misc.c b/misc.c index 36f27171..92890322 100644 --- a/misc.c +++ b/misc.c @@ -485,7 +485,7 @@ struct strbuf_impl { ((buf)->visible.s = (ptr), \ (buf)->visible.u = (unsigned char *)(buf)->visible.s) -char *strbuf_append(strbuf *buf_o, size_t len) +void *strbuf_append(strbuf *buf_o, size_t len) { struct strbuf_impl *buf = FROMFIELD(buf_o, struct strbuf_impl, visible); char *toret; diff --git a/misc.h b/misc.h index 4b830d99..35d9de6c 100644 --- a/misc.h +++ b/misc.h @@ -40,7 +40,7 @@ struct strbuf { }; strbuf *strbuf_new(void); void strbuf_free(strbuf *buf); -char *strbuf_append(strbuf *buf, size_t len); +void *strbuf_append(strbuf *buf, size_t len); char *strbuf_to_str(strbuf *buf); /* does free buf, but you must free result */ void strbuf_catf(strbuf *buf, const char *fmt, ...); void strbuf_catfv(strbuf *buf, const char *fmt, va_list ap); diff --git a/ssh.h b/ssh.h index 1c0f276c..0eaea9f2 100644 --- a/ssh.h +++ b/ssh.h @@ -350,10 +350,10 @@ struct ssh_mac { /* Passes in the cipher context */ void *(*make_context)(void *); void (*free_context)(void *); - void (*setkey) (void *, unsigned char *key); + void (*setkey) (void *, const void *key); /* whole-packet operations */ - void (*generate) (void *, unsigned char *blk, int len, unsigned long seq); - int (*verify) (void *, unsigned char *blk, int len, unsigned long seq); + void (*generate) (void *, void *blk, int len, unsigned long seq); + int (*verify) (void *, const void *blk, int len, unsigned long seq); /* partial-packet operations */ void (*start) (void *); BinarySink *(*sink) (void *); diff --git a/sshccp.c b/sshccp.c index 9345c6fa..04f1cc16 100644 --- a/sshccp.c +++ b/sshccp.c @@ -878,7 +878,7 @@ static void poly_free_context(void *ctx) /* Not allocated, just forwarded, no need to free */ } -static void poly_setkey(void *ctx, unsigned char *key) +static void poly_setkey(void *ctx, const void *key) { /* Uses the same context as ChaCha20, so ignore */ } @@ -948,7 +948,8 @@ static int poly_verresult(void *handle, unsigned char const *blk) } /* The generic poly operation used before generate and verify */ -static void poly_op(void *handle, unsigned char *blk, int len, unsigned long seq) +static void poly_op(void *handle, const unsigned char *blk, int len, + unsigned long seq) { struct ccp_context *ctx = (struct ccp_context *)handle; poly_start(ctx); @@ -957,14 +958,17 @@ static void poly_op(void *handle, unsigned char *blk, int len, unsigned long seq put_data(ctx, blk, len); } -static void poly_generate(void *handle, unsigned char *blk, int len, unsigned long seq) +static void poly_generate(void *handle, void *vblk, int len, unsigned long seq) { + unsigned char *blk = (unsigned char *)vblk; poly_op(handle, blk, len, seq); poly_genresult(handle, blk+len); } -static int poly_verify(void *handle, unsigned char *blk, int len, unsigned long seq) +static int poly_verify(void *handle, const void *vblk, int len, + unsigned long seq) { + const unsigned char *blk = (const unsigned char *)vblk; poly_op(handle, blk, len, seq); return poly_verresult(handle, blk+len); } diff --git a/sshmd5.c b/sshmd5.c index 5bd0ccb4..05f00d0b 100644 --- a/sshmd5.c +++ b/sshmd5.c @@ -261,7 +261,7 @@ void hmacmd5_key(void *handle, void const *keyv, int len) smemclr(foo, 64); /* burn the evidence */ } -static void hmacmd5_key_16(void *handle, unsigned char *key) +static void hmacmd5_key_16(void *handle, const void *key) { hmacmd5_key(handle, key, 16); } @@ -329,15 +329,17 @@ static void hmacmd5_do_hmac_ssh(void *handle, unsigned char const *blk, int len, hmacmd5_do_hmac_internal(handle, seqbuf, 4, blk, len, hmac); } -static void hmacmd5_generate(void *handle, unsigned char *blk, int len, +static void hmacmd5_generate(void *handle, void *vblk, int len, unsigned long seq) { + unsigned char *blk = (unsigned char *)vblk; hmacmd5_do_hmac_ssh(handle, blk, len, seq, blk + len); } -static int hmacmd5_verify(void *handle, unsigned char *blk, int len, +static int hmacmd5_verify(void *handle, const void *vblk, int len, unsigned long seq) { + const unsigned char *blk = (const unsigned char *)vblk; unsigned char correct[16]; hmacmd5_do_hmac_ssh(handle, blk, len, seq, correct); return smemeq(correct, blk + len, 16); diff --git a/sshsh256.c b/sshsh256.c index 0a0a9546..66752326 100644 --- a/sshsh256.c +++ b/sshsh256.c @@ -267,7 +267,8 @@ static void sha256_free_context(void *handle) sfree(handle); } -static void sha256_key_internal(void *handle, unsigned char *key, int len) +static void sha256_key_internal(void *handle, + const unsigned char *key, int len) { SHA256_State *keys = (SHA256_State *)handle; unsigned char foo[64]; @@ -288,7 +289,7 @@ static void sha256_key_internal(void *handle, unsigned char *key, int len) smemclr(foo, 64); /* burn the evidence */ } -static void sha256_key(void *handle, unsigned char *key) +static void sha256_key(void *handle, const void *key) { sha256_key_internal(handle, key, 32); } @@ -322,7 +323,7 @@ static void hmacsha256_genresult(void *handle, unsigned char *hmac) SHA256_Final(&s, hmac); } -static void sha256_do_hmac(void *handle, unsigned char *blk, int len, +static void sha256_do_hmac(void *handle, const unsigned char *blk, int len, unsigned long seq, unsigned char *hmac) { BinarySink *bs = hmacsha256_sink(handle); @@ -332,9 +333,10 @@ static void sha256_do_hmac(void *handle, unsigned char *blk, int len, hmacsha256_genresult(handle, hmac); } -static void sha256_generate(void *handle, unsigned char *blk, int len, +static void sha256_generate(void *handle, void *vblk, int len, unsigned long seq) { + unsigned char *blk = (unsigned char *)vblk; sha256_do_hmac(handle, blk, len, seq, blk + len); } @@ -345,9 +347,10 @@ static int hmacsha256_verresult(void *handle, unsigned char const *hmac) return smemeq(correct, hmac, 32); } -static int sha256_verify(void *handle, unsigned char *blk, int len, +static int sha256_verify(void *handle, const void *vblk, int len, unsigned long seq) { + const unsigned char *blk = (const unsigned char *)vblk; unsigned char correct[32]; sha256_do_hmac(handle, blk, len, seq, correct); return smemeq(correct, blk + len, 32); diff --git a/sshsha.c b/sshsha.c index ddcab81e..4b9d002f 100644 --- a/sshsha.c +++ b/sshsha.c @@ -294,7 +294,7 @@ static void sha1_free_context(void *handle) sfree(handle); } -static void sha1_key_internal(void *handle, unsigned char *key, int len) +static void sha1_key_internal(void *handle, const unsigned char *key, int len) { SHA_State *keys = (SHA_State *)handle; unsigned char foo[64]; @@ -315,12 +315,12 @@ static void sha1_key_internal(void *handle, unsigned char *key, int len) smemclr(foo, 64); /* burn the evidence */ } -static void sha1_key(void *handle, unsigned char *key) +static void sha1_key(void *handle, const void *key) { sha1_key_internal(handle, key, 20); } -static void sha1_key_buggy(void *handle, unsigned char *key) +static void sha1_key_buggy(void *handle, const void *key) { sha1_key_internal(handle, key, 16); } @@ -354,7 +354,7 @@ static void hmacsha1_genresult(void *handle, unsigned char *hmac) SHA_Final(&s, hmac); } -static void sha1_do_hmac(void *handle, unsigned char *blk, int len, +static void sha1_do_hmac(void *handle, const unsigned char *blk, int len, unsigned long seq, unsigned char *hmac) { BinarySink *bs = hmacsha1_sink(handle); @@ -364,9 +364,10 @@ static void sha1_do_hmac(void *handle, unsigned char *blk, int len, hmacsha1_genresult(handle, hmac); } -static void sha1_generate(void *handle, unsigned char *blk, int len, +static void sha1_generate(void *handle, void *vblk, int len, unsigned long seq) { + unsigned char *blk = (unsigned char *)vblk; sha1_do_hmac(handle, blk, len, seq, blk + len); } @@ -377,9 +378,10 @@ static int hmacsha1_verresult(void *handle, unsigned char const *hmac) return smemeq(correct, hmac, 20); } -static int sha1_verify(void *handle, unsigned char *blk, int len, +static int sha1_verify(void *handle, const void *vblk, int len, unsigned long seq) { + const unsigned char *blk = (const unsigned char *)vblk; unsigned char correct[20]; sha1_do_hmac(handle, blk, len, seq, correct); return smemeq(correct, blk + len, 20); @@ -392,9 +394,10 @@ static void hmacsha1_96_genresult(void *handle, unsigned char *hmac) memcpy(hmac, full, 12); } -static void sha1_96_generate(void *handle, unsigned char *blk, int len, +static void sha1_96_generate(void *handle, void *vblk, int len, unsigned long seq) { + unsigned char *blk = (unsigned char *)vblk; unsigned char full[20]; sha1_do_hmac(handle, blk, len, seq, full); memcpy(blk + len, full, 12); @@ -407,9 +410,10 @@ static int hmacsha1_96_verresult(void *handle, unsigned char const *hmac) return smemeq(correct, hmac, 12); } -static int sha1_96_verify(void *handle, unsigned char *blk, int len, +static int sha1_96_verify(void *handle, const void *vblk, int len, unsigned long seq) { + const unsigned char *blk = (const unsigned char *)vblk; unsigned char correct[20]; sha1_do_hmac(handle, blk, len, seq, correct); return smemeq(correct, blk + len, 12);