aboutsummaryrefslogtreecommitdiffstats
path: root/digest.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-02-09 21:30:06 +0100
committerMattias Andrée <maandree@kth.se>2019-02-09 21:30:06 +0100
commitae42e15f211feb8625450e5dcc899ae29d885ba7 (patch)
treebddb7469da7d1f32502df31e0d7c0d57aee66fde /digest.c
parentImprove makefile: mv LIBEXT and LIBFLAGS to config.mk (diff)
downloadlibsha2-ae42e15f211feb8625450e5dcc899ae29d885ba7.tar.gz
libsha2-ae42e15f211feb8625450e5dcc899ae29d885ba7.tar.bz2
libsha2-ae42e15f211feb8625450e5dcc899ae29d885ba7.tar.xz
Fix warnings
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--digest.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/digest.c b/digest.c
index 8658388..bcd318f 100644
--- a/digest.c
+++ b/digest.c
@@ -16,10 +16,10 @@ libsha2_digest(struct libsha2_state *restrict state, const char *restrict messag
char *appendix;
size_t i, j, k, n;
- if (msglen & ~7) {
- libsha2_update(state, message, msglen & ~7);
- message += msglen & ~7;
- msglen &= 7;
+ if (msglen & ~(size_t)7) {
+ libsha2_update(state, message, msglen & ~(size_t)7);
+ message += msglen & ~(size_t)7;
+ msglen &= (size_t)7;
}
k = 8 * state->chunk_size;
@@ -31,36 +31,31 @@ libsha2_digest(struct libsha2_state *restrict state, const char *restrict messag
if (msglen) {
j = 7 - msglen;
*appendix = *message;
- *appendix |= 1 << j;
- *appendix &= ~((1 << j) - 1);
+ *appendix |= (char)(1 << j);
+ *appendix &= (char)~((1 << j) - 1);
} else {
- *appendix = (unsigned char)128;
+ *appendix = (char)128;
}
k = state->message_size + msglen;
i = state->chunk_size / 8;
appendix += n + i - 1;
for (i = i < sizeof(size_t) ? i : sizeof(size_t); i--;)
- *(appendix - i) = (unsigned char)((k >> (i * 8)) & 255);
+ *(appendix - i) = (char)((k >> (i * 8)) & 255);
n += state->chunk_size;
libsha2_update(state, state->appendix, n);
n = libsha2_algorithm_output_size(state->algorithm);
- switch (state->algorithm) {
- case LIBSHA2_224:
- case LIBSHA2_256:
+ if (state->algorithm <= LIBSHA2_256) {
for (i = 0; i < 8; i++)
for (j = 0; j < (state->chunk_size / 16); j++)
if (k = (i + 1) * (state->chunk_size / 16) - j - 1, k < n)
output[k] = (char)((state->h.b32[i] >> (8 * j)) & 255);
- break;
-
- default:
+ } else {
for (i = 0; i < 8; i++)
for (j = 0; j < (state->chunk_size / 16); j++)
if (k = (i + 1) * (state->chunk_size / 16) - j - 1, k < n)
output[k] = (char)((state->h.b64[i] >> (8 * j)) & 255);
- break;
}
}