Skip to content

Instantly share code, notes, and snippets.

@jedisct1
Created June 12, 2023 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedisct1/9e8699435975bf18017eaa0e6fe97d3d to your computer and use it in GitHub Desktop.
Save jedisct1/9e8699435975bf18017eaa0e6fe97d3d to your computer and use it in GitHub Desktop.
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "src/aegis128l/aegis128l.h"
static void
dump(const uint8_t *x, size_t len)
{
for (size_t i = 0; i < len; i++) {
printf("%02x", x[i]);
}
printf("\n");
}
int
main(int argc, char *argv[])
{
if (aegis_init() != 0) {
return 254;
}
#define MACLEN 16
uint8_t m[1000] = { 0 };
uint8_t c[1000 + MACLEN] = { 0 };
uint8_t k[16] = { 0 };
uint8_t npub[16] = { 0 };
int ret;
aegis128l_encrypt(c, MACLEN, m, sizeof m, NULL, 0, npub, k);
ret = aegis128l_decrypt(m, c, sizeof c, MACLEN, NULL, 0, npub, k);
aegis128l_state st;
size_t pos = 0;
size_t written;
memset(c, 0, sizeof c);
aegis128l_state_init(&st, NULL, 0, npub, k);
aegis128l_state_encrypt_update(&st, c, (sizeof c) - MACLEN, &written, m, 500);
pos += written;
printf("written: %zu\n", written);
aegis128l_state_encrypt_update(&st, c + pos, (sizeof c) - MACLEN - pos, &written, m + 500,
(sizeof m) - 500);
pos += written;
aegis128l_state_encrypt_detached_final(&st, c + pos, (sizeof c) - MACLEN - pos, &written,
c + (sizeof m), MACLEN);
dump(c, sizeof c);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment