3 * $Id: cbc.h,v 1.2 1999/12/10 23:16:39 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.2 1999/12/10 23:16:39 mdw
34 * Split mode macros into interface and implementation.
36 * Revision 1.1 1999/09/03 08:41:11 mdw
41 #ifndef CATACOMB_CBC_H
42 #define CATACOMB_CBC_H
48 /*----- Header files ------------------------------------------------------*/
52 #include <mLib/bits.h>
54 #ifndef CATACOMB_GCIPHER_H
58 /*----- Macros ------------------------------------------------------------*/
60 /* --- @CBC_DECL@ --- *
62 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
64 * Use: Creates declarations for CBC stealing mode.
67 #define CBC_DECL(PRE, pre) \
69 /* --- Cipher block chaining context --- */ \
71 typedef struct pre##_cbcctx { \
72 pre##_ctx ctx; /* Underlying cipher context */ \
73 uint32 iv[PRE##_BLKSZ / 4]; /* Previous ciphertext or IV */ \
76 /* --- @pre_cbcgetiv@ --- * \
78 * Arguments: @const pre_cbcctx *ctx@ = pointer to CBC context block \
79 * @void *iv#@ = pointer to output data block \
83 * Use: Reads the currently set IV. Reading and setting an IV \
84 * is transparent to the CBC encryption or decryption \
88 extern void pre##_cbcgetiv(const pre##_cbcctx */*ctx*/, \
91 /* --- @pre_cbcsetiv@ --- * \
93 * Arguments: @pre_cbcctx *ctx@ = pointer to CBC context block \
94 * @cnost void *iv@ = pointer to IV to set \
98 * Use: Sets the IV to use for subsequent encryption. \
101 extern void pre##_cbcsetiv(pre##_cbcctx */*ctx*/, \
102 const void */*iv*/); \
104 /* --- @pre_cbcsetkey@ --- * \
106 * Arguments: @pre_cbcctx *ctx@ = pointer to CBC context block \
107 * @const pre_ctx *k@ = pointer to cipher context \
111 * Use: Sets the CBC context to use a different cipher key. \
114 extern void pre##_cbcsetkey(pre##_cbcctx */*ctx*/, \
115 const pre##_ctx */*k*/); \
117 /* --- @pre_cbcinit@ --- * \
119 * Arguments: @pre_cbcctx *ctx@ = pointer to cipher context \
120 * @const void *key@ = pointer to the key buffer \
121 * @size_t sz@ = size of the key \
122 * @const void *iv@ = pointer to initialization vector \
126 * Use: Initializes a CBC context ready for use. The @iv@ \
127 * argument may be passed as a null pointer to set a zero \
128 * IV. Apart from that, this call is equivalent to calls \
129 * to @pre_init@, @pre_cbcsetkey@ and @pre_cbcsetiv@. \
132 extern void pre##_cbcinit(pre##_cbcctx */*ctx*/, \
133 const void */*key*/, size_t /*sz*/, \
134 const void */*iv*/); \
136 /* --- @pre_cbcencrypt@ --- * \
138 * Arguments: @pre_cbcctx *ctx@ = pointer to CBC context block \
139 * @const void *src@ = pointer to source data \
140 * @void *dest@ = pointer to destination data \
141 * @size_t sz@ = size of block to be encrypted \
145 * Use: Encrypts a block with a block cipher in CBC mode, with \
146 * ciphertext stealing and other clever tricks. \
147 * Essentially, data can be encrypted in arbitrary sized \
148 * chunks, although decryption must use the same chunks. \
151 extern void pre##_cbcencrypt(pre##_cbcctx */*ctx*/, \
152 const void */*src*/, void */*dest*/, \
155 /* --- @pre_cbcdecrypt@ --- * \
157 * Arguments: @pre_cbcctx *ctx@ = pointer to CBC context block \
158 * @const void *src@ = pointer to source data \
159 * @void *dest@ = pointer to destination data \
160 * @size_t sz@ = size of block to be encrypted \
164 * Use: Decrypts a block with a block cipher in CBC mode, with \
165 * ciphertext stealing and other clever tricks. \
166 * Essentially, data can be encrypted in arbitrary sized \
167 * chunks, although decryption must use the same chunks. \
170 extern void pre##_cbcdecrypt(pre##_cbcctx */*ctx*/, \
171 const void */*src*/, void */*dest*/, \
174 /* --- Generic cipher interface --- */ \
176 extern const gccipher pre##_cbc;
178 /*----- That's all, folks -------------------------------------------------*/