]> git.cryptolib.org Git - avr-crypto-lib.git/blob - gcm/gcm128.h
755b75ac76f843bda3a027c8ee1a9d2f26487328
[avr-crypto-lib.git] / gcm / gcm128.h
1 /* gcm128.h */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2015 Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef GCM_GCM128_H_
21 #define GCM_GCM128_H_
22
23
24 /* gcm128.c */
25 /*
26     This file is part of the AVR-Crypto-Lib.
27     Copyright (C) 2006-2015 Daniel Otte (daniel.otte@rub.de)
28
29     This program is free software: you can redistribute it and/or modify
30     it under the terms of the GNU General Public License as published by
31     the Free Software Foundation, either version 3 of the License, or
32     (at your option) any later version.
33
34     This program is distributed in the hope that it will be useful,
35     but WITHOUT ANY WARRANTY; without even the implied warranty of
36     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37     GNU General Public License for more details.
38
39     You should have received a copy of the GNU General Public License
40     along with this program.  If not, see <http://www.gnu.org/licenses/>.
41 */
42
43 #include <inttypes.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <memxor.h>
47 #include <blockcipher_descriptor.h>
48 #include <gcm128.h>
49
50 #define GCM128_BLOCK_BYTES 16
51 #define GCM128_BLOCK_BITS (GCM128_BLOCK_BYTES * 8)
52
53 #define GCM128_COUNT_BYTES 4
54 #define GCM128_COUNT_BITS (GCM128_COUNT_BYTES * 8)
55
56
57
58 typedef struct {
59     uint8_t tag[GCM128_BLOCK_BYTES];
60     uint8_t key[GCM128_BLOCK_BYTES];
61 } ghash128_ctx_t;
62
63 typedef struct {
64     ghash128_ctx_t ghash_ctx;
65     bcgen_ctx_t cipher_ctx;
66     uint8_t ctr[GCM128_BLOCK_BYTES];
67     uint8_t j0[GCM128_COUNT_BYTES];
68     uint32_t length_a;
69     uint32_t length_c;
70 } gcm128_ctx_t;
71
72 int8_t gcm128_init(
73         gcm128_ctx_t *ctx,
74         const bcdesc_t *cipher,
75         const void *key,
76         uint16_t key_length_b,
77         const void *iv,
78         uint16_t iv_length_b);
79
80 void gcm128_add_ad_block(
81         gcm128_ctx_t *ctx,
82         const void *block );
83
84 void gcm128_add_ad_final_block(
85         gcm128_ctx_t *ctx,
86         const void *block,
87         uint16_t length_b );
88
89 void gcm128_encrypt_block(
90         gcm128_ctx_t *ctx,
91         void *dest,
92         const void *src);
93
94 void gcm128_encrypt_final_block(
95         gcm128_ctx_t *ctx,
96         void *dest,
97         const void *src,
98         uint16_t length_b);
99
100 void gcm128_decrypt_block(
101         gcm128_ctx_t *ctx,
102         void *dest,
103         const void *src);
104
105 void gcm128_decrypt_final_block(
106         gcm128_ctx_t *ctx,
107         void *dest,
108         const void *src,
109         uint16_t length_b);
110
111 void gcm128_finalize(
112         gcm128_ctx_t *ctx,
113         void *tag,
114         uint16_t tag_length_b);
115
116 #endif /* GCM_GCM128_H_ */