aboutsummaryrefslogtreecommitdiffstats

xchapolybox

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

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));