aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-11-05 22:23:35 +0100
committerMattias Andrée <maandree@operamail.com>2014-11-05 22:23:35 +0100
commit132e61300cc9005fbbcc4779eef5db2bae347698 (patch)
tree7074f72b79e3881dfe470e039ac043a366698ab7
parenttest.c does not need its own directory (diff)
downloadlibkeccak-132e61300cc9005fbbcc4779eef5db2bae347698.tar.gz
libkeccak-132e61300cc9005fbbcc4779eef5db2bae347698.tar.bz2
libkeccak-132e61300cc9005fbbcc4779eef5db2bae347698.tar.xz
m improvement: make msg in libkeccak_digest const
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/libkeccak/digest.c10
-rw-r--r--src/libkeccak/digest.h2
2 files changed, 5 insertions, 7 deletions
diff --git a/src/libkeccak/digest.c b/src/libkeccak/digest.c
index fec92f9..640f7b9 100644
--- a/src/libkeccak/digest.c
+++ b/src/libkeccak/digest.c
@@ -392,14 +392,13 @@ int libkeccak_update(libkeccak_state_t* restrict state, const char* restrict msg
* @param hashsum Output paramter for the hashsum, may be `NULL`
* @return Zero on success, -1 on error
*/
-int libkeccak_digest(libkeccak_state_t* restrict state, char* restrict msg, size_t msglen,
+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)
{
long rr = state->r >> 3, i;
long ww = state->w >> 3;
long nn = (state->n + 7) >> 3;
size_t ext, suffix_len = suffix ? __builtin_strlen(suffix) : 0;
- const char* restrict message = msg;
char* restrict new;
if (msg == NULL)
@@ -407,8 +406,7 @@ int libkeccak_digest(libkeccak_state_t* restrict state, char* restrict msg, size
else
{
msglen += bits >> 3;
- if ((bits &= 7))
- msg[msglen] &= (char)((1 << bits) - 1);
+ bits &= 7;
}
ext = msglen + ((bits + suffix_len + 7) >> 3) + (size_t)rr;
@@ -422,11 +420,11 @@ int libkeccak_digest(libkeccak_state_t* restrict state, char* restrict msg, size
}
if (msglen)
- __builtin_memcpy(state->M + state->mptr, message, msglen * sizeof(char));
+ __builtin_memcpy(state->M + state->mptr, msg, msglen * sizeof(char));
state->mptr += msglen;
if (bits)
- state->M[state->mptr] = message[msglen];
+ state->M[state->mptr] = msg[msglen] & (char)((1 << bits) - 1);
if (__builtin_expect(!!suffix_len, 1))
{
if (bits == 0)
diff --git a/src/libkeccak/digest.h b/src/libkeccak/digest.h
index 23ca12b..792389c 100644
--- a/src/libkeccak/digest.h
+++ b/src/libkeccak/digest.h
@@ -47,7 +47,7 @@ int libkeccak_update(libkeccak_state_t* restrict state, const char* restrict msg
* @return Zero on success, -1 on error
*/
__attribute__((nonnull(1)))
-int libkeccak_digest(libkeccak_state_t* restrict state, char* restrict msg, size_t msglen,
+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);