| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * The Tiny Encryption Algorithm |
| 4 | * |
| 5 | * (c) 2000 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 | /*----- Notes on the Tiny Encryption Algorithm ----------------------------* |
| 29 | * |
| 30 | * TEA is an amazingly simple 64-round Feistel network. It's tiny, fairly |
| 31 | * quick and surprisingly strong. It was invented by David Wheeler and Roger |
| 32 | * Needham. It's unpatented. The keyspace is has only 126 effective bits, |
| 33 | * and there are related-key attacks. If you want these fixed, use XTEA. |
| 34 | * |
| 35 | * This implementation uses big-endian byte order, following SCAN. |
| 36 | */ |
| 37 | |
| 38 | #ifndef CATACOMB_TEA_H |
| 39 | #define CATACOMB_TEA_H |
| 40 | |
| 41 | #ifdef __cplusplus |
| 42 | extern "C" { |
| 43 | #endif |
| 44 | |
| 45 | /*----- Header files ------------------------------------------------------*/ |
| 46 | |
| 47 | #include <stddef.h> |
| 48 | |
| 49 | #include <mLib/bits.h> |
| 50 | |
| 51 | /*----- Magical numbers ---------------------------------------------------*/ |
| 52 | |
| 53 | #define TEA_BLKSZ 8 |
| 54 | #define TEA_KEYSZ 16 |
| 55 | #define TEA_CLASS (N, B, 64) |
| 56 | |
| 57 | extern const octet tea_keysz[]; |
| 58 | |
| 59 | /*----- Data structures ---------------------------------------------------*/ |
| 60 | |
| 61 | typedef struct tea_ctx { |
| 62 | unsigned r; |
| 63 | uint32 ka, kb, kc, kd; |
| 64 | } tea_ctx; |
| 65 | |
| 66 | /*----- Functions provided ------------------------------------------------*/ |
| 67 | |
| 68 | /* --- @tea_init@ --- * |
| 69 | * |
| 70 | * Arguments: @tea_ctx *k@ = pointer to key block |
| 71 | * @const void *buf@ = pointer to key buffer |
| 72 | * @size_t sz@ = size of key material |
| 73 | * |
| 74 | * Returns: --- |
| 75 | * |
| 76 | * Use: Initializes a TEA key buffer. The key buffer may be up to 16 |
| 77 | * bytes long. |
| 78 | */ |
| 79 | |
| 80 | extern void tea_init(tea_ctx */*k*/, const void */*buf*/, size_t /*sz*/); |
| 81 | |
| 82 | /* --- @tea_eblk@, @tea_dblk@ --- * |
| 83 | * |
| 84 | * Arguments: @const tea_ctx *k@ = pointer to key block |
| 85 | * @const uint32 s[2]@ = pointer to source block |
| 86 | * @uint32 d[2]@ = pointer to teatination block |
| 87 | * |
| 88 | * Returns: --- |
| 89 | * |
| 90 | * Use: Low-level block encryption and decryption. |
| 91 | */ |
| 92 | |
| 93 | extern void tea_eblk(const tea_ctx */*k*/, |
| 94 | const uint32 */*s*/, uint32 */*d*/); |
| 95 | extern void tea_dblk(const tea_ctx */*k*/, |
| 96 | const uint32 */*s*/, uint32 */*d*/); |
| 97 | |
| 98 | /*----- That's all, folks -------------------------------------------------*/ |
| 99 | |
| 100 | #ifdef __cplusplus |
| 101 | } |
| 102 | #endif |
| 103 | |
| 104 | #endif |