d03ab969 |
1 | /* -*-c-*- |
d03ab969 |
2 | * |
79ba130c |
3 | * Electronic code book for block ciphers |
d03ab969 |
4 | * |
5 | * (c) 1999 Straylight/Edgeware |
6 | */ |
7 | |
45c0fd36 |
8 | /*----- Licensing notice --------------------------------------------------* |
d03ab969 |
9 | * |
10 | * This file is part of Catacomb. |
11 | * |
12 | * Catacomb is free software; you can redistribute it and/or modify |
13 | * it under the terms of the GNU Library General Public License as |
14 | * published by the Free Software Foundation; either version 2 of the |
15 | * License, or (at your option) any later version. |
45c0fd36 |
16 | * |
d03ab969 |
17 | * Catacomb is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | * GNU Library General Public License for more details. |
45c0fd36 |
21 | * |
d03ab969 |
22 | * You should have received a copy of the GNU Library General Public |
23 | * License along with Catacomb; if not, write to the Free |
24 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
25 | * MA 02111-1307, USA. |
26 | */ |
27 | |
79ba130c |
28 | #ifndef CATACOMB_ECB_H |
29 | #define CATACOMB_ECB_H |
d03ab969 |
30 | |
31 | #ifdef __cplusplus |
32 | extern "C" { |
33 | #endif |
34 | |
35 | /*----- Header files ------------------------------------------------------*/ |
36 | |
79ba130c |
37 | #include <stddef.h> |
d03ab969 |
38 | |
79ba130c |
39 | #ifndef CATACOMB_GCIPHER_H |
40 | # include "gcipher.h" |
d03ab969 |
41 | #endif |
42 | |
43 | /*----- Macros ------------------------------------------------------------*/ |
44 | |
45 | /* --- @ECB_DECL@ --- * |
46 | * |
47 | * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher |
48 | * |
49 | * Use: Creates declarations for ECB stealing mode. |
50 | */ |
51 | |
52 | #define ECB_DECL(PRE, pre) \ |
53 | \ |
79ba130c |
54 | /* --- Electronic codebook context --- */ \ |
d03ab969 |
55 | \ |
79ba130c |
56 | typedef struct pre##_ecbctx { \ |
57 | pre##_ctx ctx; /* Underlying cipher context */ \ |
58 | } pre##_ecbctx; \ |
d03ab969 |
59 | \ |
60 | /* --- @pre_ecbsetkey@ --- * \ |
61 | * \ |
62 | * Arguments: @pre_ecbctx *ctx@ = pointer to ECB context block \ |
63 | * @const pre_ctx *k@ = pointer to cipher context \ |
64 | * \ |
65 | * Returns: --- \ |
66 | * \ |
67 | * Use: Sets the ECB context to use a different cipher key. \ |
68 | */ \ |
69 | \ |
79ba130c |
70 | extern void pre##_ecbsetkey(pre##_ecbctx */*ctx*/, \ |
71 | const pre##_ctx */*k*/); \ |
d03ab969 |
72 | \ |
73 | /* --- @pre_ecbinit@ --- * \ |
74 | * \ |
75 | * Arguments: @pre_ecbctx *ctx@ = pointer to cipher context \ |
76 | * @const void *key@ = pointer to the key buffer \ |
77 | * @size_t sz@ = size of the key \ |
78 | * @const void *iv@ = pointer to initialization vector \ |
79 | * \ |
80 | * Returns: --- \ |
81 | * \ |
82 | * Use: Initializes an ECB context ready for use. This is \ |
83 | * equivalent to calls to @pre_init@ and @pre_setkey@. \ |
84 | */ \ |
85 | \ |
79ba130c |
86 | extern void pre##_ecbinit(pre##_ecbctx */*ctx*/, \ |
87 | const void */*key*/, size_t /*sz*/, \ |
88 | const void */*iv*/); \ |
d03ab969 |
89 | \ |
90 | /* --- @pre_ecbencrypt@ --- * \ |
91 | * \ |
92 | * Arguments: @pre_ecbctx *ctx@ = pointer to ECB context block \ |
93 | * @const void *src@ = pointer to source data \ |
94 | * @void *dest@ = pointer to destination data \ |
95 | * @size_t sz@ = size of block to be encrypted \ |
96 | * \ |
97 | * Returns: --- \ |
98 | * \ |
99 | * Use: Encrypts a block with a block cipher in ECB mode, with \ |
100 | * ciphertext stealing and other clever tricks. \ |
101 | * Essentially, data can be encrypted in arbitrary sized \ |
102 | * chunks, although decryption must use the same chunks. \ |
103 | */ \ |
104 | \ |
79ba130c |
105 | extern void pre##_ecbencrypt(pre##_ecbctx */*ctx*/, \ |
106 | const void */*src*/, void */*dest*/, \ |
107 | size_t /*sz*/); \ |
d03ab969 |
108 | \ |
109 | /* --- @pre_ecbdecrypt@ --- * \ |
110 | * \ |
111 | * Arguments: @pre_ecbctx *ctx@ = pointer to ECB context block \ |
112 | * @const void *src@ = pointer to source data \ |
113 | * @void *dest@ = pointer to destination data \ |
114 | * @size_t sz@ = size of block to be encrypted \ |
115 | * \ |
116 | * Returns: --- \ |
117 | * \ |
79ba130c |
118 | * Use: Decrypts a block with a block cipher in ECB mode, with \ |
d03ab969 |
119 | * ciphertext stealing and other clever tricks. \ |
120 | * Essentially, data can be encrypted in arbitrary sized \ |
121 | * chunks, although decryption must use the same chunks. \ |
122 | */ \ |
123 | \ |
79ba130c |
124 | extern void pre##_ecbdecrypt(pre##_ecbctx */*ctx*/, \ |
125 | const void */*src*/, void */*dest*/, \ |
126 | size_t /*sz*/); \ |
d03ab969 |
127 | \ |
79ba130c |
128 | /* --- Generic cipher interface --- */ \ |
d03ab969 |
129 | \ |
79ba130c |
130 | extern const gccipher pre##_ecb; |
d03ab969 |
131 | |
132 | /*----- That's all, folks -------------------------------------------------*/ |
133 | |
134 | #ifdef __cplusplus |
135 | } |
136 | #endif |
137 | |
138 | #endif |