3 Cipher block chaining mode.
5 Copyright (C) 2001 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
18 * the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at your
20 option) any later version.
22 or both in parallel, as here.
24 GNU Nettle is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
29 You should have received copies of the GNU General Public License and
30 the GNU Lesser General Public License along with this program. If
31 not, see http://www.gnu.org/licenses/.
34 #ifndef NETTLE_CBC_H_INCLUDED
35 #define NETTLE_CBC_H_INCLUDED
37 #include "nettle-types.h"
44 #define cbc_encrypt nettle_cbc_encrypt
45 #define cbc_decrypt nettle_cbc_decrypt
48 cbc_encrypt(const void *ctx, nettle_cipher_func *f,
49 size_t block_size, uint8_t *iv,
50 size_t length, uint8_t *dst,
54 cbc_decrypt(const void *ctx, nettle_cipher_func *f,
55 size_t block_size, uint8_t *iv,
56 size_t length, uint8_t *dst,
59 #define CBC_CTX(type, size) \
60 { type ctx; uint8_t iv[size]; }
62 #define CBC_SET_IV(ctx, data) \
63 memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
65 /* NOTE: Avoid using NULL, as we don't include anything defining it. */
66 #define CBC_ENCRYPT(self, f, length, dst, src) \
67 (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
68 (uint8_t *) 0, (const uint8_t *) 0)) \
69 : cbc_encrypt((void *) &(self)->ctx, \
70 (nettle_cipher_func *) (f), \
71 sizeof((self)->iv), (self)->iv, \
72 (length), (dst), (src)))
74 #define CBC_DECRYPT(self, f, length, dst, src) \
75 (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
76 (uint8_t *) 0, (const uint8_t *) 0)) \
77 : cbc_decrypt((void *) &(self)->ctx, \
78 (nettle_cipher_func *) (f), \
79 sizeof((self)->iv), (self)->iv, \
80 (length), (dst), (src)))
86 #endif /* NETTLE_CBC_H_INCLUDED */