X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=gcm%2Fgcm128.h;fp=gcm%2Fgcm128.h;h=755b75ac76f843bda3a027c8ee1a9d2f26487328;hp=0000000000000000000000000000000000000000;hb=e542ff92d053ecf40b42364a44bc887431cecae2;hpb=deca11a7e7be5605c387aa2cd577e22925854ff8 diff --git a/gcm/gcm128.h b/gcm/gcm128.h new file mode 100644 index 0000000..755b75a --- /dev/null +++ b/gcm/gcm128.h @@ -0,0 +1,116 @@ +/* gcm128.h */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2015 Daniel Otte (daniel.otte@rub.de) + + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GCM_GCM128_H_ +#define GCM_GCM128_H_ + + +/* gcm128.c */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2006-2015 Daniel Otte (daniel.otte@rub.de) + + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include +#include +#include +#include + +#define GCM128_BLOCK_BYTES 16 +#define GCM128_BLOCK_BITS (GCM128_BLOCK_BYTES * 8) + +#define GCM128_COUNT_BYTES 4 +#define GCM128_COUNT_BITS (GCM128_COUNT_BYTES * 8) + + + +typedef struct { + uint8_t tag[GCM128_BLOCK_BYTES]; + uint8_t key[GCM128_BLOCK_BYTES]; +} ghash128_ctx_t; + +typedef struct { + ghash128_ctx_t ghash_ctx; + bcgen_ctx_t cipher_ctx; + uint8_t ctr[GCM128_BLOCK_BYTES]; + uint8_t j0[GCM128_COUNT_BYTES]; + uint32_t length_a; + uint32_t length_c; +} gcm128_ctx_t; + +int8_t gcm128_init( + gcm128_ctx_t *ctx, + const bcdesc_t *cipher, + const void *key, + uint16_t key_length_b, + const void *iv, + uint16_t iv_length_b); + +void gcm128_add_ad_block( + gcm128_ctx_t *ctx, + const void *block ); + +void gcm128_add_ad_final_block( + gcm128_ctx_t *ctx, + const void *block, + uint16_t length_b ); + +void gcm128_encrypt_block( + gcm128_ctx_t *ctx, + void *dest, + const void *src); + +void gcm128_encrypt_final_block( + gcm128_ctx_t *ctx, + void *dest, + const void *src, + uint16_t length_b); + +void gcm128_decrypt_block( + gcm128_ctx_t *ctx, + void *dest, + const void *src); + +void gcm128_decrypt_final_block( + gcm128_ctx_t *ctx, + void *dest, + const void *src, + uint16_t length_b); + +void gcm128_finalize( + gcm128_ctx_t *ctx, + void *tag, + uint16_t tag_length_b); + +#endif /* GCM_GCM128_H_ */