| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id: cast128.h,v 1.1 2000/06/17 10:49:14 mdw Exp $ |
| 4 | * |
| 5 | * The CAST-128 block cipher |
| 6 | * |
| 7 | * (c) 2000 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: cast128.h,v $ |
| 33 | * Revision 1.1 2000/06/17 10:49:14 mdw |
| 34 | * New cipher. |
| 35 | * |
| 36 | */ |
| 37 | |
| 38 | /*----- Notes on the CAST-128 block cipher --------------------------------* |
| 39 | * |
| 40 | * CAST, designed by Carlisle Adams and Stafford Tavares, is a method for |
| 41 | * designing block ciphers, based around the concept of `bent functions'. It |
| 42 | * is described in the paper `Constructing Symmetric Ciphers using the CAST |
| 43 | * Design Procedure' by Carlisle Adams. |
| 44 | * |
| 45 | * CAST-128, defined in RFC2144, is a particular instance of the CAST design |
| 46 | * procedure, The cipher seems strong and fairly quick. The design procedure |
| 47 | * itself is patented, although the cipher CAST-128 is free to use. |
| 48 | * |
| 49 | * Although CAST ciphers are resistant to differential and linear |
| 50 | * cryptanalysis, some instances have been broken by more advanced techniques |
| 51 | * -- the CAST procedure does not guarantee a strong cipher. However, |
| 52 | * CAST-128 has so far resisted all attacks against it, and has now been |
| 53 | * accepted by the Canadian government for protection of all `Designated' |
| 54 | * material. |
| 55 | */ |
| 56 | |
| 57 | #ifndef CATACOMB_CAST128_H |
| 58 | #define CATACOMB_CAST128_H |
| 59 | |
| 60 | #ifdef __cplusplus |
| 61 | extern "C" { |
| 62 | #endif |
| 63 | |
| 64 | /*----- Header files ------------------------------------------------------*/ |
| 65 | |
| 66 | #include <mLib/bits.h> |
| 67 | |
| 68 | /*----- Magic numbers -----------------------------------------------------*/ |
| 69 | |
| 70 | #define CAST128_BLKSZ 8 |
| 71 | #define CAST128_KEYSZ 16 |
| 72 | #define CAST128_CLASS (N, B, 64) |
| 73 | |
| 74 | extern const octet cast128_keysz[]; |
| 75 | |
| 76 | /*----- Data structures ---------------------------------------------------*/ |
| 77 | |
| 78 | typedef struct cast128_ctx { |
| 79 | unsigned r; |
| 80 | uint32 km[16]; |
| 81 | octet kr[16]; |
| 82 | } cast128_ctx; |
| 83 | |
| 84 | /*----- Functions provided ------------------------------------------------*/ |
| 85 | |
| 86 | /* --- @cast128_init@ --- * |
| 87 | * |
| 88 | * Arguments: @cast128_ctx *k@ = pointer to key block to fill in |
| 89 | * @const void *buf@ = pointer to buffer of key material |
| 90 | * @size_t sz@ = size of key material |
| 91 | * |
| 92 | * Returns: --- |
| 93 | * |
| 94 | * Use: Initializes a CAST-128 key buffer. CAST-128 accepts |
| 95 | * 128-bit keys or shorter. |
| 96 | */ |
| 97 | |
| 98 | extern void cast128_init(cast128_ctx */*k*/, |
| 99 | const void */*buf*/, size_t /*sz*/); |
| 100 | |
| 101 | /* --- @cast128_eblk@, @cast128_dblk@ --- * |
| 102 | * |
| 103 | * Arguments: @const cast128_ctx *k@ = pointer to key block |
| 104 | * @const uint32 s[2]@ = pointer to source block |
| 105 | * @uint32 d[2]@ = pointer to destination block |
| 106 | * |
| 107 | * Returns: --- |
| 108 | * |
| 109 | * Use: Low-level block encryption and decryption. |
| 110 | */ |
| 111 | |
| 112 | extern void cast128_eblk(const cast128_ctx */*k*/, |
| 113 | const uint32 */*s*/, uint32 */*d*/); |
| 114 | |
| 115 | extern void cast128_dblk(const cast128_ctx */*k*/, |
| 116 | const uint32 */*s*/, uint32 */*d*/); |
| 117 | |
| 118 | /*----- That's all, folks -------------------------------------------------*/ |
| 119 | |
| 120 | #ifdef __cplusplus |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | #endif |