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
|
## [xchapolybox](https://git.zx2c4.com/xchapolybox/about/)
by Jason A. Donenfeld
_Warning: you probably shouldn't use this. It hasn't actually ever been used._
This is a very simple "crypto box", meant for being included as a single C file inside your project. It presents an extremely simple API:
### Constants
- `XCHAPOLYBOX_OVERHEAD_LEN`
- `XCHAPOLYBOX_KEY_LEN`
### Functions
- `void xchapolybox_seal(uint8_t *dst, const uint8_t *src, size_t src_len, const uint8_t key[XCHAPOLYBOX_KEY_LEN]);`
- `bool xchapolybox_open(uint8_t *dst, const uint8_t *src, size_t src_len, const uint8_t key[XCHAPOLYBOX_KEY_LEN]);`
- `void xchapolybox_genkey(uint8_t key[XCHAPOLYBOX_KEY_LEN]);`
### Example
```c
uint8_t key[XCHAPOLYBOX_KEY_LEN];
uint8_t *output, *input, *input2;
size_t input_len, output_len;
xchapolybox_genkey(key);
input = get_input_from_somewhere(&input_len);
assert(input);
output_len = input_len + XCHAPOLYBOX_OVERHEAD_LEN;
output = malloc(output_len);
assert(output);
xchapolybox_seal(output, input, input_len, key);
input2 = malloc(input_len);
assert(input2);
if (!xchapolybox_open(input2, output, output_len, key)) {
// Always remember to check the auth tag.
return -1;
}
assert(!memcmp(input, input2, input_len));
```
|