process unaligned data through a trampoline buffer when architecture needs it

should fix #108
This commit is contained in:
Vincent Hanquez 2016-12-09 15:04:02 +00:00
parent 12a26c14c4
commit ba10930add

View File

@ -25,6 +25,7 @@
#include <stdint.h>
#include <string.h>
#include "cryptonite_bitfn.h"
#include "cryptonite_align.h"
#include "cryptonite_sha3.h"
#define KECCAK_NB_ROUNDS 24
@ -124,9 +125,19 @@ void cryptonite_sha3_update(struct sha3_ctx *ctx, const uint8_t *data, uint32_t
ctx->bufindex = 0;
}
if (need_alignment(data, 8)) {
uint64_t tramp[200 - 2 * (224 / 8)];
ASSERT_ALIGNMENT(tramp, 8);
for (; len >= ctx->bufsz; len -= ctx->bufsz, data += ctx->bufsz) {
memcpy(tramp, data, ctx->bufsz / 8);
sha3_do_chunk(ctx->state, (uint64_t *) data, ctx->bufsz / 8);
}
} else {
/* process as much ctx->bufsz-block */
for (; len >= ctx->bufsz; len -= ctx->bufsz, data += ctx->bufsz)
sha3_do_chunk(ctx->state, (uint64_t *) data, ctx->bufsz / 8);
}
/* append data into buf */
if (len) {