aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-07-30 18:06:26 +0200
committerMattias Andrée <maandree@kth.se>2021-07-30 18:06:26 +0200
commita198f806d60b641406955d6b8c494b2bd5d8989c (patch)
tree27883711145184fff8d9dc564d368383b1c675db
parentFix warning (diff)
downloadlibkeccak-a198f806d60b641406955d6b8c494b2bd5d8989c.tar.gz
libkeccak-a198f806d60b641406955d6b8c494b2bd5d8989c.tar.bz2
libkeccak-a198f806d60b641406955d6b8c494b2bd5d8989c.tar.xz
Do not divide by sizeof(char)
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--libkeccak.h8
-rw-r--r--libkeccak_hmac_copy.c2
-rw-r--r--libkeccak_hmac_set_key.c4
-rw-r--r--libkeccak_hmac_unmarshal.c10
-rw-r--r--libkeccak_state_marshal.c4
-rw-r--r--libkeccak_state_unmarshal.c6
6 files changed, 17 insertions, 17 deletions
diff --git a/libkeccak.h b/libkeccak.h
index 36c86f3..df712d8 100644
--- a/libkeccak.h
+++ b/libkeccak.h
@@ -808,7 +808,7 @@ struct libkeccak_hmac_state {
*/
unsigned char leftover;
- char __pad[sizeof(void *) / sizeof(char) - 1];
+ char __pad[sizeof(void *) - 1];
};
@@ -1008,11 +1008,11 @@ libkeccak_hmac_marshal(const struct libkeccak_hmac_state *restrict state, void *
unsigned char *restrict data = data_;
size_t written = libkeccak_state_marshal(&state->sponge, data);
if (data) {
- data += written / sizeof(char);
+ data += written;
*(size_t *)data = state->key_length;
- data += sizeof(size_t) / sizeof(char);
+ data += sizeof(size_t);
memcpy(data, state->key_opad, (state->key_length + 7) >> 3);
- data += ((state->key_length + 7) >> 3) / sizeof(char);
+ data += (state->key_length + 7) >> 3;
data[0] = (unsigned char)!!state->key_ipad;
data[1] = state->leftover;
}
diff --git a/libkeccak_hmac_copy.c b/libkeccak_hmac_copy.c
index 9c52328..6c61553 100644
--- a/libkeccak_hmac_copy.c
+++ b/libkeccak_hmac_copy.c
@@ -29,7 +29,7 @@ libkeccak_hmac_copy(struct libkeccak_hmac_state *restrict dest, const struct lib
libkeccak_state_destroy(&dest->sponge);
return -1;
}
- dest->key_ipad = dest->key_opad + size / sizeof(char);
+ dest->key_ipad = dest->key_opad + size;
memcpy(dest->key_opad, src->key_opad, size);
memcpy(dest->key_ipad, src->key_ipad, size);
diff --git a/libkeccak_hmac_set_key.c b/libkeccak_hmac_set_key.c
index f8f6a39..b056439 100644
--- a/libkeccak_hmac_set_key.c
+++ b/libkeccak_hmac_set_key.c
@@ -25,7 +25,7 @@ libkeccak_hmac_set_key(struct libkeccak_hmac_state *restrict state, const void *
state->key_opad = realloc(old = state->key_opad, 2 * size);
if (!state->key_opad)
return state->key_opad = old, -1;
- state->key_ipad = state->key_opad + size / sizeof(char);
+ state->key_ipad = state->key_opad + size;
}
memcpy(state->key_opad, key, key_bytes);
@@ -33,7 +33,7 @@ libkeccak_hmac_set_key(struct libkeccak_hmac_state *restrict state, const void *
state->key_opad[(key_bytes >> 3) - 1] &= (unsigned char)((1 << (key_length & 7)) - 1);
if ((size_t)(state->sponge.r) > key_length)
- __builtin_memset(state->key_opad + key_bytes / sizeof(char), 0, size - key_bytes);
+ __builtin_memset(state->key_opad + key_bytes, 0, size - key_bytes);
for (i = 0; i < size; i++) {
state->key_ipad[i] = state->key_opad[i] ^ HMAC_INNER_PAD;
diff --git a/libkeccak_hmac_unmarshal.c b/libkeccak_hmac_unmarshal.c
index 452efa3..2084e23 100644
--- a/libkeccak_hmac_unmarshal.c
+++ b/libkeccak_hmac_unmarshal.c
@@ -22,10 +22,10 @@ libkeccak_hmac_unmarshal(struct libkeccak_hmac_state *restrict state, const void
parsed = libkeccak_state_unmarshal(state ? &state->sponge : NULL, data);
if (!parsed)
return 0;
- data += parsed / sizeof(char);
+ data += parsed;
size = *(const size_t *)data;
- data += sizeof(size_t) / sizeof(char);
+ data += sizeof(size_t);
if (state)
size = state->key_length;
size = (state->key_length + 7) >> 3;
@@ -37,12 +37,12 @@ libkeccak_hmac_unmarshal(struct libkeccak_hmac_state *restrict state, const void
return 0;
}
memcpy(state->key_opad, data, size);
- data += size / sizeof(char);
+ data += size;
if (data[0]) {
- state->key_ipad = state->key_opad + size / sizeof(char);
+ state->key_ipad = state->key_opad + size;
memcpy(state->key_ipad, state->key_opad, size);
- for (i = 0; i < size / sizeof(char); i++)
+ for (i = 0; i < size; i++)
state->key_ipad[i] ^= (char)(HMAC_OUTER_PAD ^ HMAC_INNER_PAD);
}
diff --git a/libkeccak_state_marshal.c b/libkeccak_state_marshal.c
index c4ce7f6..896676d 100644
--- a/libkeccak_state_marshal.c
+++ b/libkeccak_state_marshal.c
@@ -12,7 +12,7 @@
size_t
libkeccak_state_marshal(const struct libkeccak_state *restrict state, void *restrict data_)
{
-#define set(type, var) *((type *)data) = state->var, data += sizeof(type) / sizeof(char)
+#define set(type, var) *((type *)data) = state->var, data += sizeof(type)
unsigned char *restrict data = data_;
if (data) {
set(long int, r);
@@ -24,7 +24,7 @@ libkeccak_state_marshal(const struct libkeccak_state *restrict state, void *rest
set(long int, l);
set(long int, nr);
memcpy(data, state->S, sizeof(state->S));
- data += sizeof(state->S) / sizeof(char);
+ data += sizeof(state->S);
set(size_t, mptr);
set(size_t, mlen);
memcpy(data, state->M, state->mptr * sizeof(char));
diff --git a/libkeccak_state_unmarshal.c b/libkeccak_state_unmarshal.c
index e46db54..6922a3e 100644
--- a/libkeccak_state_unmarshal.c
+++ b/libkeccak_state_unmarshal.c
@@ -13,10 +13,10 @@
size_t
libkeccak_state_unmarshal(struct libkeccak_state *restrict state, const void *restrict data_)
{
-#define get(type, var) state->var = *((const type *)data), data += sizeof(type) / sizeof(char)
+#define get(type, var) state->var = *((const type *)data), data += sizeof(type)
const unsigned char *restrict data = data_;
if (!state) {
- data += (7 * sizeof(long int) + 26 * sizeof(int64_t)) / sizeof(char);
+ data += (7 * sizeof(long int) + 26 * sizeof(int64_t));
return sizeof(struct libkeccak_state) - sizeof(char *) + *(const size_t *)data * sizeof(char);
}
get(long int, r);
@@ -28,7 +28,7 @@ libkeccak_state_unmarshal(struct libkeccak_state *restrict state, const void *re
get(long int, l);
get(long int, nr);
memcpy(state->S, data, sizeof(state->S));
- data += sizeof(state->S) / sizeof(char);
+ data += sizeof(state->S);
get(size_t, mptr);
get(size_t, mlen);
state->M = malloc(state->mptr * sizeof(char));