tfstream: add separate xor_block function
[tfcrypt.git] / tfstream.c
1 #include <string.h>
2 #include "tfdef.h"
3 #include "tfe.h"
4
5 static inline void xor_block(void *dst, const void *src, size_t sz)
6 {
7         const size_t *sx = (const size_t *)src;
8         const TF_BYTE_TYPE *usx = (const TF_BYTE_TYPE *)src;
9         size_t *dx = (size_t *)dst;
10         TF_BYTE_TYPE *udx = (TF_BYTE_TYPE *)dst;
11         size_t sl = sz;
12
13         for (sl = 0; sl < (sz / sizeof(size_t)); sl++) dx[sl] ^= sx[sl];
14         if (sz - (sl * sizeof(size_t))) for (sl *= sizeof(size_t); sl < sz; sl++) udx[sl] ^= usx[sl];
15 }
16
17 void tf_stream_crypt(struct tfe_stream *tfe, void *out, const void *in, size_t sz)
18 {
19         tfe_emit(out, sz, tfe);
20         xor_block(out, in, sz);
21 }