diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-11-07 01:03:44 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-11-07 01:03:44 +0100 |
commit | 5480da2067f6fc8059824006041c848ed497163e (patch) | |
tree | da5b3e6b71fa9b14870d80e86388f1b87ec994b6 /src | |
parent | m (diff) | |
download | libkeccak-5480da2067f6fc8059824006041c848ed497163e.tar.gz libkeccak-5480da2067f6fc8059824006041c848ed497163e.tar.bz2 libkeccak-5480da2067f6fc8059824006041c848ed497163e.tar.xz |
more optimisation
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/libkeccak/digest.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/libkeccak/digest.c b/src/libkeccak/digest.c index c2a7d6f..3eda69a 100644 --- a/src/libkeccak/digest.c +++ b/src/libkeccak/digest.c @@ -408,14 +408,11 @@ int libkeccak_update(libkeccak_state_t* restrict state, const char* restrict msg int libkeccak_digest(libkeccak_state_t* restrict state, const char* restrict msg, size_t msglen, size_t bits, const char* restrict suffix, char* restrict hashsum) { - /* TODO optimise function */ - char* restrict new; - long rr = state->r >> 3; - long ww = state->w >> 3; - long nn = (state->n + 7) >> 3; - size_t suffix_len = suffix ? __builtin_strlen(suffix) : 0; - size_t ext; - long i; + auto char* restrict new; + register long rr = state->r >> 3; + auto size_t suffix_len = suffix ? __builtin_strlen(suffix) : 0; + register size_t ext; + register long i; if (msg == NULL) msglen = bits = 0; @@ -423,7 +420,7 @@ int libkeccak_digest(libkeccak_state_t* restrict state, const char* restrict msg msglen += bits >> 3, bits &= 7; ext = msglen + ((bits + suffix_len + 7) >> 3) + (size_t)rr; - if (state->mptr + ext > state->mlen) + if (__builtin_expect(state->mptr + ext > state->mlen, 0)) { state->mlen += ext; new = realloc(state->M, state->mlen * sizeof(char)); /* FIXME insecure */ @@ -456,7 +453,7 @@ int libkeccak_digest(libkeccak_state_t* restrict state, const char* restrict msg libkeccak_absorption_phase(state, state->mptr); if (hashsum != NULL) - libkeccak_squeezing_phase(state, rr, nn, ww, hashsum); + libkeccak_squeezing_phase(state, rr, (state->n + 7) >> 3, state->w >> 3, hashsum); else for (i = (state->n - 1) / state->r; i--;) libkeccak_f(state); |