3 * $Id: cbc.h,v 1.3 2001/06/17 00:10:51 mdw Exp $
5 * Ciphertext block chaining for block ciphers
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.3 2001/06/17 00:10:51 mdw
36 * Revision 1.2 1999/12/10 23:16:39 mdw
37 * Split mode macros into interface and implementation.
39 * Revision 1.1 1999/09/03 08:41:11 mdw
44 #ifndef CATACOMB_CBC_H
45 #define CATACOMB_CBC_H
51 /*----- Header files ------------------------------------------------------*/
55 #include <mLib/bits.h>
57 #ifndef CATACOMB_GCIPHER_H
61 /*----- Macros ------------------------------------------------------------*/
63 /* --- @CBC_DECL@ --- *
65 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
67 * Use: Creates declarations for CBC stealing mode.
70 #define CBC_DECL(PRE, pre) \
72 /* --- Cipher block chaining context --- */ \
74 typedef struct pre##_cbcctx { \
75 pre##_ctx ctx; /* Underlying cipher context */ \
76 uint32 iv[PRE##_BLKSZ / 4]; /* Previous ciphertext or IV */ \
79 /* --- @pre_cbcgetiv@ --- * \
81 * Arguments: @const pre_cbcctx *ctx@ = pointer to CBC context block \
82 * @void *iv@ = pointer to output data block \
86 * Use: Reads the currently set IV. Reading and setting an IV \
87 * is transparent to the CBC encryption or decryption \
91 extern void pre##_cbcgetiv(const pre##_cbcctx */*ctx*/, \
94 /* --- @pre_cbcsetiv@ --- * \
96 * Arguments: @pre_cbcctx *ctx@ = pointer to CBC context block \
97 * @cnost void *iv@ = pointer to IV to set \
101 * Use: Sets the IV to use for subsequent encryption. \
104 extern void pre##_cbcsetiv(pre##_cbcctx */*ctx*/, \
105 const void */*iv*/); \
107 /* --- @pre_cbcsetkey@ --- * \
109 * Arguments: @pre_cbcctx *ctx@ = pointer to CBC context block \
110 * @const pre_ctx *k@ = pointer to cipher context \
114 * Use: Sets the CBC context to use a different cipher key. \
117 extern void pre##_cbcsetkey(pre##_cbcctx */*ctx*/, \
118 const pre##_ctx */*k*/); \
120 /* --- @pre_cbcinit@ --- * \
122 * Arguments: @pre_cbcctx *ctx@ = pointer to cipher context \
123 * @const void *key@ = pointer to the key buffer \
124 * @size_t sz@ = size of the key \
125 * @const void *iv@ = pointer to initialization vector \
129 * Use: Initializes a CBC context ready for use. The @iv@ \
130 * argument may be passed as a null pointer to set a zero \
131 * IV. Apart from that, this call is equivalent to calls \
132 * to @pre_init@, @pre_cbcsetkey@ and @pre_cbcsetiv@. \
135 extern void pre##_cbcinit(pre##_cbcctx */*ctx*/, \
136 const void */*key*/, size_t /*sz*/, \
137 const void */*iv*/); \
139 /* --- @pre_cbcencrypt@ --- * \
141 * Arguments: @pre_cbcctx *ctx@ = pointer to CBC context block \
142 * @const void *src@ = pointer to source data \
143 * @void *dest@ = pointer to destination data \
144 * @size_t sz@ = size of block to be encrypted \
148 * Use: Encrypts a block with a block cipher in CBC mode, with \
149 * ciphertext stealing and other clever tricks. \
150 * Essentially, data can be encrypted in arbitrary sized \
151 * chunks, although decryption must use the same chunks. \
154 extern void pre##_cbcencrypt(pre##_cbcctx */*ctx*/, \
155 const void */*src*/, void */*dest*/, \
158 /* --- @pre_cbcdecrypt@ --- * \
160 * Arguments: @pre_cbcctx *ctx@ = pointer to CBC context block \
161 * @const void *src@ = pointer to source data \
162 * @void *dest@ = pointer to destination data \
163 * @size_t sz@ = size of block to be encrypted \
167 * Use: Decrypts a block with a block cipher in CBC mode, with \
168 * ciphertext stealing and other clever tricks. \
169 * Essentially, data can be encrypted in arbitrary sized \
170 * chunks, although decryption must use the same chunks. \
173 extern void pre##_cbcdecrypt(pre##_cbcctx */*ctx*/, \
174 const void */*src*/, void */*dest*/, \
177 /* --- Generic cipher interface --- */ \
179 extern const gccipher pre##_cbc;
181 /*----- That's all, folks -------------------------------------------------*/