cbc.h 2.36 KB
Newer Older
1
/* cbc.h
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

   Cipher block chaining mode.

   Copyright (C) 2001 Niels Möller

   This file is part of GNU Nettle.

   GNU Nettle is free software: you can redistribute it and/or
   modify it under the terms of either:

     * the GNU Lesser General Public License as published by the Free
       Software Foundation; either version 3 of the License, or (at your
       option) any later version.

   or

     * the GNU General Public License as published by the Free
       Software Foundation; either version 2 of the License, or (at your
       option) any later version.

   or both in parallel, as here.

   GNU Nettle is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received copies of the GNU General Public License and
   the GNU Lesser General Public License along with this program.  If
   not, see http://www.gnu.org/licenses/.
*/
33 34 35 36

#ifndef NETTLE_CBC_H_INCLUDED
#define NETTLE_CBC_H_INCLUDED

37
#include "nettle-types.h"
38

Niels Möller's avatar
Niels Möller committed
39 40 41 42
#ifdef __cplusplus
extern "C" {
#endif

43 44 45 46
/* Name mangling */
#define cbc_encrypt nettle_cbc_encrypt
#define cbc_decrypt nettle_cbc_decrypt

47
void
48
cbc_encrypt(const void *ctx, nettle_cipher_func *f,
49 50
	    size_t block_size, uint8_t *iv,
	    size_t length, uint8_t *dst,
51 52 53
	    const uint8_t *src);

void
54
cbc_decrypt(const void *ctx, nettle_cipher_func *f,
55 56
	    size_t block_size, uint8_t *iv,
	    size_t length, uint8_t *dst,
57 58
	    const uint8_t *src);

Niels Möller's avatar
Niels Möller committed
59 60 61 62 63 64
#define CBC_CTX(type, size) \
{ type ctx; uint8_t iv[size]; }

#define CBC_SET_IV(ctx, data) \
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 68
  (0 ? ((f)(&(self)->ctx, ~(size_t) 0,			\
	    (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)))
Niels Möller's avatar
Niels Möller committed
73

74
#define CBC_DECRYPT(self, f, length, dst, src)		\
75 76
  (0 ? ((f)(&(self)->ctx, ~(size_t) 0,			\
	    (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)))
Niels Möller's avatar
Niels Möller committed
81

Niels Möller's avatar
Niels Möller committed
82 83 84 85
#ifdef __cplusplus
}
#endif

86
#endif /* NETTLE_CBC_H_INCLUDED */