8dd8c294 |
1 | /* -*-c-*- |
8dd8c294 |
2 | * |
3 | * The Serpent block cipher |
4 | * |
5 | * (c) 2000 Straylight/Edgeware |
6 | */ |
7 | |
45c0fd36 |
8 | /*----- Licensing notice --------------------------------------------------* |
8dd8c294 |
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. |
45c0fd36 |
16 | * |
8dd8c294 |
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. |
45c0fd36 |
21 | * |
8dd8c294 |
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 | |
8dd8c294 |
28 | /*----- Notes on the Serpent block cipher ---------------------------------* |
29 | * |
fbac94e6 |
30 | * Serpent was designed and proposed for the AES contest by Ross Anderson, |
8dd8c294 |
31 | * Eli Biham and Lars Knudsen. It's not particularly quick, but is |
32 | * stunningly secure. The best differential and linear attacks are |
33 | * speculated to require %$2^{256}$% texts (it's a 128-bit block cipher). |
34 | * The designers originally intended to file a patent, but failed to persue |
35 | * it. Use of the algorithm is completely unencumbered. |
36 | */ |
37 | |
38 | #ifndef CATACOMB_SERPENT_H |
39 | #define CATACOMB_SERPENT_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 | /*----- Magic numbers -----------------------------------------------------*/ |
52 | |
53 | #define SERPENT_BLKSZ 16 |
54 | #define SERPENT_KEYSZ 32 |
55 | #define SERPENT_CLASS (N, L, 128) |
56 | |
57 | extern const octet serpent_keysz[]; |
58 | |
59 | /*----- Data structures ---------------------------------------------------*/ |
60 | |
61 | typedef struct serpent_ctx { |
62 | uint32 k[4 * 33]; |
63 | } serpent_ctx; |
64 | |
65 | /*----- Functions provided ------------------------------------------------*/ |
66 | |
67 | /* --- @serpent_init@ --- * |
68 | * |
69 | * Arguments: @serpent_ctx *k@ = pointer to context block to initialize |
70 | * @const void *buf@ = pointer to input buffer |
71 | * @size_t sz@ = size of input buffer |
72 | * |
73 | * Returns: --- |
74 | * |
75 | * Use: Initializes a Serpent context. The key may be any length of |
76 | * up to 32 bytes (256 bits). |
77 | */ |
78 | |
79 | extern void serpent_init(serpent_ctx */*k*/, |
80 | const void */*buf*/, size_t /*sz*/); |
81 | |
82 | /* --- @serpent_eblk@, @serpent_dblk@ --- * |
83 | * |
84 | * Arguments: @const serpent_ctx *k@ = pointer to key context |
85 | * @const uint32 s[4]@ = pointer to source block |
86 | * @uint32 d[4]@ = pointer to destination block |
87 | * |
88 | * Returns: --- |
89 | * |
90 | * Use: Low-level block encryption. |
91 | */ |
92 | |
93 | extern void serpent_eblk(const serpent_ctx */*k*/, |
94 | const uint32 */*s*/, uint32 */*d*/); |
95 | extern void serpent_dblk(const serpent_ctx */*k*/, |
96 | const uint32 */*s*/, uint32 */*d*/); |
97 | |
98 | /*----- That's all, folks -------------------------------------------------*/ |
99 | |
100 | #ifdef __cplusplus |
101 | } |
102 | #endif |
103 | |
104 | #endif |