/* main-gcm-test.c */
/*
This file is part of the AVR-Crypto-Lib.
- Copyright (C) 2006-2014 Daniel Otte (daniel.otte@rub.de)
+ Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "main-test-common.h"
#include <gcm128.h>
-#include <bcal_aes128.h>
-#include <bcal_aes192.h>
-#include <bcal_aes256.h>
+#include <bcal_aes128_enconly.h>
+#include <bcal_aes192_enconly.h>
+#include <bcal_aes256_enconly.h>
#include "performance_test.h"
char *algo_name = "GCM-AES128";
void *tag,
uint8_t tag_length_b)
{
+ uint8_t dec_tag[16];
int8_t r;
- gcm128_ctx_t ctx;
+ gcm128_ctx_t ctx, dec_ctx;
const bcdesc_t *cipher;
switch (key_length_b) {
case 128: cipher = &aes128_desc; break;
uart0_flush();
return -1;
}
+ if ((r = gcm128_init(&dec_ctx, cipher, key, key_length_b, iv, iv_length_b))) {
+ printf_P(PSTR("DBG: (Oooops) Error: %"PRId8"\n"), r);
+ uart0_flush();
+ return -1;
+ }
}
uint8_t tmp[GCM128_BLOCK_BYTES];
ad_p = &((uint8_t*)ad_p)[GCM128_BLOCK_BYTES];
ad_length_b -= GCM128_BLOCK_BITS;
gcm128_add_ad_block(&ctx, tmp);
+ gcm128_add_ad_block(&dec_ctx, tmp);
}
memcpy_P(tmp, ad_p, (ad_length_b + 7) / 8);
gcm128_add_ad_final_block(&ctx, tmp, ad_length_b);
+ gcm128_add_ad_final_block(&dec_ctx, tmp, ad_length_b);
while (src_length_b >= GCM128_BLOCK_BITS) {
memcpy_P(tmp, src_p, GCM128_BLOCK_BYTES);
- src_p = &((uint8_t*)src_p)[GCM128_BLOCK_BYTES];
src_length_b -= GCM128_BLOCK_BITS;
gcm128_encrypt_block(&ctx, tmp, tmp);
+ gcm128_decrypt_block(&dec_ctx, tmp, tmp);
+ if (memcmp_P(tmp, src_p, GCM128_BLOCK_BYTES)) {
+ printf("DBG: Error: decryption error");
+ DUMP(tmp);
+ }
// DUMP(tmp);
+ src_p = &((uint8_t*)src_p)[GCM128_BLOCK_BYTES];
}
memcpy_P(tmp, src_p, (src_length_b + 7) / 8);
gcm128_encrypt_final_block(&ctx, tmp, tmp, src_length_b);
+ gcm128_decrypt_final_block(&dec_ctx, tmp, tmp, src_length_b);
if (src_length_b > 0) {
// DUMP_LEN(tmp, (src_length_b + 7) / 8);
+ if (memcmp_P(tmp, src_p, (src_length_b + 7) / 8)) {
+ printf("DBG: Error: decryption error");
+ DUMP_LEN(tmp, (src_length_b + 7) / 8);
+ }
}
-
+ gcm128_finalize(&dec_ctx, dec_tag, tag_length_b);
gcm128_finalize(&ctx, tag, tag_length_b);
+ if (memcmp(tag, dec_tag, (tag_length_b + 7) / 8)) {
+ printf("DBG: Error: tag error");
+ DUMP_LEN(tag, (tag_length_b + 7) / 8);
+ DUMP_LEN(dec_tag, (tag_length_b + 7) / 8);
+ }
return 0;
}