diff --git a/base16-decode.c b/base16-decode.c index 28acc40480f17b79242cadad379d653efb2d50c0..fc33123677bed32d9f80f16e5ae0ee35a64fe2b2 100644 --- a/base16-decode.c +++ b/base16-decode.c @@ -66,14 +66,16 @@ hex_decode_table[0x80] = int base16_decode_single(struct base16_decode_ctx *ctx, uint8_t *dst, - uint8_t src) + char src) { + /* Avoid signed char for indexing. */ + unsigned char usrc = src; int digit; - if (src >= 0x80) + if (usrc >= 0x80) return -1; - digit = hex_decode_table[src]; + digit = hex_decode_table[usrc]; switch (digit) { case -1: @@ -104,7 +106,7 @@ base16_decode_update(struct base16_decode_ctx *ctx, size_t *dst_length, uint8_t *dst, size_t src_length, - const uint8_t *src) + const char *src) { size_t done; size_t i; diff --git a/base16-encode.c b/base16-encode.c index 297491ad4f0ee6d955dc210bba36652975c7bd06..9c7f0b1ed017c54678257c50d9f574825bc506b8 100644 --- a/base16-encode.c +++ b/base16-encode.c @@ -45,7 +45,7 @@ hex_digits[16] = "0123456789abcdef"; /* Encodes a single byte. Always stores two digits in dst[0] and dst[1]. */ void -base16_encode_single(uint8_t *dst, +base16_encode_single(char *dst, uint8_t src) { dst[0] = DIGIT(src/0x10); @@ -54,7 +54,7 @@ base16_encode_single(uint8_t *dst, /* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */ void -base16_encode_update(uint8_t *dst, +base16_encode_update(char *dst, size_t length, const uint8_t *src) { diff --git a/base16-meta.c b/base16-meta.c index a2a109068bc3d8fd3a19494909ef04c1a14ddb1e..a7789c50afa3290fa302d0392f569ddc112683ed 100644 --- a/base16-meta.c +++ b/base16-meta.c @@ -59,7 +59,7 @@ base16_encode_init(void *ctx UNUSED) static nettle_armor_encode_update_func base16_encode_update_wrapper; static size_t -base16_encode_update_wrapper(void *ctx UNUSED, uint8_t *dst, +base16_encode_update_wrapper(void *ctx UNUSED, char *dst, size_t length, const uint8_t *src) { base16_encode_update(dst, length, src); @@ -71,7 +71,7 @@ base16_encode_update_wrapper(void *ctx UNUSED, uint8_t *dst, static nettle_armor_encode_final_func base16_encode_final; static size_t -base16_encode_final(void *ctx UNUSED, uint8_t *dst UNUSED) +base16_encode_final(void *ctx UNUSED, char *dst UNUSED) { return 0; } diff --git a/base16.h b/base16.h index 2579c0efa661a24d758559a6bd0601cbda660948..755e6ed321eb87b6b90cbd9843c4fc7dddb214c6 100644 --- a/base16.h +++ b/base16.h @@ -56,12 +56,12 @@ extern "C" { /* Encodes a single byte. Always stores two digits in dst[0] and dst[1]. */ void -base16_encode_single(uint8_t *dst, +base16_encode_single(char *dst, uint8_t src); /* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */ void -base16_encode_update(uint8_t *dst, +base16_encode_update(char *dst, size_t length, const uint8_t *src); @@ -86,7 +86,7 @@ base16_decode_init(struct base16_decode_ctx *ctx); int base16_decode_single(struct base16_decode_ctx *ctx, uint8_t *dst, - uint8_t src); + char src); /* Returns 1 on success, 0 on error. DST should point to an area of * size at least BASE16_DECODE_LENGTH(length). The amount of data @@ -97,7 +97,7 @@ base16_decode_update(struct base16_decode_ctx *ctx, size_t *dst_length, uint8_t *dst, size_t src_length, - const uint8_t *src); + const char *src); /* Returns 1 on success. */ int diff --git a/base64-decode.c b/base64-decode.c index 337ea3953d6ab6d2f0f1c30f635f5609d90e63c1..b993117ad8eb111ec2000d3102ff08c115e32ab7 100644 --- a/base64-decode.c +++ b/base64-decode.c @@ -73,9 +73,9 @@ base64_decode_init(struct base64_decode_ctx *ctx) int base64_decode_single(struct base64_decode_ctx *ctx, uint8_t *dst, - uint8_t src) + char src) { - int data = ctx->table[src]; + int data = ctx->table[(uint8_t) src]; switch(data) { @@ -122,7 +122,7 @@ base64_decode_update(struct base64_decode_ctx *ctx, size_t *dst_length, uint8_t *dst, size_t src_length, - const uint8_t *src) + const char *src) { size_t done; size_t i; diff --git a/base64-encode.c b/base64-encode.c index f23115a9ff9bb8655ec2bef77232af847ced723c..42fa016d7191fa3ecdd7d47c00ee0a39c9ffc010 100644 --- a/base64-encode.c +++ b/base64-encode.c @@ -41,11 +41,11 @@ #define ENCODE(alphabet,x) ((alphabet)[0x3F & (x)]) static void -encode_raw(const uint8_t *alphabet, - uint8_t *dst, size_t length, const uint8_t *src) +encode_raw(const char *alphabet, + char *dst, size_t length, const uint8_t *src) { const uint8_t *in = src + length; - uint8_t *out = dst + BASE64_ENCODE_RAW_LENGTH(length); + char *out = dst + BASE64_ENCODE_RAW_LENGTH(length); unsigned left_over = length % 3; @@ -83,19 +83,19 @@ encode_raw(const uint8_t *alphabet, assert(out == dst); } -static const uint8_t base64_encode_table[64] = +static const char base64_encode_table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; void -base64_encode_raw(uint8_t *dst, size_t length, const uint8_t *src) +base64_encode_raw(char *dst, size_t length, const uint8_t *src) { encode_raw(base64_encode_table, dst, length, src); } void -base64_encode_group(uint8_t *dst, uint32_t group) +base64_encode_group(char *dst, uint32_t group) { *dst++ = ENCODE(base64_encode_table, (group >> 18)); *dst++ = ENCODE(base64_encode_table, (group >> 12)); @@ -113,7 +113,7 @@ base64_encode_init(struct base64_encode_ctx *ctx) /* Encodes a single byte. */ size_t base64_encode_single(struct base64_encode_ctx *ctx, - uint8_t *dst, + char *dst, uint8_t src) { unsigned done = 0; @@ -138,7 +138,7 @@ base64_encode_single(struct base64_encode_ctx *ctx, * area of size at least BASE64_ENCODE_LENGTH(length). */ size_t base64_encode_update(struct base64_encode_ctx *ctx, - uint8_t *dst, + char *dst, size_t length, const uint8_t *src) { @@ -181,7 +181,7 @@ base64_encode_update(struct base64_encode_ctx *ctx, * BASE64_ENCODE_FINAL_SIZE */ size_t base64_encode_final(struct base64_encode_ctx *ctx, - uint8_t *dst) + char *dst) { unsigned done = 0; unsigned bits = ctx->bits; diff --git a/base64.h b/base64.h index 79194bd4f6ed5b818984f50a29e24342d6191b6f..a6cac86067644b2f6d6865af3564a16f0eca5c06 100644 --- a/base64.h +++ b/base64.h @@ -73,7 +73,7 @@ extern "C" { struct base64_encode_ctx { - const uint8_t *alphabet; /* Alphabet to use for encoding */ + const char *alphabet; /* Alphabet to use for encoding */ unsigned short word; /* Leftover bits */ unsigned char bits; /* Number of bits, always 0, 2, or 4. */ }; @@ -89,14 +89,14 @@ base64url_encode_init(struct base64_encode_ctx *ctx); /* Encodes a single byte. Returns amount of output (always 1 or 2). */ size_t base64_encode_single(struct base64_encode_ctx *ctx, - uint8_t *dst, + char *dst, uint8_t src); /* Returns the number of output characters. DST should point to an * area of size at least BASE64_ENCODE_LENGTH(length). */ size_t base64_encode_update(struct base64_encode_ctx *ctx, - uint8_t *dst, + char *dst, size_t length, const uint8_t *src); @@ -104,7 +104,7 @@ base64_encode_update(struct base64_encode_ctx *ctx, * BASE64_ENCODE_FINAL_LENGTH */ size_t base64_encode_final(struct base64_encode_ctx *ctx, - uint8_t *dst); + char *dst); /* Lower level functions */ @@ -112,10 +112,10 @@ base64_encode_final(struct base64_encode_ctx *ctx, * Generates exactly BASE64_ENCODE_RAW_LENGTH(length) bytes of output. * Supports overlapped operation, if src <= dst. */ void -base64_encode_raw(uint8_t *dst, size_t length, const uint8_t *src); +base64_encode_raw(char *dst, size_t length, const uint8_t *src); void -base64_encode_group(uint8_t *dst, uint32_t group); +base64_encode_group(char *dst, uint32_t group); /* Base64 decoding */ @@ -147,7 +147,7 @@ base64url_decode_init(struct base64_decode_ctx *ctx); int base64_decode_single(struct base64_decode_ctx *ctx, uint8_t *dst, - uint8_t src); + char src); /* Returns 1 on success, 0 on error. DST should point to an area of * size at least BASE64_DECODE_LENGTH(length). The amount of data @@ -157,7 +157,7 @@ base64_decode_update(struct base64_decode_ctx *ctx, size_t *dst_length, uint8_t *dst, size_t src_length, - const uint8_t *src); + const char *src); /* Returns 1 on success. */ int diff --git a/base64url-encode.c b/base64url-encode.c index 6af33fb893d66e42df69d245362ae9337e60a552..d30044ea8686626d83b972ce666c1ffe7fb278f3 100644 --- a/base64url-encode.c +++ b/base64url-encode.c @@ -38,7 +38,7 @@ void base64url_encode_init(struct base64_encode_ctx *ctx) { - static const uint8_t base64url_encode_table[64] = + static const char base64url_encode_table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789-_"; diff --git a/examples/base16dec.c b/examples/base16dec.c index 7071456713ab368b0cc2596f0575cc2ee5cc4b14..1185b3e1bf8f5195b29dd5db6bdadab461f61319 100644 --- a/examples/base16dec.c +++ b/examples/base16dec.c @@ -58,7 +58,7 @@ int main(int argc UNUSED, char **argv UNUSED) { /* "buffer" will hold the bytes from disk: */ - uint8_t * buffer = xalloc (CHUNK_SIZE); + char * buffer = xalloc (CHUNK_SIZE); /* "result" will hold bytes before output: */ uint8_t * result = xalloc (DECODED_SIZE); diff --git a/examples/base16enc.c b/examples/base16enc.c index 02e4f2808fa82573be2f8a2c2140ec6cd085f995..6ac08e1dd0ceea548db1d4cf2205a3272105e2e5 100644 --- a/examples/base16enc.c +++ b/examples/base16enc.c @@ -70,7 +70,7 @@ main(int argc UNUSED, char **argv UNUSED) /* "buffer" will hold the bytes from disk: */ uint8_t buffer[CHUNK_SIZE]; /* "result" will hold bytes before output: */ - uint8_t result[ENCODED_SIZE + 1]; + char result[ENCODED_SIZE + 1]; unsigned nbytes; /* Number of bytes read from stdin */ int encoded_bytes; /* Total number of bytes encoded per iteration */ diff --git a/examples/base64dec.c b/examples/base64dec.c index 624de628f89b78a7146727f20ab764efc6367561..d05d924a5f9a508e26dac6fce5d2e50682bf6a23 100644 --- a/examples/base64dec.c +++ b/examples/base64dec.c @@ -58,7 +58,7 @@ int main(int argc UNUSED, char **argv UNUSED) { /* "buffer" will hold the bytes from disk: */ - uint8_t * buffer = xalloc (CHUNK_SIZE); + char * buffer = xalloc (CHUNK_SIZE); /* "result" will hold bytes before output: */ uint8_t * result = xalloc (DECODED_SIZE); diff --git a/examples/base64enc.c b/examples/base64enc.c index f8ba829bb772f2c38b1d33224aced8ea7b01a3a1..cc6010cc15acb4a0c4727f6cbb5acdd910f3b66e 100644 --- a/examples/base64enc.c +++ b/examples/base64enc.c @@ -72,7 +72,7 @@ main(int argc UNUSED, char **argv UNUSED) /* "buffer" will hold the bytes from disk: */ uint8_t buffer[CHUNK_SIZE]; /* "result" is the result vector: */ - uint8_t result[ENCODED_SIZE + BASE64_ENCODE_FINAL_LENGTH + 1]; + char result[ENCODED_SIZE + BASE64_ENCODE_FINAL_LENGTH + 1]; unsigned nbytes; /* Number of bytes read from stdin */ int encoded_bytes; /* total number of bytes encoded per iteration */ nbytes = fread(buffer,1,CHUNK_SIZE,stdin); diff --git a/nettle-types.h b/nettle-types.h index 475937d20d47e38b9a34239c2a794c4aba1cabd4..84c375d2e6d49608fe7c5cecb0412d04228c0eca 100644 --- a/nettle-types.h +++ b/nettle-types.h @@ -89,17 +89,17 @@ typedef size_t nettle_armor_length_func(size_t length); typedef void nettle_armor_init_func(void *ctx); typedef size_t nettle_armor_encode_update_func(void *ctx, - uint8_t *dst, + char *dst, size_t src_length, const uint8_t *src); -typedef size_t nettle_armor_encode_final_func(void *ctx, uint8_t *dst); +typedef size_t nettle_armor_encode_final_func(void *ctx, char *dst); typedef int nettle_armor_decode_update_func(void *ctx, size_t *dst_length, uint8_t *dst, size_t src_length, - const uint8_t *src); + const char *src); typedef int nettle_armor_decode_final_func(void *ctx); diff --git a/pgp-encode.c b/pgp-encode.c index fc78e7f66302c29f8180da91ddbad81c663f2b9a..c051f9e44e15cbc3c61a5377eb88b4f70b77e344 100644 --- a/pgp-encode.c +++ b/pgp-encode.c @@ -371,8 +371,8 @@ pgp_armor(struct nettle_buffer *buffer, length -= BINARY_PER_LINE, data += BINARY_PER_LINE) { unsigned done; - uint8_t *p - = nettle_buffer_space(buffer, TEXT_PER_LINE); + char *p + = (char *) nettle_buffer_space(buffer, TEXT_PER_LINE); if (!p) return 0; @@ -393,8 +393,8 @@ pgp_armor(struct nettle_buffer *buffer, + BASE64_ENCODE_FINAL_LENGTH; unsigned done; - uint8_t *p - = nettle_buffer_space(buffer, text_size); + char *p + = (char *) nettle_buffer_space(buffer, text_size); if (!p) return 0; @@ -412,7 +412,7 @@ pgp_armor(struct nettle_buffer *buffer, return 0; { - uint8_t *p = nettle_buffer_space(buffer, 4); + char *p = (char *) nettle_buffer_space(buffer, 4); if (!p) return 0; base64_encode_group(p, crc); diff --git a/sexp-transport-format.c b/sexp-transport-format.c index c9946a70a85d34358162b9b10b351d77a1dc3921..70de1c03e4f531539f892ad0d7658bc70d7521d0 100644 --- a/sexp-transport-format.c +++ b/sexp-transport-format.c @@ -68,7 +68,7 @@ sexp_transport_vformat(struct nettle_buffer *buffer, if (!nettle_buffer_space(buffer, base64_length - length)) return 0; - base64_encode_raw(buffer->contents + start, + base64_encode_raw((char*) (buffer->contents + start), length, buffer->contents + start); if (!NETTLE_BUFFER_PUTC(buffer, '}')) diff --git a/sexp-transport.c b/sexp-transport.c index 8736478a22b26e80c8cd8de075f6680595c4a298..1a34db7129b0d0ef251ddd5f1e9834c753e6546e 100644 --- a/sexp-transport.c +++ b/sexp-transport.c @@ -84,7 +84,7 @@ sexp_transport_iterator_first(struct sexp_iterator *iterator, base64_decode_init(&ctx); if (base64_decode_update(&ctx, &coded_length, input + out, - end - in, input + in) + end - in, (const char*) (input + in)) && base64_decode_final(&ctx)) { out += coded_length; diff --git a/testsuite/testutils.c b/testsuite/testutils.c index 6f897617cadbd23077a5adbeac91d73c671140e5..c4ce71b178fec77c5d47577808024eb609d77e43 100644 --- a/testsuite/testutils.c +++ b/testsuite/testutils.c @@ -566,7 +566,7 @@ test_armor(const struct nettle_armor *armor, const char *ascii) { size_t ascii_length = strlen(ascii); - uint8_t *buffer = xalloc(1 + ascii_length); + char *buffer = xalloc(1 + ascii_length); uint8_t *check = xalloc(1 + armor->decode_length(ascii_length)); void *encode = xalloc(armor->encode_context_size); void *decode = xalloc(armor->decode_context_size); diff --git a/tools/input.c b/tools/input.c index 18a9dff5c5659382bac92e2080ffdb72df49772c..90e41a29058e83b5dbde988a11628e428fcb7b8b 100644 --- a/tools/input.c +++ b/tools/input.c @@ -90,7 +90,7 @@ sexp_get_char(struct sexp_input *input) * character at a time. */ if (!input->coding->decode_update(&input->state, &done, &input->c, - 1, &input->c)) + 1, (const char*) &input->c)) die("Invalid coded data.\n"); if (done) diff --git a/tools/nettle-pbkdf2.c b/tools/nettle-pbkdf2.c index c9e4d11c5604d5640b75a40202222c9ca255adf3..1f0a3015ad3c7fd18f016b9e1a4d4d9b10e27ad1 100644 --- a/tools/nettle-pbkdf2.c +++ b/tools/nettle-pbkdf2.c @@ -73,7 +73,7 @@ main (int argc, char **argv) size_t password_length; uint8_t *output; size_t salt_length; - uint8_t *salt; + char *salt; int raw = 0; int hex_salt = 0; int c; @@ -141,7 +141,7 @@ main (int argc, char **argv) return EXIT_FAILURE; } - salt = (uint8_t *) strdup (argv[0]); + salt = strdup (argv[0]); salt_length = strlen(argv[0]); if (hex_salt) @@ -150,7 +150,7 @@ main (int argc, char **argv) base16_decode_init (&base16); if (!base16_decode_update (&base16, - &salt_length, salt, + &salt_length, (uint8_t *) salt, salt_length, salt) || !base16_decode_final (&base16)) die ("Invalid salt (expecting hex encoding).\n"); @@ -165,7 +165,7 @@ main (int argc, char **argv) output = xalloc (output_length); pbkdf2_hmac_sha256 (password_length, (const uint8_t *) password, - iterations, salt_length, salt, + iterations, salt_length, (const uint8_t*) salt, output_length, output); free (salt); diff --git a/tools/output.c b/tools/output.c index 02e43d58547c56f82a2d6374206e102f7c9ee9e8..80a44a97c468652ad97716e59e8953c317406dcc 100644 --- a/tools/output.c +++ b/tools/output.c @@ -114,7 +114,7 @@ sexp_put_char(struct sexp_output *output, uint8_t c) if (output->coding) { /* Two is enough for both base16 and base64. */ - uint8_t encoded[2]; + char encoded[2]; unsigned done; unsigned i; @@ -183,7 +183,7 @@ void sexp_put_code_end(struct sexp_output *output) { /* Enough for both hex and base64 */ - uint8_t encoded[BASE64_ENCODE_FINAL_LENGTH]; + char encoded[BASE64_ENCODE_FINAL_LENGTH]; unsigned done; assert(output->coding); @@ -194,7 +194,7 @@ sexp_put_code_end(struct sexp_output *output) output->coding = NULL; - sexp_put_data(output, done, encoded); + sexp_put_data(output, done, (const uint8_t*) encoded); } void diff --git a/tools/pkcs1-conv.c b/tools/pkcs1-conv.c index 9e346858b18273ba37cb38a8a658cd071ad169b0..c8697c445dc5c2a74258a93400e90eaaf799aba4 100644 --- a/tools/pkcs1-conv.c +++ b/tools/pkcs1-conv.c @@ -255,7 +255,7 @@ decode_base64(struct nettle_buffer *buffer, /* Decode in place */ if (base64_decode_update(&ctx, length, buffer->contents + start, - *length, buffer->contents + start) + *length, (const char *) buffer->contents + start) && base64_decode_final(&ctx)) return 1;