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