Commit | Line | Data |
---|---|---|
ea937a0e | 1 | /* -*-c-*- |
2 | * | |
b817bfc6 | 3 | * $Id: xtea.h,v 1.4 2004/04/08 01:36:15 mdw Exp $ |
ea937a0e | 4 | * |
ffd4d6a3 | 5 | * The Extended Tiny Encryption Algorithm |
ea937a0e | 6 | * |
7 | * (c) 2000 Straylight/Edgeware | |
8 | */ | |
9 | ||
45c0fd36 | 10 | /*----- Licensing notice --------------------------------------------------* |
ea937a0e | 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. | |
45c0fd36 | 18 | * |
ea937a0e | 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. | |
45c0fd36 | 23 | * |
ea937a0e | 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 | ||
ea937a0e | 30 | /*----- Notes on the Tiny Encryption Algorithm ----------------------------* |
31 | * | |
32 | * XTEA is an amazingly simple 64-round Feistel network. It's tiny, fairly | |
33 | * quick and surprisingly strong. It was invented by David Wheeler and Roger | |
34 | * Needham. It's unpatented. XTEA is a new version of TEA, by the same | |
35 | * designers, which fixes some weaknesses in TEA's key schedule. | |
36 | * | |
37 | * This implementation uses big-endian byte order, following SCAN. | |
38 | */ | |
39 | ||
40 | #ifndef CATACOMB_XTEA_H | |
41 | #define CATACOMB_XTEA_H | |
42 | ||
43 | #ifdef __cplusplus | |
44 | extern "C" { | |
45 | #endif | |
46 | ||
47 | /*----- Header files ------------------------------------------------------*/ | |
48 | ||
49 | #include <stddef.h> | |
50 | ||
51 | #include <mLib/bits.h> | |
52 | ||
53 | /*----- Magical numbers ---------------------------------------------------*/ | |
54 | ||
55 | #define XTEA_BLKSZ 8 | |
56 | #define XTEA_KEYSZ 16 | |
57 | #define XTEA_CLASS (N, B, 64) | |
58 | ||
59 | extern const octet xtea_keysz[]; | |
60 | ||
61 | /*----- Data structures ---------------------------------------------------*/ | |
62 | ||
63 | typedef struct xtea_ctx { | |
d36cd240 | 64 | unsigned r; |
ea937a0e | 65 | uint32 k[4]; |
66 | } xtea_ctx; | |
67 | ||
68 | /*----- Functions provided ------------------------------------------------*/ | |
69 | ||
70 | /* --- @xtea_init@ --- * | |
71 | * | |
45c0fd36 MW |
72 | * Arguments: @xtea_ctx *k@ = pointer to key block |
73 | * @const void *buf@ = pointer to key buffer | |
74 | * @size_t sz@ = size of key material | |
ea937a0e | 75 | * |
45c0fd36 | 76 | * Returns: --- |
ea937a0e | 77 | * |
45c0fd36 | 78 | * Use: Initializes an XTEA key buffer. The key buffer may be up to |
ea937a0e | 79 | * 16 bytes long. |
80 | */ | |
81 | ||
82 | extern void xtea_init(xtea_ctx */*k*/, const void */*buf*/, size_t /*sz*/); | |
83 | ||
84 | /* --- @xtea_eblk@, @xtea_dblk@ --- * | |
85 | * | |
45c0fd36 MW |
86 | * Arguments: @const xtea_ctx *k@ = pointer to key block |
87 | * @const uint32 s[2]@ = pointer to source block | |
88 | * @uint32 d[2]@ = pointer to xteatination block | |
ea937a0e | 89 | * |
45c0fd36 | 90 | * Returns: --- |
ea937a0e | 91 | * |
45c0fd36 | 92 | * Use: Low-level block encryption and decryption. |
ea937a0e | 93 | */ |
94 | ||
95 | extern void xtea_eblk(const xtea_ctx */*k*/, | |
96 | const uint32 */*s*/, uint32 */*d*/); | |
97 | extern void xtea_dblk(const xtea_ctx */*k*/, | |
98 | const uint32 */*s*/, uint32 */*d*/); | |
99 | ||
100 | /*----- That's all, folks -------------------------------------------------*/ | |
101 | ||
102 | #ifdef __cplusplus | |
103 | } | |
104 | #endif | |
105 | ||
106 | #endif |