ea937a0e |
1 | /* -*-c-*- |
2 | * |
d36cd240 |
3 | * $Id: xtea.h,v 1.3 2000/07/29 09:56:47 mdw Exp $ |
ea937a0e |
4 | * |
ffd4d6a3 |
5 | * The Extended Tiny Encryption Algorithm |
ea937a0e |
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: xtea.h,v $ |
d36cd240 |
33 | * Revision 1.3 2000/07/29 09:56:47 mdw |
34 | * Allow the number of rounds to be configured. This isn't exported |
35 | * through the gcipher interface, but it may be useful anyway. |
36 | * |
ffd4d6a3 |
37 | * Revision 1.2 2000/07/15 13:47:14 mdw |
38 | * Whoops. Fix the purpose comment. |
39 | * |
ea937a0e |
40 | * Revision 1.1 2000/07/15 13:44:31 mdw |
41 | * New ciphers. |
42 | * |
43 | */ |
44 | |
45 | /*----- Notes on the Tiny Encryption Algorithm ----------------------------* |
46 | * |
47 | * XTEA is an amazingly simple 64-round Feistel network. It's tiny, fairly |
48 | * quick and surprisingly strong. It was invented by David Wheeler and Roger |
49 | * Needham. It's unpatented. XTEA is a new version of TEA, by the same |
50 | * designers, which fixes some weaknesses in TEA's key schedule. |
51 | * |
52 | * This implementation uses big-endian byte order, following SCAN. |
53 | */ |
54 | |
55 | #ifndef CATACOMB_XTEA_H |
56 | #define CATACOMB_XTEA_H |
57 | |
58 | #ifdef __cplusplus |
59 | extern "C" { |
60 | #endif |
61 | |
62 | /*----- Header files ------------------------------------------------------*/ |
63 | |
64 | #include <stddef.h> |
65 | |
66 | #include <mLib/bits.h> |
67 | |
68 | /*----- Magical numbers ---------------------------------------------------*/ |
69 | |
70 | #define XTEA_BLKSZ 8 |
71 | #define XTEA_KEYSZ 16 |
72 | #define XTEA_CLASS (N, B, 64) |
73 | |
74 | extern const octet xtea_keysz[]; |
75 | |
76 | /*----- Data structures ---------------------------------------------------*/ |
77 | |
78 | typedef struct xtea_ctx { |
d36cd240 |
79 | unsigned r; |
ea937a0e |
80 | uint32 k[4]; |
81 | } xtea_ctx; |
82 | |
83 | /*----- Functions provided ------------------------------------------------*/ |
84 | |
85 | /* --- @xtea_init@ --- * |
86 | * |
87 | * Arguments: @xtea_ctx *k@ = pointer to key block |
88 | * @const void *buf@ = pointer to key buffer |
89 | * @size_t sz@ = size of key material |
90 | * |
91 | * Returns: --- |
92 | * |
93 | * Use: Initializes an XTEA key buffer. The key buffer may be up to |
94 | * 16 bytes long. |
95 | */ |
96 | |
97 | extern void xtea_init(xtea_ctx */*k*/, const void */*buf*/, size_t /*sz*/); |
98 | |
99 | /* --- @xtea_eblk@, @xtea_dblk@ --- * |
100 | * |
101 | * Arguments: @const xtea_ctx *k@ = pointer to key block |
102 | * @const uint32 s[2]@ = pointer to source block |
103 | * @uint32 d[2]@ = pointer to xteatination block |
104 | * |
105 | * Returns: --- |
106 | * |
107 | * Use: Low-level block encryption and decryption. |
108 | */ |
109 | |
110 | extern void xtea_eblk(const xtea_ctx */*k*/, |
111 | const uint32 */*s*/, uint32 */*d*/); |
112 | extern void xtea_dblk(const xtea_ctx */*k*/, |
113 | const uint32 */*s*/, uint32 */*d*/); |
114 | |
115 | /*----- That's all, folks -------------------------------------------------*/ |
116 | |
117 | #ifdef __cplusplus |
118 | } |
119 | #endif |
120 | |
121 | #endif |