aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-01-19 22:39:52 +0100
committerMattias Andrée <maandree@kth.se>2022-01-19 22:39:52 +0100
commitcb9fd292424291ef4927f5bceb5910bf52a88a58 (patch)
tree83c6eadf1986d16c87941396accfba360ea4648c
parentAdd todos about more tests being needed (diff)
downloadlibblake-cb9fd292424291ef4927f5bceb5910bf52a88a58.tar.gz
libblake-cb9fd292424291ef4927f5bceb5910bf52a88a58.tar.bz2
libblake-cb9fd292424291ef4927f5bceb5910bf52a88a58.tar.xz
Fix warnings
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--common.h8
-rw-r--r--libblake.h11
-rw-r--r--libblake_blake2b_init.c21
-rw-r--r--libblake_blake2s_init.c23
-rw-r--r--libblake_internal_blake2b_output_digest.c2
-rw-r--r--libblake_internal_blake2s_output_digest.c2
-rw-r--r--libblake_internal_blake2xb_init0.c21
-rw-r--r--libblake_internal_blake2xs_init0.c25
-rw-r--r--test.c8
9 files changed, 83 insertions, 38 deletions
diff --git a/common.h b/common.h
index 3f9dce0..63d2bb4 100644
--- a/common.h
+++ b/common.h
@@ -58,6 +58,8 @@
# error Endian is unknown
#endif
+#define CODE_KILLER(X) (X)
+
#define A 10
#define B 11
#define C 12
@@ -81,3 +83,9 @@ HIDDEN void libblake_internal_blake2xb_init0(struct libblake_blake2xb_state *sta
HIDDEN void libblake_internal_blake2s_output_digest(struct libblake_blake2s_state *state, size_t output_len, unsigned char *output);
HIDDEN void libblake_internal_blake2b_output_digest(struct libblake_blake2b_state *state, size_t output_len, unsigned char *output);
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunreachable-code"
+# pragma clang diagnostic ignored "-Wvla"
+# pragma clang diagnostic ignored "-Wimplicit-fallthrough"
+#endif
diff --git a/libblake.h b/libblake.h
index 48c2ca1..65f31cf 100644
--- a/libblake.h
+++ b/libblake.h
@@ -5,6 +5,12 @@
#include <stddef.h>
#include <stdint.h>
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wpadded"
+# pragma clang diagnostic ignored "-Wvla"
+#endif
+
#ifndef LIBBLAKE_PUBLIC__
# if defined(_MSC_VER)
# define LIBBLAKE_PUBLIC__ __declspec(dllexport)
@@ -76,7 +82,6 @@ LIBBLAKE_PUBLIC__ void libblake_blake512_digest(struct libblake_blake512_state *
const char *suffix, unsigned char output[static LIBBLAKE_BLAKE512_OUTPUT_SIZE]);
LIBBLAKE_PUBLIC__ LIBBLAKE_PURE__ size_t libblake_blake512_digest_get_required_input_size(size_t len, size_t bits, const char *suffix);
-
struct libblake_blake2s_params {
uint_least8_t digest_len; /* in bytes, [1, 32] */
uint_least8_t key_len; /* in bytes, [0, 32] */
@@ -222,4 +227,8 @@ LIBBLAKE_PUBLIC__ void libblake_blake2xb_digest(const struct libblake_blake2xb_s
uint_least8_t len /* desired hash MIN(length - i * 64, 64) */,
unsigned char output[static len] /* output for hash offset by i * 64 */);
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
#endif
diff --git a/libblake_blake2b_init.c b/libblake_blake2b_init.c
index f07d1ef..cf5f35f 100644
--- a/libblake_blake2b_init.c
+++ b/libblake_blake2b_init.c
@@ -37,15 +37,22 @@ libblake_blake2b_init(struct libblake_blake2b_state *state, const struct libblak
state->f[0] = 0;
state->f[1] = 0;
- if (offsetof(struct libblake_blake2b_params, inner_len) == 17) {
- state->h[0] ^= le64(((uint_least64_t *)params)[0]);
- state->h[1] ^= le64(((uint_least64_t *)params)[1]);
+ if (CODE_KILLER(offsetof(struct libblake_blake2b_params, inner_len) == 17)) {
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wcast-align"
+#endif
+ state->h[0] ^= le64(((const uint_least64_t *)params)[0]);
+ state->h[1] ^= le64(((const uint_least64_t *)params)[1]);
state->h[2] ^= le64(((uint_least64_t)params->node_depth << 0) |
((uint_least64_t)params->inner_len << 8));
- state->h[4] ^= le64(*(uint_least64_t *)&params->salt[0]);
- state->h[5] ^= le64(*(uint_least64_t *)&params->salt[8]);
- state->h[6] ^= le64(*(uint_least64_t *)&params->pepper[0]);
- state->h[7] ^= le64(*(uint_least64_t *)&params->pepper[8]);
+ state->h[4] ^= le64(*(const uint_least64_t *)&params->salt[0]);
+ state->h[5] ^= le64(*(const uint_least64_t *)&params->salt[8]);
+ state->h[6] ^= le64(*(const uint_least64_t *)&params->pepper[0]);
+ state->h[7] ^= le64(*(const uint_least64_t *)&params->pepper[8]);
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
} else {
state->h[0] ^= ((uint_least64_t)params->digest_len & 255) << 0;
state->h[0] ^= ((uint_least64_t)params->key_len & 255) << 8;
diff --git a/libblake_blake2s_init.c b/libblake_blake2s_init.c
index fae7e0c..e9eacb8 100644
--- a/libblake_blake2s_init.c
+++ b/libblake_blake2s_init.c
@@ -33,17 +33,24 @@ libblake_blake2s_init(struct libblake_blake2s_state *state, const struct libblak
state->f[0] = 0;
state->f[1] = 0;
- if (offsetof(struct libblake_blake2s_params, inner_len) == 17) {
- state->h[0] ^= le32(((uint_least32_t *)params)[0]);
- state->h[1] ^= le32(((uint_least32_t *)params)[1]);
+ if (CODE_KILLER(offsetof(struct libblake_blake2s_params, inner_len) == 17)) {
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wcast-align"
+#endif
+ state->h[0] ^= le32(((const uint_least32_t *)params)[0]);
+ state->h[1] ^= le32(((const uint_least32_t *)params)[1]);
state->h[2] ^= le32((uint_least32_t)(params->node_offset >> 0));
- state->h[3] ^= le32(((uint_least32_t)(params->node_offset >> 32) & UINT_LEAST64_C(0xFFFF)) |
+ state->h[3] ^= le32(((uint_least32_t)(params->node_offset >> 32) & UINT_LEAST32_C(0xFFFF)) |
((uint_least32_t)params->node_depth << 16) |
((uint_least32_t)params->inner_len << 24));
- state->h[4] ^= le32(*(uint_least32_t *)&params->salt[0]);
- state->h[5] ^= le32(*(uint_least32_t *)&params->salt[4]);
- state->h[6] ^= le32(*(uint_least32_t *)&params->pepper[0]);
- state->h[7] ^= le32(*(uint_least32_t *)&params->pepper[4]);
+ state->h[4] ^= le32(*(const uint_least32_t *)&params->salt[0]);
+ state->h[5] ^= le32(*(const uint_least32_t *)&params->salt[4]);
+ state->h[6] ^= le32(*(const uint_least32_t *)&params->pepper[0]);
+ state->h[7] ^= le32(*(const uint_least32_t *)&params->pepper[4]);
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
} else {
state->h[0] ^= ((uint_least32_t)params->digest_len & 255) << 0;
state->h[0] ^= ((uint_least32_t)params->key_len & 255) << 8;
diff --git a/libblake_internal_blake2b_output_digest.c b/libblake_internal_blake2b_output_digest.c
index 8700c8c..110143f 100644
--- a/libblake_internal_blake2b_output_digest.c
+++ b/libblake_internal_blake2b_output_digest.c
@@ -50,7 +50,7 @@ libblake_internal_blake2b_output_digest(struct libblake_blake2b_state *state, si
size_t i, j;
#ifdef LITTLE_ENDIAN
- if ((uint_least64_t)(UINT_LEAST64_C(0xFFFFffffFFFFffff) + 1) == 0) {
+ if (CODE_KILLER((uint_least64_t)(UINT_LEAST64_C(0xFFFFffffFFFFffff) + 1) == 0)) {
/* 37.5x performance improvement;
* even though the compiler is smart enough to optimise
* `encode_uint64_le(&output[i], state->h[j], 8);` to a
diff --git a/libblake_internal_blake2s_output_digest.c b/libblake_internal_blake2s_output_digest.c
index 6b4a5da..7751c7f 100644
--- a/libblake_internal_blake2s_output_digest.c
+++ b/libblake_internal_blake2s_output_digest.c
@@ -38,7 +38,7 @@ libblake_internal_blake2s_output_digest(struct libblake_blake2s_state *state, si
size_t i, j;
#ifdef LITTLE_ENDIAN
- if ((uint_least32_t)(UINT_LEAST32_C(0xFFFFffff) + 1) == 0) {
+ if (CODE_KILLER((uint_least32_t)(UINT_LEAST32_C(0xFFFFffff) + 1) == 0)) {
/* No noticeable performance benefit on amd64, however
* it signficantly reduces the translation size and
* a 37.5x performance benefit was seen on the 64-bit
diff --git a/libblake_internal_blake2xb_init0.c b/libblake_internal_blake2xb_init0.c
index c045cec..7bfabc2 100644
--- a/libblake_internal_blake2xb_init0.c
+++ b/libblake_internal_blake2xb_init0.c
@@ -37,15 +37,22 @@ libblake_internal_blake2xb_init0(struct libblake_blake2xb_state *state, const st
state->b2b.f[0] = 0;
state->b2b.f[1] = 0;
- if (offsetof(struct libblake_blake2xb_params, inner_len) == 17) {
- state->b2b.h[0] ^= le64(((uint_least64_t *)params)[0]);
- state->b2b.h[1] ^= le64(((uint_least64_t *)params)[1]);
+ if (CODE_KILLER(offsetof(struct libblake_blake2xb_params, inner_len) == 17)) {
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wcast-align"
+#endif
+ state->b2b.h[0] ^= le64(((const uint_least64_t *)params)[0]);
+ state->b2b.h[1] ^= le64(((const uint_least64_t *)params)[1]);
state->b2b.h[2] ^= le64(((uint_least64_t)params->node_depth << 0) |
((uint_least64_t)params->inner_len << 8));
- state->b2b.h[4] ^= le64(*(uint_least64_t *)&params->salt[0]);
- state->b2b.h[5] ^= le64(*(uint_least64_t *)&params->salt[8]);
- state->b2b.h[6] ^= le64(*(uint_least64_t *)&params->pepper[0]);
- state->b2b.h[7] ^= le64(*(uint_least64_t *)&params->pepper[8]);
+ state->b2b.h[4] ^= le64(*(const uint_least64_t *)&params->salt[0]);
+ state->b2b.h[5] ^= le64(*(const uint_least64_t *)&params->salt[8]);
+ state->b2b.h[6] ^= le64(*(const uint_least64_t *)&params->pepper[0]);
+ state->b2b.h[7] ^= le64(*(const uint_least64_t *)&params->pepper[8]);
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
} else {
state->b2b.h[0] ^= ((uint_least64_t)params->digest_len & 255) << 0;
state->b2b.h[0] ^= ((uint_least64_t)params->key_len & 255) << 8;
diff --git a/libblake_internal_blake2xs_init0.c b/libblake_internal_blake2xs_init0.c
index f20bb9c..bde760f 100644
--- a/libblake_internal_blake2xs_init0.c
+++ b/libblake_internal_blake2xs_init0.c
@@ -33,15 +33,22 @@ libblake_internal_blake2xs_init0(struct libblake_blake2xs_state *state, const st
state->b2s.f[0] = 0;
state->b2s.f[1] = 0;
- if (sizeof(*params) == sizeof(state->b2s.h)) {
- state->b2s.h[0] ^= le32(((uint_least32_t *)params)[0]);
- state->b2s.h[1] ^= le32(((uint_least32_t *)params)[1]);
- state->b2s.h[2] ^= le32(((uint_least32_t *)params)[2]);
- state->b2s.h[3] ^= le32(((uint_least32_t *)params)[3]);
- state->b2s.h[4] ^= le32(((uint_least32_t *)params)[4]);
- state->b2s.h[5] ^= le32(((uint_least32_t *)params)[5]);
- state->b2s.h[6] ^= le32(((uint_least32_t *)params)[6]);
- state->b2s.h[7] ^= le32(((uint_least32_t *)params)[7]);
+ if (CODE_KILLER(sizeof(*params) == sizeof(state->b2s.h))) {
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wcast-align"
+#endif
+ state->b2s.h[0] ^= le32(((const uint_least32_t *)params)[0]);
+ state->b2s.h[1] ^= le32(((const uint_least32_t *)params)[1]);
+ state->b2s.h[2] ^= le32(((const uint_least32_t *)params)[2]);
+ state->b2s.h[3] ^= le32(((const uint_least32_t *)params)[3]);
+ state->b2s.h[4] ^= le32(((const uint_least32_t *)params)[4]);
+ state->b2s.h[5] ^= le32(((const uint_least32_t *)params)[5]);
+ state->b2s.h[6] ^= le32(((const uint_least32_t *)params)[6]);
+ state->b2s.h[7] ^= le32(((const uint_least32_t *)params)[7]);
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
} else {
state->b2s.h[0] ^= ((uint_least32_t)params->digest_len & 255) << 0;
state->b2s.h[0] ^= ((uint_least32_t)params->key_len & 255) << 8;
diff --git a/test.c b/test.c
index 4a38423..6205d4e 100644
--- a/test.c
+++ b/test.c
@@ -129,7 +129,7 @@ check_blake1(void)
"a701c2a1f9baabd8b1db6b75aee096900276f0b86dc15d247ecc03937b370324a16a4ffc0c3a85cd63229cfa15c15f4ba6d46ae2e849ed6335e9ff43b764198a");
bits = 1;
-#define X(INPUT, EXPECT) CHECK_BLAKE224_BITS(INPUT, bits++, EXPECT);
+#define X(INPUT, EXPECT) CHECK_BLAKE224_BITS(INPUT, bits++, EXPECT)
X("00", "615b9bd1077a8270d4f647799ffaaf87c03d72efd37e4947fcf01cca");
X("C0", "6a829dca3a3d0d35762d7b0f9a2c8379c32415c87a8ad773fefec19f");
X("C0", "5478a106aca2b539d5bd52db8b19717d436ca27c14ef99ed565bc4a7");
@@ -182,7 +182,7 @@ check_blake1(void)
#undef X
bits = 1;
-#define X(INPUT, EXPECT) CHECK_BLAKE256_BITS(INPUT, bits++, EXPECT);
+#define X(INPUT, EXPECT) CHECK_BLAKE256_BITS(INPUT, bits++, EXPECT)
X("00", "81a10984912cd57c12e923b46142b2b434dfe1a0ef29c03de05555f9f2fee9b4");
X("C0", "eae1614ea36088a8fd69a4614c2d98fada81134baa991aebfb743cd297669b01");
X("C0", "4ac92b8903f7076563a6309eb9bd386807d28fe721fc8128af86e88967739443");
@@ -235,7 +235,7 @@ check_blake1(void)
#undef X
bits = 1;
-#define X(INPUT, EXPECT) CHECK_BLAKE384_BITS(INPUT, bits++, EXPECT);
+#define X(INPUT, EXPECT) CHECK_BLAKE384_BITS(INPUT, bits++, EXPECT)
X("00", "1ffde9711b419d7c97dc142e7704d2ae61163f8a818c47938b978d6113949d8e7819b9699d497a3b289b8bb4415ffae7");
X("C0", "195d771c302bb1ca0c9ac55a782cbe877bc0bc28016f735de68d7cf5fc1d0a99cc69a32cb0174fd2a97d5fcf46aafded");
X("C0", "883b186d9372a04d585eb1eef1cd32ff8a7c061d5e396f05fd9d3d9d6033de757bfc3adf30b06d7fb02a875a2ac0db70");
@@ -288,7 +288,7 @@ check_blake1(void)
#undef X
bits = 1;
-#define X(INPUT, EXPECT) CHECK_BLAKE512_BITS(INPUT, bits++, EXPECT);
+#define X(INPUT, EXPECT) CHECK_BLAKE512_BITS(INPUT, bits++, EXPECT)
X("00", "f0a9b5b755802205fd1a1f56e7a03d7573d46e8ba5037517281560fbe6db03c174b00597fb4e1427747c7382fe63c6692f05a5e0841e99883cb7c272c2a62191");
X("C0", "777e21c87839badde651fc37334f6d7cdc8316914e7cb76dab2efab90c62ef307e590936349b85041542f00d94d870633957699e818db79e1e064b0991a9cd1a");
X("C0", "1ffb9a5c5c4c5a0cb91d806fc1398e8a49bdac2cfb549628c886bf388f5a6c6b0854bc9c68155502016592c3f0cd54ded83276463a2aed864436950d99244958");