| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * Electronic code book for block ciphers |
| 4 | * |
| 5 | * (c) 1999 Straylight/Edgeware |
| 6 | */ |
| 7 | |
| 8 | /*----- Licensing notice --------------------------------------------------* |
| 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. |
| 16 | * |
| 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. |
| 21 | * |
| 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 | |
| 28 | #ifndef CATACOMB_ECB_H |
| 29 | #define CATACOMB_ECB_H |
| 30 | |
| 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
| 35 | /*----- Header files ------------------------------------------------------*/ |
| 36 | |
| 37 | #include <stddef.h> |
| 38 | |
| 39 | #ifndef CATACOMB_GCIPHER_H |
| 40 | # include "gcipher.h" |
| 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 | \ |
| 54 | /* --- Electronic codebook context --- */ \ |
| 55 | \ |
| 56 | typedef struct pre##_ecbctx { \ |
| 57 | pre##_ctx ctx; /* Underlying cipher context */ \ |
| 58 | } pre##_ecbctx; \ |
| 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 | \ |
| 70 | extern void pre##_ecbsetkey(pre##_ecbctx */*ctx*/, \ |
| 71 | const pre##_ctx */*k*/); \ |
| 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 | \ |
| 86 | extern void pre##_ecbinit(pre##_ecbctx */*ctx*/, \ |
| 87 | const void */*key*/, size_t /*sz*/, \ |
| 88 | const void */*iv*/); \ |
| 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 | \ |
| 105 | extern void pre##_ecbencrypt(pre##_ecbctx */*ctx*/, \ |
| 106 | const void */*src*/, void */*dest*/, \ |
| 107 | size_t /*sz*/); \ |
| 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 | * \ |
| 118 | * Use: Decrypts a block with a block cipher in ECB mode, with \ |
| 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 | \ |
| 124 | extern void pre##_ecbdecrypt(pre##_ecbctx */*ctx*/, \ |
| 125 | const void */*src*/, void */*dest*/, \ |
| 126 | size_t /*sz*/); \ |
| 127 | \ |
| 128 | /* --- Generic cipher interface --- */ \ |
| 129 | \ |
| 130 | extern const gccipher pre##_ecb; |
| 131 | |
| 132 | /*----- That's all, folks -------------------------------------------------*/ |
| 133 | |
| 134 | #ifdef __cplusplus |
| 135 | } |
| 136 | #endif |
| 137 | |
| 138 | #endif |