From: Andrey Rys Date: Sat, 15 Jan 2022 15:22:11 +0000 (+0100) Subject: tfstream: add separate xor_block function X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=e3b1cafef772fa27575cedeb98a9e241ac6ecc8f;p=tfcrypt.git tfstream: add separate xor_block function --- diff --git a/VERSION b/VERSION index b1e7d26..a8fa06e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -61 +62 diff --git a/tfstream.c b/tfstream.c index b64d4d9..014b5c1 100644 --- a/tfstream.c +++ b/tfstream.c @@ -2,21 +2,20 @@ #include "tfdef.h" #include "tfe.h" -void tf_stream_crypt(struct tfe_stream *tfe, void *out, const void *in, size_t sz) +static inline void xor_block(void *dst, const void *src, size_t sz) { - const TF_UNIT_TYPE *uin = in; - TF_UNIT_TYPE *uout = out; - const TF_BYTE_TYPE *uuin = in; - TF_BYTE_TYPE *uuout = out; - size_t n, z, x; + const size_t *sx = (const size_t *)src; + const TF_BYTE_TYPE *usx = (const TF_BYTE_TYPE *)src; + size_t *dx = (size_t *)dst; + TF_BYTE_TYPE *udx = (TF_BYTE_TYPE *)dst; + size_t sl = sz; - switch (TF_SIZE_UNIT) { - case 2: n = 1; break; - case 4: n = 2; break; - case 8: n = 3; break; - } + for (sl = 0; sl < (sz / sizeof(size_t)); sl++) dx[sl] ^= sx[sl]; + if (sz - (sl * sizeof(size_t))) for (sl *= sizeof(size_t); sl < sz; sl++) udx[sl] ^= usx[sl]; +} +void tf_stream_crypt(struct tfe_stream *tfe, void *out, const void *in, size_t sz) +{ tfe_emit(out, sz, tfe); - for (z = 0; z < (sz >> n); z++) uout[z] ^= uin[z]; - if (sz - (z << n)) for (x = (z << n); x < sz; x++) uuout[x] ^= uuin[x]; + xor_block(out, in, sz); }