3 * Cipher block chaining mode.
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2001 Niels Möller
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 #ifndef NETTLE_CBC_H_INCLUDED
27 #define NETTLE_CBC_H_INCLUDED
29 #include "nettle-types.h"
36 #define cbc_encrypt nettle_cbc_encrypt
37 #define cbc_decrypt nettle_cbc_decrypt
40 cbc_encrypt(void *ctx, nettle_crypt_func *f,
41 unsigned block_size, uint8_t *iv,
42 unsigned length, uint8_t *dst,
46 cbc_decrypt(void *ctx, nettle_crypt_func *f,
47 unsigned block_size, uint8_t *iv,
48 unsigned length, uint8_t *dst,
51 #define CBC_CTX(type, size) \
52 { type ctx; uint8_t iv[size]; }
54 #define CBC_SET_IV(ctx, data) \
55 memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
57 /* NOTE: Avoid using NULL, as we don't include anything defining it. */
58 #define CBC_ENCRYPT(self, f, length, dst, src) \
59 (0 ? ((f)(&(self)->ctx, 0, (void *)0, (void *)0)) \
60 : cbc_encrypt((void *) &(self)->ctx, \
61 (nettle_crypt_func *) (f), \
62 sizeof((self)->iv), (self)->iv, \
63 (length), (dst), (src)))
65 #define CBC_DECRYPT(self, f, length, dst, src) \
66 (0 ? ((f)(&(self)->ctx, 0, (void *)0, (void *)0)) \
67 : cbc_decrypt((void *) &(self)->ctx, \
68 (nettle_crypt_func *) (f), \
69 sizeof((self)->iv), (self)->iv, \
70 (length), (dst), (src)))
76 #endif /* NETTLE_CBC_H_INCLUDED */