aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile3
-rw-r--r--src/libkeccak/generalised-spec.c39
2 files changed, 28 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 289bb47..9d2aa61 100644
--- a/Makefile
+++ b/Makefile
@@ -21,8 +21,9 @@ WARN = -Wall -Wextra -pedantic -Wdouble-promotion -Wformat=2 -Winit-self -Wmissi
-Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-attribute=format \
-Wnormalized=nfkc
-FLAGS = -std=gnu99 $(WARN)
+OPTIMISE = -O3
+FLAGS = -std=gnu99 $(WARN) $(OPTIMISE)
# TODO optimisation flags to test, and naturally -ON
# -faggressive-loop-optimizations -falign-functions[=N]
diff --git a/src/libkeccak/generalised-spec.c b/src/libkeccak/generalised-spec.c
index 7bab1fc..aecf0fd 100644
--- a/src/libkeccak/generalised-spec.c
+++ b/src/libkeccak/generalised-spec.c
@@ -21,7 +21,7 @@
#define have(v) (spec->v != LIBKECCAK_GENERALISED_SPEC_AUTOMATIC)
#define copy(v) (v = spec->v)
-#define deft(v, dv) (have(v) ? v : (dv))
+#define deft(v, dv) (have_##v ? v : (dv))
/**
@@ -37,9 +37,18 @@
int libkeccak_degeneralise_spec(libkeccak_generalised_spec_t* restrict spec,
libkeccak_spec_t* restrict output_spec)
{
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+
long state_size, word_size, capacity, bitrate, output;
+ const int have_state_size = have(state_size);
+ const int have_word_size = have(word_size);
+ const int have_capacity = have(capacity);
+ const int have_bitrate = have(bitrate);
+ const int have_output = have(output);
+
- if (have(state_size))
+ if (have_state_size)
{
copy(state_size);
if (state_size <= 0) return LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_NONPOSITIVE;
@@ -47,39 +56,39 @@ int libkeccak_degeneralise_spec(libkeccak_generalised_spec_t* restrict spec,
if (state_size % 25) return LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_MOD_25;
}
- if (have(word_size))
+ if (have_word_size)
{
copy(word_size);
if (word_size <= 0) return LIBKECCAK_GENERALISED_SPEC_ERROR_WORD_NONPOSITIVE;
if (word_size > 64) return LIBKECCAK_GENERALISED_SPEC_ERROR_WORD_TOO_LARGE;
- if (have(state_size) && (state_size != word_size * 25))
+ if (have_state_size && (state_size != word_size * 25))
return LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_WORD_INCOHERENCY;
- else if (!have(state_size))
+ else if (!have_state_size)
spec->state_size = 1, state_size = word_size * 25;
}
- if (have(capacity))
+ if (have_capacity)
{
copy(capacity);
if (capacity <= 0) return LIBKECCAK_GENERALISED_SPEC_ERROR_CAPACITY_NONPOSITIVE;
if (capacity & 7) return LIBKECCAK_GENERALISED_SPEC_ERROR_CAPACITY_MOD_8;
}
- if (have(bitrate))
+ if (have_bitrate)
{
copy(bitrate);
if (bitrate <= 0) return LIBKECCAK_GENERALISED_SPEC_ERROR_BITRATE_NONPOSITIVE;
if (bitrate & 7) return LIBKECCAK_GENERALISED_SPEC_ERROR_BITRATE_MOD_8;
}
- if (have(output))
+ if (have_output)
{
copy(output);
if (output <= 0) return LIBKECCAK_GENERALISED_SPEC_ERROR_OUTPUT_NONPOSITIVE;
}
- if (!have(bitrate) && !have(capacity) && !have(output)) /* state_size? */
+ if (!have_bitrate && !have_capacity && !have_output)
{
state_size = deft(state_size, 1600L);
output = ((state_size << 5) / 100L + 7L) & ~0x07L;
@@ -87,36 +96,40 @@ int libkeccak_degeneralise_spec(libkeccak_generalised_spec_t* restrict spec,
capacity = state_size - bitrate;
output = output >= 8 ? output : 8;
}
- else if (!have(bitrate) && !have(capacity)) /* have(output) state_size? */
+ else if (!have_bitrate && !have_capacity)
{
bitrate = 1024;
capacity = 1600 - 1024;
state_size = deft(state_size, bitrate + capacity);
}
- else if (!have(bitrate)) /* have(capacity) output? state_size? */
+ else if (!have_bitrate)
{
state_size = deft(state_size, 1600L);
bitrate = state_size - capacity;
output = deft(output, capacity == 8 ? 8 : (capacity << 1));
}
- else if (!have(capacity)) /* have(bitrate) output? state_size? */
+ else if (!have_capacity)
{
state_size = deft(state_size, 1600L);
capacity = state_size - bitrate;
output = deft(output, capacity == 8 ? 8 : (capacity << 1));
}
- else /* have(bitrate) have(capacity) output? state_size? */
+ else
{
state_size = deft(state_size, bitrate + capacity);
output = deft(output, capacity == 8 ? 8 : (capacity << 1));
}
+
spec->capacity = output_spec->capacity = capacity;
spec->bitrate = output_spec->bitrate = bitrate;
spec->output = output_spec->output = output;
spec->state_size = state_size;
spec->word_size = state_size / 25;
+
return 0;
+
+# pragma GCC diagnostic pop
}