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