d03ab969 |
1 | /* -*-c-*- |
2 | * |
b817bfc6 |
3 | * $Id: ecb.h,v 1.3 2004/04/08 01:36:15 mdw Exp $ |
d03ab969 |
4 | * |
79ba130c |
5 | * Electronic code book for block ciphers |
d03ab969 |
6 | * |
7 | * (c) 1999 Straylight/Edgeware |
8 | */ |
9 | |
45c0fd36 |
10 | /*----- Licensing notice --------------------------------------------------* |
d03ab969 |
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. |
45c0fd36 |
18 | * |
d03ab969 |
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. |
45c0fd36 |
23 | * |
d03ab969 |
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 | |
79ba130c |
30 | #ifndef CATACOMB_ECB_H |
31 | #define CATACOMB_ECB_H |
d03ab969 |
32 | |
33 | #ifdef __cplusplus |
34 | extern "C" { |
35 | #endif |
36 | |
37 | /*----- Header files ------------------------------------------------------*/ |
38 | |
79ba130c |
39 | #include <stddef.h> |
d03ab969 |
40 | |
79ba130c |
41 | #ifndef CATACOMB_GCIPHER_H |
42 | # include "gcipher.h" |
d03ab969 |
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 | \ |
79ba130c |
56 | /* --- Electronic codebook context --- */ \ |
d03ab969 |
57 | \ |
79ba130c |
58 | typedef struct pre##_ecbctx { \ |
59 | pre##_ctx ctx; /* Underlying cipher context */ \ |
60 | } pre##_ecbctx; \ |
d03ab969 |
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 | \ |
79ba130c |
72 | extern void pre##_ecbsetkey(pre##_ecbctx */*ctx*/, \ |
73 | const pre##_ctx */*k*/); \ |
d03ab969 |
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 | \ |
79ba130c |
88 | extern void pre##_ecbinit(pre##_ecbctx */*ctx*/, \ |
89 | const void */*key*/, size_t /*sz*/, \ |
90 | const void */*iv*/); \ |
d03ab969 |
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 | \ |
79ba130c |
107 | extern void pre##_ecbencrypt(pre##_ecbctx */*ctx*/, \ |
108 | const void */*src*/, void */*dest*/, \ |
109 | size_t /*sz*/); \ |
d03ab969 |
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 | * \ |
79ba130c |
120 | * Use: Decrypts a block with a block cipher in ECB mode, with \ |
d03ab969 |
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 | \ |
79ba130c |
126 | extern void pre##_ecbdecrypt(pre##_ecbctx */*ctx*/, \ |
127 | const void */*src*/, void */*dest*/, \ |
128 | size_t /*sz*/); \ |
d03ab969 |
129 | \ |
79ba130c |
130 | /* --- Generic cipher interface --- */ \ |
d03ab969 |
131 | \ |
79ba130c |
132 | extern const gccipher pre##_ecb; |
d03ab969 |
133 | |
134 | /*----- That's all, folks -------------------------------------------------*/ |
135 | |
136 | #ifdef __cplusplus |
137 | } |
138 | #endif |
139 | |
140 | #endif |