diff options
author | Mattias Andrée <maandree@kth.se> | 2022-01-21 16:31:52 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-01-21 16:31:52 +0100 |
commit | 900e1a78c71aeba3ec72eb3bac6ce863f563a449 (patch) | |
tree | a6cc791f003bc57f69589965a14574a094a1284c /test.c | |
parent | Fix warnings (diff) | |
download | libblake-900e1a78c71aeba3ec72eb3bac6ce863f563a449.tar.gz libblake-900e1a78c71aeba3ec72eb3bac6ce863f563a449.tar.bz2 libblake-900e1a78c71aeba3ec72eb3bac6ce863f563a449.tar.xz |
Fix memory corruption bug in test.c and simplify message byte-length calculation
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -35,7 +35,7 @@ check_hex(int uppercase, const char *hex, const unsigned char *bin, size_t n) static const char * digest_blake1(int length, const void *msg, size_t msglen, size_t bits) { - static char hex[sizeof(LIBBLAKE_BLAKE512_OUTPUT_SIZE) * 2 + 1]; + static char hex[LIBBLAKE_BLAKE512_OUTPUT_SIZE * 2 + 1]; unsigned char buf[LIBBLAKE_BLAKE512_OUTPUT_SIZE]; size_t req; char *data; @@ -45,7 +45,7 @@ digest_blake1(int length, const void *msg, size_t msglen, size_t bits) struct libblake_blake##BITS##_state s##BITS;\ req = libblake_blake##BITS##_digest_get_required_input_size(msglen, bits, NULL);\ data = malloc(req);\ - memcpy(data, msg, msglen + bits / 8 + !!(bits & 7));\ + memcpy(data, msg, msglen + (bits + 7) / 8);\ libblake_blake##BITS##_init(&s##BITS);\ libblake_blake##BITS##_digest(&s##BITS, data, msglen, bits, NULL, buf);\ libblake_encode_hex(buf, LIBBLAKE_BLAKE##BITS##_OUTPUT_SIZE, hex, 0);\ |