fix mhexdump machine detection.
[tfcrypt.git] / tfstream.c
1 #include <string.h>
2 #include "tfdef.h"
3 #include "tfe.h"
4
5 void tf_stream_crypt(struct tfe_stream *tfe, void *out, const void *in, size_t sz)
6 {
7         const TF_UNIT_TYPE *uin = in;
8         TF_UNIT_TYPE *uout = out;
9         const TF_BYTE_TYPE *uuin = in;
10         TF_BYTE_TYPE *uuout = out;
11         size_t n, z, x;
12
13         switch (TF_SIZE_UNIT) {
14                 case 2: n = 1; break;
15                 case 4: n = 2; break;
16                 case 8: n = 3; break;
17         }
18
19         tfe_emit(out, sz, tfe);
20         for (z = 0; z < (sz >> n); z++) uout[z] ^= uin[z];
21         if (sz - (z << n)) for (x = (z << n); x < sz; x++) uuout[x] ^= uuin[x];
22 }