1/* cbc.h
2
3 Cipher block chaining mode.
4
5 Copyright (C) 2001 Niels Möller
6
7 This file is part of GNU Nettle.
8
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
11
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.
15
16 or
17
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.
21
22 or both in parallel, as here.
23
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.
28
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/.
32*/
33
34#ifndef NETTLE_CBC_H_INCLUDED
35#define NETTLE_CBC_H_INCLUDED
36
37#include "nettle-types.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/* Name mangling */
44#define cbc_encrypt nettle_cbc_encrypt
45#define cbc_decrypt nettle_cbc_decrypt
46
47void
48cbc_encrypt(const void *ctx, nettle_cipher_func *f,
49 size_t block_size, uint8_t *iv,
50 size_t length, uint8_t *dst,
51 const uint8_t *src);
52
53void
54cbc_decrypt(const void *ctx, nettle_cipher_func *f,
55 size_t block_size, uint8_t *iv,
56 size_t length, uint8_t *dst,
57 const uint8_t *src);
58
59#define CBC_CTX(type, size) \
60{ type ctx; uint8_t iv[size]; }
61
62#define CBC_SET_IV(ctx, data) \
63memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
64
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)))
73
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)))
81
82#ifdef __cplusplus
83}
84#endif
85
86#endif /* NETTLE_CBC_H_INCLUDED */
87