Skip to content

Instantly share code, notes, and snippets.

@kazuho
Created May 6, 2020 07:40
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 kazuho/02c0d512ea9e10c6f45e0d0fad5de091 to your computer and use it in GitHub Desktop.
Save kazuho/02c0d512ea9e10c6f45e0d0fad5de091 to your computer and use it in GitHub Desktop.
int main(int argc, char **argv)
{
static const uint8_t key[16] = {}, iv[12] = {}, aad[13] = {}, text[16384] = {};
ptls_fusion_aesgcm_context_t ctx;
uint8_t encrypted[sizeof(text) + 16];
size_t textlen = 16384;
// 以下のifを追加すると0.7秒遅くなる
if (sscanf(argv[1], "%zu", &textlen) != 1) {
fprintf(stderr, "failed to obtain text length from argument\n");
return 1;
}
ptls_fusion_aesgcm_init(&ctx, key);
for (int i = 0; i < 1000000; ++i)
ptls_fusion_aesgcm_encrypt(&ctx, iv, aad, sizeof(aad), encrypted, text, textlen);
// このprintfにはバグがあり、sizeof(text)をtextlenに変えると、上掲の速度低下はなくなる
for (int i = 0; i < 16; ++i)
printf("%02x", encrypted[sizeof(text) + i]);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment