mpmul.[ch]: Move internal `HWM' and `LWM' constants to implementation.
[u/mdw/catacomb] / ecb.h
1 /* -*-c-*-
2 *
3 * $Id: ecb.h,v 1.3 2004/04/08 01:36:15 mdw Exp $
4 *
5 * Electronic code book 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 #ifndef CATACOMB_ECB_H
31 #define CATACOMB_ECB_H
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /*----- Header files ------------------------------------------------------*/
38
39 #include <stddef.h>
40
41 #ifndef CATACOMB_GCIPHER_H
42 # include "gcipher.h"
43 #endif
44
45 /*----- Macros ------------------------------------------------------------*/
46
47 /* --- @ECB_DECL@ --- *
48 *
49 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
50 *
51 * Use: Creates declarations for ECB stealing mode.
52 */
53
54 #define ECB_DECL(PRE, pre) \
55 \
56 /* --- Electronic codebook context --- */ \
57 \
58 typedef struct pre##_ecbctx { \
59 pre##_ctx ctx; /* Underlying cipher context */ \
60 } pre##_ecbctx; \
61 \
62 /* --- @pre_ecbsetkey@ --- * \
63 * \
64 * Arguments: @pre_ecbctx *ctx@ = pointer to ECB context block \
65 * @const pre_ctx *k@ = pointer to cipher context \
66 * \
67 * Returns: --- \
68 * \
69 * Use: Sets the ECB context to use a different cipher key. \
70 */ \
71 \
72 extern void pre##_ecbsetkey(pre##_ecbctx */*ctx*/, \
73 const pre##_ctx */*k*/); \
74 \
75 /* --- @pre_ecbinit@ --- * \
76 * \
77 * Arguments: @pre_ecbctx *ctx@ = pointer to cipher context \
78 * @const void *key@ = pointer to the key buffer \
79 * @size_t sz@ = size of the key \
80 * @const void *iv@ = pointer to initialization vector \
81 * \
82 * Returns: --- \
83 * \
84 * Use: Initializes an ECB context ready for use. This is \
85 * equivalent to calls to @pre_init@ and @pre_setkey@. \
86 */ \
87 \
88 extern void pre##_ecbinit(pre##_ecbctx */*ctx*/, \
89 const void */*key*/, size_t /*sz*/, \
90 const void */*iv*/); \
91 \
92 /* --- @pre_ecbencrypt@ --- * \
93 * \
94 * Arguments: @pre_ecbctx *ctx@ = pointer to ECB context block \
95 * @const void *src@ = pointer to source data \
96 * @void *dest@ = pointer to destination data \
97 * @size_t sz@ = size of block to be encrypted \
98 * \
99 * Returns: --- \
100 * \
101 * Use: Encrypts a block with a block cipher in ECB mode, with \
102 * ciphertext stealing and other clever tricks. \
103 * Essentially, data can be encrypted in arbitrary sized \
104 * chunks, although decryption must use the same chunks. \
105 */ \
106 \
107 extern void pre##_ecbencrypt(pre##_ecbctx */*ctx*/, \
108 const void */*src*/, void */*dest*/, \
109 size_t /*sz*/); \
110 \
111 /* --- @pre_ecbdecrypt@ --- * \
112 * \
113 * Arguments: @pre_ecbctx *ctx@ = pointer to ECB context block \
114 * @const void *src@ = pointer to source data \
115 * @void *dest@ = pointer to destination data \
116 * @size_t sz@ = size of block to be encrypted \
117 * \
118 * Returns: --- \
119 * \
120 * Use: Decrypts a block with a block cipher in ECB mode, with \
121 * ciphertext stealing and other clever tricks. \
122 * Essentially, data can be encrypted in arbitrary sized \
123 * chunks, although decryption must use the same chunks. \
124 */ \
125 \
126 extern void pre##_ecbdecrypt(pre##_ecbctx */*ctx*/, \
127 const void */*src*/, void */*dest*/, \
128 size_t /*sz*/); \
129 \
130 /* --- Generic cipher interface --- */ \
131 \
132 extern const gccipher pre##_ecb;
133
134 /*----- That's all, folks -------------------------------------------------*/
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif