Further separation of CMAC per-message state from subkeys.
[gd/nettle] / cfb.h
1 /* cfb.h
2
3    Cipher feedback mode.
4
5    Copyright (C) 2015, 2017 Dmitry Eremin-Solenikov
6    Copyright (C) 2001 Niels Möller
7
8    This file is part of GNU Nettle.
9
10    GNU Nettle is free software: you can redistribute it and/or
11    modify it under the terms of either:
12
13      * the GNU Lesser General Public License as published by the Free
14        Software Foundation; either version 3 of the License, or (at your
15        option) any later version.
16
17    or
18
19      * the GNU General Public License as published by the Free
20        Software Foundation; either version 2 of the License, or (at your
21        option) any later version.
22
23    or both in parallel, as here.
24
25    GNU Nettle is distributed in the hope that it will be useful,
26    but WITHOUT ANY WARRANTY; without even the implied warranty of
27    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28    General Public License for more details.
29
30    You should have received copies of the GNU General Public License and
31    the GNU Lesser General Public License along with this program.  If
32    not, see http://www.gnu.org/licenses/.
33 */
34
35 #ifndef NETTLE_CFB_H_INCLUDED
36 #define NETTLE_CFB_H_INCLUDED
37
38 #include "nettle-types.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /* Name mangling */
45 #define cfb_encrypt nettle_cfb_encrypt
46 #define cfb_decrypt nettle_cfb_decrypt
47
48 #define cfb8_encrypt nettle_cfb8_encrypt
49 #define cfb8_decrypt nettle_cfb8_decrypt
50
51 void
52 cfb_encrypt(const void *ctx, nettle_cipher_func *f,
53             size_t block_size, uint8_t *iv,
54             size_t length, uint8_t *dst,
55             const uint8_t *src);
56
57 void
58 cfb_decrypt(const void *ctx, nettle_cipher_func *f,
59             size_t block_size, uint8_t *iv,
60             size_t length, uint8_t *dst,
61             const uint8_t *src);
62
63 void
64 cfb8_encrypt(const void *ctx, nettle_cipher_func *f,
65              size_t block_size, uint8_t *iv,
66              size_t length, uint8_t *dst,
67              const uint8_t *src);
68
69 void
70 cfb8_decrypt(const void *ctx, nettle_cipher_func *f,
71              size_t block_size, uint8_t *iv,
72              size_t length, uint8_t *dst,
73              const uint8_t *src);
74
75
76 #define CFB_CTX(type, size) \
77 { type ctx; uint8_t iv[size]; }
78
79 #define CFB_SET_IV(ctx, data) \
80 memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
81
82 #define CFB8_CTX CFB_CTX
83 #define CFB8_SET_IV CFB_SET_IV
84
85 /* NOTE: Avoid using NULL, as we don't include anything defining it. */
86 #define CFB_ENCRYPT(self, f, length, dst, src)          \
87   (0 ? ((f)(&(self)->ctx, ~(size_t) 0,                  \
88             (uint8_t *) 0, (const uint8_t *) 0))        \
89    : cfb_encrypt((void *) &(self)->ctx,                 \
90                  (nettle_cipher_func *) (f),            \
91                  sizeof((self)->iv), (self)->iv,        \
92                  (length), (dst), (src)))
93
94 #define CFB_DECRYPT(self, f, length, dst, src)          \
95   (0 ? ((f)(&(self)->ctx, ~(size_t) 0,                  \
96             (uint8_t *) 0, (const uint8_t *) 0))        \
97    : cfb_decrypt((void *) &(self)->ctx,                 \
98                  (nettle_cipher_func *) (f),            \
99                  sizeof((self)->iv), (self)->iv,        \
100                  (length), (dst), (src)))
101
102 #define CFB8_ENCRYPT(self, f, length, dst, src)         \
103   (0 ? ((f)(&(self)->ctx, ~(size_t) 0,                  \
104             (uint8_t *) 0, (const uint8_t *) 0))        \
105    : cfb8_encrypt((void *) &(self)->ctx,                \
106                   (nettle_cipher_func *) (f),           \
107                   sizeof((self)->iv), (self)->iv,       \
108                   (length), (dst), (src)))
109
110 #define CFB8_DECRYPT(self, f, length, dst, src)         \
111   (0 ? ((f)(&(self)->ctx, ~(size_t) 0,                  \
112             (uint8_t *) 0, (const uint8_t *) 0))        \
113    : cfb8_decrypt((void *) &(self)->ctx,                \
114                   (nettle_cipher_func *) (f),           \
115                   sizeof((self)->iv), (self)->iv,       \
116                   (length), (dst), (src)))
117
118 #ifdef __cplusplus
119 }
120 #endif
121
122 #endif /* NETTLE_CFB_H_INCLUDED */