Renamed from `rsa-decrypt', since the name was no longer appropriate.
[u/mdw/catacomb] / cbc.h
CommitLineData
d03ab969 1/* -*-c-*-
2 *
79ba130c 3 * $Id: cbc.h,v 1.2 1999/12/10 23:16:39 mdw Exp $
d03ab969 4 *
5 * Ciphertext block chaining for block ciphers
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
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.
18 *
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.
23 *
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,
27 * MA 02111-1307, USA.
28 */
29
30/*----- Revision history --------------------------------------------------*
31 *
32 * $Log: cbc.h,v $
79ba130c 33 * Revision 1.2 1999/12/10 23:16:39 mdw
34 * Split mode macros into interface and implementation.
35 *
d03ab969 36 * Revision 1.1 1999/09/03 08:41:11 mdw
37 * Initial import.
38 *
39 */
40
79ba130c 41#ifndef CATACOMB_CBC_H
42#define CATACOMB_CBC_H
d03ab969 43
44#ifdef __cplusplus
45 extern "C" {
46#endif
47
48/*----- Header files ------------------------------------------------------*/
49
79ba130c 50#include <stddef.h>
d03ab969 51
52#include <mLib/bits.h>
53
79ba130c 54#ifndef CATACOMB_GCIPHER_H
55# include "gcipher.h"
d03ab969 56#endif
57
58/*----- Macros ------------------------------------------------------------*/
59
60/* --- @CBC_DECL@ --- *
61 *
62 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
63 *
64 * Use: Creates declarations for CBC stealing mode.
65 */
66
67#define CBC_DECL(PRE, pre) \
68 \
79ba130c 69/* --- Cipher block chaining context --- */ \
d03ab969 70 \
79ba130c 71typedef struct pre##_cbcctx { \
72 pre##_ctx ctx; /* Underlying cipher context */ \
73 uint32 iv[PRE##_BLKSZ / 4]; /* Previous ciphertext or IV */ \
74} pre##_cbcctx; \
d03ab969 75 \
76/* --- @pre_cbcgetiv@ --- * \
77 * \
78 * Arguments: @const pre_cbcctx *ctx@ = pointer to CBC context block \
79 * @void *iv#@ = pointer to output data block \
80 * \
81 * Returns: --- \
82 * \
83 * Use: Reads the currently set IV. Reading and setting an IV \
84 * is transparent to the CBC encryption or decryption \
85 * process. \
86 */ \
87 \
79ba130c 88extern void pre##_cbcgetiv(const pre##_cbcctx */*ctx*/, \
89 void */*iv*/); \
d03ab969 90 \
91/* --- @pre_cbcsetiv@ --- * \
92 * \
93 * Arguments: @pre_cbcctx *ctx@ = pointer to CBC context block \
94 * @cnost void *iv@ = pointer to IV to set \
95 * \
96 * Returns: --- \
97 * \
98 * Use: Sets the IV to use for subsequent encryption. \
99 */ \
100 \
79ba130c 101extern void pre##_cbcsetiv(pre##_cbcctx */*ctx*/, \
102 const void */*iv*/); \
d03ab969 103 \
104/* --- @pre_cbcsetkey@ --- * \
105 * \
106 * Arguments: @pre_cbcctx *ctx@ = pointer to CBC context block \
107 * @const pre_ctx *k@ = pointer to cipher context \
108 * \
109 * Returns: --- \
110 * \
111 * Use: Sets the CBC context to use a different cipher key. \
112 */ \
113 \
79ba130c 114extern void pre##_cbcsetkey(pre##_cbcctx */*ctx*/, \
115 const pre##_ctx */*k*/); \
d03ab969 116 \
117/* --- @pre_cbcinit@ --- * \
118 * \
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 \
123 * \
124 * Returns: --- \
125 * \
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@. \
130 */ \
131 \
79ba130c 132extern void pre##_cbcinit(pre##_cbcctx */*ctx*/, \
133 const void */*key*/, size_t /*sz*/, \
134 const void */*iv*/); \
d03ab969 135 \
136/* --- @pre_cbcencrypt@ --- * \
137 * \
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 \
142 * \
143 * Returns: --- \
144 * \
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. \
149 */ \
150 \
79ba130c 151extern void pre##_cbcencrypt(pre##_cbcctx */*ctx*/, \
152 const void */*src*/, void */*dest*/, \
153 size_t /*sz*/); \
d03ab969 154 \
155/* --- @pre_cbcdecrypt@ --- * \
156 * \
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 \
161 * \
162 * Returns: --- \
163 * \
79ba130c 164 * Use: Decrypts a block with a block cipher in CBC mode, with \
d03ab969 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. \
168 */ \
169 \
79ba130c 170extern void pre##_cbcdecrypt(pre##_cbcctx */*ctx*/, \
171 const void */*src*/, void */*dest*/, \
172 size_t /*sz*/); \
d03ab969 173 \
79ba130c 174/* --- Generic cipher interface --- */ \
d03ab969 175 \
79ba130c 176extern const gccipher pre##_cbc;
d03ab969 177
178/*----- That's all, folks -------------------------------------------------*/
179
180#ifdef __cplusplus
181 }
182#endif
183
184#endif