-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuf.cl
58 lines (48 loc) · 1.31 KB
/
buf.cl
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
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2012 Alex Reece
#include "common.h"
#define make_buf_append(address_space) \
void buf_append_##address_space(buffer_t* buf, \
address_space const char* data, uint len) { \
uint i; \
for (i = 0; i < len; i++) { \
buf->buffer[buf->size + i] = data[i]; \
} \
buf->size = buf->size + len; \
}
make_buf_append(private)
make_buf_append(constant)
void buf_init(buffer_t* buf, const char* data, uint len) {
uint i;
for (i = 0; i < len; i++) {
buf->buffer[i] = data[i];
}
buf->size = len;
}
void md5_buffer(const buffer_t* in, buffer_t* out) {
md5(in->buffer, in->size, (uint*) out->buffer);
out->size = 16;
}
void rc4_crypt_buffer(const buffer_t* key, const buffer_t* in, buffer_t* out) {
rc4_state_t state;
rc4_init(&state, key->buffer, key->size);
rc4_crypt(&state, in->buffer, out->buffer, in->size);
out->size = in->size;
}
void buf_xorall(buffer_t* buf, uchar byte) {
uint i;
for (i = 0; i < buf->size; i++) {
buf->buffer[i] = (char)(((uchar)buf->buffer[i]) ^ byte);
}
}
int buf_eq(const buffer_t* a, const buffer_t* b) {
if (a->size != b->size) {
return 1;
}
uint i;
for (i = 0; i < a->size; i++) {
if (a->buffer[i] != b->buffer[i]) {
return 1;
}
}
return 0;
}