1 | /* serpent.h |
2 | |
3 | The serpent block cipher. |
4 | |
5 | Copyright (C) 2001 Niels Möller |
6 | |
7 | This file is part of GNU Nettle. |
8 | |
9 | GNU Nettle is free software: you can redistribute it and/or |
10 | modify it under the terms of either: |
11 | |
12 | * the GNU Lesser General Public License as published by the Free |
13 | Software Foundation; either version 3 of the License, or (at your |
14 | option) any later version. |
15 | |
16 | or |
17 | |
18 | * the GNU General Public License as published by the Free |
19 | Software Foundation; either version 2 of the License, or (at your |
20 | option) any later version. |
21 | |
22 | or both in parallel, as here. |
23 | |
24 | GNU Nettle is distributed in the hope that it will be useful, |
25 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
27 | General Public License for more details. |
28 | |
29 | You should have received copies of the GNU General Public License and |
30 | the GNU Lesser General Public License along with this program. If |
31 | not, see http://www.gnu.org/licenses/. |
32 | */ |
33 | |
34 | /* Serpent is a 128-bit block cipher that accepts a key size of 256 |
35 | * bits, designed by Ross Anderson, Eli Biham, and Lars Knudsen. See |
36 | * http://www.cl.cam.ac.uk/~rja14/serpent.html for details. |
37 | */ |
38 | |
39 | #ifndef NETTLE_SERPENT_H_INCLUDED |
40 | #define NETTLE_SERPENT_H_INCLUDED |
41 | |
42 | #include "nettle-types.h" |
43 | |
44 | #ifdef __cplusplus |
45 | extern "C" { |
46 | #endif |
47 | |
48 | /* Name mangling */ |
49 | #define serpent_set_key nettle_serpent_set_key |
50 | #define serpent128_set_key nettle_serpent128_set_key |
51 | #define serpent192_set_key nettle_serpent192_set_key |
52 | #define serpent256_set_key nettle_serpent256_set_key |
53 | #define serpent_encrypt nettle_serpent_encrypt |
54 | #define serpent_decrypt nettle_serpent_decrypt |
55 | |
56 | #define SERPENT_BLOCK_SIZE 16 |
57 | |
58 | /* Other key lengths are possible, but the design of Serpent makes |
59 | * smaller key lengths quite pointless; they cheated with the AES |
60 | * requirements, using a 256-bit key length exclusively and just |
61 | * padding it out if the desired key length was less, so there really |
62 | * is no advantage to using key lengths less than 256 bits. */ |
63 | #define SERPENT_KEY_SIZE 32 |
64 | |
65 | /* Allow keys of size 128 <= bits <= 256 */ |
66 | |
67 | #define SERPENT_MIN_KEY_SIZE 16 |
68 | #define SERPENT_MAX_KEY_SIZE 32 |
69 | |
70 | #define SERPENT128_KEY_SIZE 16 |
71 | #define SERPENT192_KEY_SIZE 24 |
72 | #define SERPENT256_KEY_SIZE 32 |
73 | |
74 | struct serpent_ctx |
75 | { |
76 | uint32_t keys[33][4]; /* key schedule */ |
77 | }; |
78 | |
79 | void |
80 | serpent_set_key(struct serpent_ctx *ctx, |
81 | size_t length, const uint8_t *key); |
82 | void |
83 | serpent128_set_key(struct serpent_ctx *ctx, const uint8_t *key); |
84 | void |
85 | serpent192_set_key(struct serpent_ctx *ctx, const uint8_t *key); |
86 | void |
87 | serpent256_set_key(struct serpent_ctx *ctx, const uint8_t *key); |
88 | |
89 | void |
90 | serpent_encrypt(const struct serpent_ctx *ctx, |
91 | size_t length, uint8_t *dst, |
92 | const uint8_t *src); |
93 | void |
94 | serpent_decrypt(const struct serpent_ctx *ctx, |
95 | size_t length, uint8_t *dst, |
96 | const uint8_t *src); |
97 | |
98 | #ifdef __cplusplus |
99 | } |
100 | #endif |
101 | |
102 | #endif /* NETTLE_SERPENT_H_INCLUDED */ |
103 | |