Fixed package group
[platform/upstream/nettle.git] / cbc.h
1 /* cbc.h
2  *
3  * Cipher block chaining mode.
4  */
5
6 /* nettle, low-level cryptographics library
7  *
8  * Copyright (C) 2001 Niels Möller
9  *  
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.
14  * 
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.
19  * 
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,
23  * MA 02111-1301, USA.
24  */
25
26 #ifndef NETTLE_CBC_H_INCLUDED
27 #define NETTLE_CBC_H_INCLUDED
28
29 #include "nettle-types.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /* Name mangling */
36 #define cbc_encrypt nettle_cbc_encrypt
37 #define cbc_decrypt nettle_cbc_decrypt
38
39 void
40 cbc_encrypt(void *ctx, nettle_crypt_func *f,
41             unsigned block_size, uint8_t *iv,
42             unsigned length, uint8_t *dst,
43             const uint8_t *src);
44
45 void
46 cbc_decrypt(void *ctx, nettle_crypt_func *f,
47             unsigned block_size, uint8_t *iv,
48             unsigned length, uint8_t *dst,
49             const uint8_t *src);
50
51 #define CBC_CTX(type, size) \
52 { type ctx; uint8_t iv[size]; }
53
54 #define CBC_SET_IV(ctx, data) \
55 memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
56
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)))
64
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)))
71
72 #ifdef __cplusplus
73 }
74 #endif
75
76 #endif /* NETTLE_CBC_H_INCLUDED */