chiark / gitweb /
b049d74059182a1a66019b9d5e799196ab359f1c
[catacomb] / idea.h
1 /* -*-c-*-
2  *
3  * $Id: idea.h,v 1.4 2004/04/08 01:36:15 mdw Exp $
4  *
5  * Implementation of the IDEA cipher
6  *
7  * (c) 1999 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 IDEA block cipher ------------------------------------*
31  *
32  * IDEA was invented by James Massey and Xuejia Lai.  The fundamental idea
33  * underlying the cipher is combining incompatible group operations.  The
34  * algorithm's main claim to fame is that it is the symmetric cipher in PGP
35  * version 2.
36  *
37  * The IDEA algorithm is allegedly patented by Ascom Tech A.G., even in the
38  * UK and Europe.  Ascom are willing to grant licences for use in software
39  * which forbids commercial use, but this is not compatible with Free
40  * Software Foundation ideology.  The author recommends against the use of
41  * the IDEA cipher entirely.  Blowfish is conceptually simpler, appears more
42  * concervative, offers a larger keyspace, runs faster, and is in the public
43  * domain.
44  */
45
46 #ifndef CATACOMB_IDEA_H
47 #define CATACOMB_IDEA_H
48
49 #ifdef __cplusplus
50   extern "C" {
51 #endif
52
53 /*----- Header files ------------------------------------------------------*/
54
55 #include <stddef.h>
56
57 #include <mLib/bits.h>
58
59 /*----- Magical numbers ---------------------------------------------------*/
60
61 #define IDEA_BLKSZ 8
62 #define IDEA_KEYSZ 16
63 #define IDEA_CLASS (N, B, 64)
64
65 extern const octet idea_keysz[];
66
67 /*----- Data structures ---------------------------------------------------*/
68
69 typedef struct idea_ctx {
70   uint16 e[52];
71   uint16 d[52];
72 } idea_ctx;
73
74 /*----- Functions provided ------------------------------------------------*/
75
76 /* --- @idea_init@ --- *
77  *
78  * Arguments:   @idea_ctx *k@ = pointer to key block
79  *              @const void *buf@ = pointer to key buffer
80  *              @size_t sz@ = size of key material
81  *
82  * Returns:     ---
83  *
84  * Use:         Initializes an IDEA key buffer.  The buffer must be exactly
85  *              16 bytes in size, because IDEA is only defined with a key
86  *              size of 128 bits.
87  */
88
89 extern void idea_init(idea_ctx */*k*/, const void */*buf*/, size_t /*sz*/);
90
91 /* --- @idea_eblk@, @idea_dblk@ --- *
92  *
93  * Arguments:   @const idea_ctx *k@ = pointer to a key block
94  *              @const uint32 s[2]@ = pointer to source block
95  *              @uint32 d[2]@ = pointer to destination block
96  *
97  * Returns:     ---
98  *
99  * Use:         Low-level block encryption and decryption.
100  */
101
102 extern void idea_eblk(const idea_ctx */*k*/,
103                       const uint32 */*s*/, uint32 */*d*/);
104 extern void idea_dblk(const idea_ctx */*k*/,
105                       const uint32 */*s*/, uint32 */*d*/);
106
107 /*----- That's all, folks -------------------------------------------------*/
108
109 #ifdef __cplusplus
110   }
111 #endif
112
113 #endif