testutils.c: Fix high bits of the mpz_urandomb used with mini-gmp.
[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 void
49 cfb_encrypt(const void *ctx, nettle_cipher_func *f,
50             size_t block_size, uint8_t *iv,
51             size_t length, uint8_t *dst,
52             const uint8_t *src);
53
54 void
55 cfb_decrypt(const void *ctx, nettle_cipher_func *f,
56             size_t block_size, uint8_t *iv,
57             size_t length, uint8_t *dst,
58             const uint8_t *src);
59
60 #define CFB_CTX(type, size) \
61 { type ctx; uint8_t iv[size]; }
62
63 #define CFB_SET_IV(ctx, data) \
64 memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
65
66 /* NOTE: Avoid using NULL, as we don't include anything defining it. */
67 #define CFB_ENCRYPT(self, f, length, dst, src)          \
68   (0 ? ((f)(&(self)->ctx, ~(size_t) 0,                  \
69             (uint8_t *) 0, (const uint8_t *) 0))        \
70    : cfb_encrypt((void *) &(self)->ctx,                 \
71                  (nettle_cipher_func *) (f),            \
72                  sizeof((self)->iv), (self)->iv,        \
73                  (length), (dst), (src)))
74
75 #define CFB_DECRYPT(self, f, length, dst, src)          \
76   (0 ? ((f)(&(self)->ctx, ~(size_t) 0,                  \
77             (uint8_t *) 0, (const uint8_t *) 0))        \
78    : cfb_decrypt((void *) &(self)->ctx,                 \
79                  (nettle_cipher_func *) (f),            \
80                  sizeof((self)->iv), (self)->iv,        \
81                  (length), (dst), (src)))
82
83 #ifdef __cplusplus
84 }
85 #endif
86
87 #endif /* NETTLE_CFB_H_INCLUDED */