-
Notifications
You must be signed in to change notification settings - Fork 14
/
transform.h
45 lines (36 loc) · 1.88 KB
/
transform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef _incl_TRANSFORM_H
#define _incl_TRANSFORM_H
#include <stdint.h>
#include <stdlib.h>
#define MASK_UNIT uint32_t
#define MASK_LEN ((int) sizeof(MASK_UNIT))
#define MASK_MAXCT ((unsigned int) 100000)
struct um_transform {
unsigned char mask[MASK_LEN];
unsigned int mask_ct;
};
#define transform(buf, buflen, m) \
do { \
size_t c = buflen / MASK_LEN; \
for (size_t i = 0; i < c; i++) { \
((MASK_UNIT *) buf)[i] ^= *((MASK_UNIT *) m); \
} \
for (size_t i = c * MASK_LEN; i < buflen; i++) { \
buf[i] ^= m[i % MASK_LEN]; \
} \
} while (0) \
#define genmask(mask, n) \
do { \
for (size_t i = 0; i < n; i++) { \
for (int j = 0; j < 10; j++) { \
mask[i] = (unsigned char) (rand() % 256); \
if (mask[i] != 0) break; \
} \
} \
} while (0) \
void check_gen_mask(struct um_transform *);
size_t maskbuf(struct um_transform *, unsigned char *, size_t);
size_t unmaskbuf(struct um_transform *, unsigned char *, size_t);
size_t masknoop(struct um_transform *, unsigned char *, size_t);
typedef size_t (*buf_func)(struct um_transform *, unsigned char *, size_t);
#endif /* _incl_TRANSFORM_H */