Commit 96f1348e authored by Niels Möller's avatar Niels Möller

Rename write_string --> write_date.

Change type of input data to const void *, for this function and
write_file.
parent 3f4c5318
2016-08-16 Niels Möller <nisse@lysator.liu.se>
* examples/io.c (write_data): Renamed, and use const void * for
the input data. Updated all callers.
(write_string): ... old name.
(write_file): Use const void * for the input data.
2016-08-05 Niels Möller <nisse@lysator.liu.se> 2016-08-05 Niels Möller <nisse@lysator.liu.se>
* examples/hogweed-benchmark.c: Use uint8_t for curve25519 values. * examples/hogweed-benchmark.c: Use uint8_t for curve25519 values.
......
...@@ -93,7 +93,7 @@ main(int argc UNUSED, char **argv UNUSED) ...@@ -93,7 +93,7 @@ main(int argc UNUSED, char **argv UNUSED)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!write_string (stdout, decoded_bytes, result)) if (!write_data (stdout, decoded_bytes, result))
{ {
werror ("Error writing file: %s\n", strerror(errno)); werror ("Error writing file: %s\n", strerror(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
......
...@@ -88,7 +88,7 @@ main(int argc UNUSED, char **argv UNUSED) ...@@ -88,7 +88,7 @@ main(int argc UNUSED, char **argv UNUSED)
werror ("Error reading file: %s\n", strerror(errno)); werror ("Error reading file: %s\n", strerror(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!write_string (stdout, encoded_bytes, result) if (!write_data (stdout, encoded_bytes, result)
|| fflush (stdout) != 0) || fflush (stdout) != 0)
{ {
werror ("Error writing file: %s\n", strerror(errno)); werror ("Error writing file: %s\n", strerror(errno));
...@@ -97,7 +97,7 @@ main(int argc UNUSED, char **argv UNUSED) ...@@ -97,7 +97,7 @@ main(int argc UNUSED, char **argv UNUSED)
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* The result vector is printed */ /* The result vector is printed */
if (!write_string(stdout,encoded_bytes, result)) if (!write_data(stdout, encoded_bytes, result))
{ {
werror ("Error writing file: %s\n", strerror(errno)); werror ("Error writing file: %s\n", strerror(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
......
...@@ -93,7 +93,7 @@ main(int argc UNUSED, char **argv UNUSED) ...@@ -93,7 +93,7 @@ main(int argc UNUSED, char **argv UNUSED)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!write_string (stdout, decoded_bytes, result)) if (!write_data (stdout, decoded_bytes, result))
{ {
werror ("Error writing file: %s\n", strerror(errno)); werror ("Error writing file: %s\n", strerror(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
......
...@@ -90,7 +90,7 @@ main(int argc UNUSED, char **argv UNUSED) ...@@ -90,7 +90,7 @@ main(int argc UNUSED, char **argv UNUSED)
encoded_bytes += base64_encode_final(&b64_ctx,result + encoded_bytes); encoded_bytes += base64_encode_final(&b64_ctx,result + encoded_bytes);
result[encoded_bytes++] = '\n'; result[encoded_bytes++] = '\n';
if (!write_string (stdout, encoded_bytes, result) if (!write_data (stdout, encoded_bytes, result)
|| fflush (stdout) != 0) || fflush (stdout) != 0)
{ {
werror ("Error writing file: %s\n", strerror(errno)); werror ("Error writing file: %s\n", strerror(errno));
...@@ -101,7 +101,7 @@ main(int argc UNUSED, char **argv UNUSED) ...@@ -101,7 +101,7 @@ main(int argc UNUSED, char **argv UNUSED)
/* The result vector is written */ /* The result vector is written */
result[encoded_bytes++] = '\n'; result[encoded_bytes++] = '\n';
if (!write_string (stdout, encoded_bytes, result)) if (!write_data (stdout, encoded_bytes, result))
{ {
werror ("Error writing file: %s\n", strerror(errno)); werror ("Error writing file: %s\n", strerror(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
......
...@@ -143,7 +143,7 @@ read_file(const char *name, size_t max_size, uint8_t **contents) ...@@ -143,7 +143,7 @@ read_file(const char *name, size_t max_size, uint8_t **contents)
} }
int int
write_string(FILE *f, unsigned size, const char *buffer) write_data(FILE *f, size_t size, const void *buffer)
{ {
size_t res = fwrite(buffer, 1, size, f); size_t res = fwrite(buffer, 1, size, f);
...@@ -151,7 +151,7 @@ write_string(FILE *f, unsigned size, const char *buffer) ...@@ -151,7 +151,7 @@ write_string(FILE *f, unsigned size, const char *buffer)
} }
int int
write_file(const char *name, unsigned size, const char *buffer) write_file(const char *name, size_t size, const void *buffer)
{ {
FILE *f = fopen(name, "wb"); FILE *f = fopen(name, "wb");
int res; int res;
...@@ -159,7 +159,7 @@ write_file(const char *name, unsigned size, const char *buffer) ...@@ -159,7 +159,7 @@ write_file(const char *name, unsigned size, const char *buffer)
if (!f) if (!f)
return 0; return 0;
res = write_string(f, size, buffer); res = write_data(f, size, buffer);
return fclose(f) == 0 && res; return fclose(f) == 0 && res;
} }
......
...@@ -56,10 +56,10 @@ size_t ...@@ -56,10 +56,10 @@ size_t
read_file(const char *name, size_t size, uint8_t **buffer); read_file(const char *name, size_t size, uint8_t **buffer);
int int
write_file(const char *name, unsigned size, const char *buffer); write_file(const char *name, size_t size, const void *data);
int int
write_string(FILE *f, unsigned size, const char *buffer); write_data(FILE *f, size_t size, const void *data);
int int
simple_random(struct yarrow256_ctx *ctx, const char *name); simple_random(struct yarrow256_ctx *ctx, const char *name);
......
...@@ -159,7 +159,7 @@ process_file(struct rsa_session *ctx, ...@@ -159,7 +159,7 @@ process_file(struct rsa_session *ctx,
{ {
CBC_DECRYPT(&ctx->aes, aes_decrypt, size, buffer, buffer); CBC_DECRYPT(&ctx->aes, aes_decrypt, size, buffer, buffer);
hmac_sha1_update(&ctx->hmac, size, buffer); hmac_sha1_update(&ctx->hmac, size, buffer);
if (!write_string(out, size, buffer)) if (!write_data(out, size, buffer))
{ {
werror("Writing output failed: %s\n", strerror(errno)); werror("Writing output failed: %s\n", strerror(errno));
return 0; return 0;
...@@ -182,7 +182,7 @@ process_file(struct rsa_session *ctx, ...@@ -182,7 +182,7 @@ process_file(struct rsa_session *ctx,
{ {
unsigned leftover = AES_BLOCK_SIZE - padding; unsigned leftover = AES_BLOCK_SIZE - padding;
hmac_sha1_update(&ctx->hmac, leftover, buffer); hmac_sha1_update(&ctx->hmac, leftover, buffer);
if (!write_string(out, leftover, buffer)) if (!write_data(out, leftover, buffer))
{ {
werror("Writing output failed: %s\n", strerror(errno)); werror("Writing output failed: %s\n", strerror(errno));
return 0; return 0;
......
...@@ -74,7 +74,7 @@ write_uint32(FILE *f, uint32_t n) ...@@ -74,7 +74,7 @@ write_uint32(FILE *f, uint32_t n)
uint8_t buffer[4]; uint8_t buffer[4];
WRITE_UINT32(buffer, n); WRITE_UINT32(buffer, n);
return write_string(f, sizeof(buffer), buffer); return write_data(f, sizeof(buffer), buffer);
} }
static int static int
...@@ -96,7 +96,7 @@ write_bignum(FILE *f, mpz_t x) ...@@ -96,7 +96,7 @@ write_bignum(FILE *f, mpz_t x)
p = xalloc(size); p = xalloc(size);
nettle_mpz_get_str_256(size, p, x); nettle_mpz_get_str_256(size, p, x);
res = write_string(f, size, p); res = write_data(f, size, p);
free(p); free(p);
return res; return res;
} }
...@@ -143,7 +143,7 @@ process_file(struct rsa_session *ctx, ...@@ -143,7 +143,7 @@ process_file(struct rsa_session *ctx,
hmac_sha1_digest(&ctx->hmac, SHA1_DIGEST_SIZE, buffer + size); hmac_sha1_digest(&ctx->hmac, SHA1_DIGEST_SIZE, buffer + size);
size += SHA1_DIGEST_SIZE; size += SHA1_DIGEST_SIZE;
if (!write_string(out, size, buffer)) if (!write_data(out, size, buffer))
{ {
werror("Writing output failed: %s\n", strerror(errno)); werror("Writing output failed: %s\n", strerror(errno));
return 0; return 0;
...@@ -152,7 +152,7 @@ process_file(struct rsa_session *ctx, ...@@ -152,7 +152,7 @@ process_file(struct rsa_session *ctx,
} }
CBC_ENCRYPT(&ctx->aes, aes_encrypt, size, buffer, buffer); CBC_ENCRYPT(&ctx->aes, aes_encrypt, size, buffer, buffer);
if (!write_string(out, size, buffer)) if (!write_data(out, size, buffer))
{ {
werror("Writing output failed: %s\n", strerror(errno)); werror("Writing output failed: %s\n", strerror(errno));
return 0; return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment