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:
size_t *dst_length,
uint8_t *dst,
size_t src_length,
- const uint8_t *src)
+ const char *src)
{
size_t done;
size_t i;
/* 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);
/* 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)
{
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);
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;
}
/* 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);
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
size_t *dst_length,
uint8_t *dst,
size_t src_length,
- const uint8_t *src);
+ const char *src);
/* Returns 1 on success. */
int
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)
{
size_t *dst_length,
uint8_t *dst,
size_t src_length,
- const uint8_t *src)
+ const char *src)
{
size_t done;
size_t i;
#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;
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));
/* 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;
* 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)
{
* 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;
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. */
};
/* 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);
* BASE64_ENCODE_FINAL_LENGTH */
size_t
base64_encode_final(struct base64_encode_ctx *ctx,
- uint8_t *dst);
+ char *dst);
/* Lower level functions */
* 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 */
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
size_t *dst_length,
uint8_t *dst,
size_t src_length,
- const uint8_t *src);
+ const char *src);
/* Returns 1 on success. */
int
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-_";
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);
/* "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 */
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);
/* "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);
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);
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;
+ 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;
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);
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, '}'))
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;
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);
* 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)
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;
return EXIT_FAILURE;
}
- salt = (uint8_t *) strdup (argv[0]);
+ salt = strdup (argv[0]);
salt_length = strlen(argv[0]);
if (hex_salt)
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");
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);
if (output->coding)
{
/* Two is enough for both base16 and base64. */
- uint8_t encoded[2];
+ char encoded[2];
unsigned done;
unsigned i;
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);
output->coding = NULL;
- sexp_put_data(output, done, encoded);
+ sexp_put_data(output, done, (const uint8_t*) encoded);
}
void
/* 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;