3 Copyright (C) 2006,2007 NTT
4 (Nippon Telegraph and Telephone Corporation).
6 Copyright (C) 2010, 2013 Niels Möller
8 This file is part of GNU Nettle.
10 GNU Nettle is free software: you can redistribute it and/or
11 modify it under the terms of either:
13 * the GNU Lesser General Public License as published by the Free
14 Software Foundation; either version 3 of the License, or (at your
15 option) any later version.
19 * the GNU General Public License as published by the Free
20 Software Foundation; either version 2 of the License, or (at your
21 option) any later version.
23 or both in parallel, as here.
25 GNU Nettle is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 General Public License for more details.
30 You should have received copies of the GNU General Public License and
31 the GNU Lesser General Public License along with this program. If
32 not, see http://www.gnu.org/licenses/.
35 #ifndef NETTLE_CAMELLIA_H_INCLUDED
36 #define NETTLE_CAMELLIA_H_INCLUDED
38 #include "nettle-types.h"
45 #define camellia128_set_encrypt_key nettle_camellia128_set_encrypt_key
46 #define camellia128_set_decrypt_key nettle_camellia_set_decrypt_key
47 #define camellia128_invert_key nettle_camellia128_invert_key
48 #define camellia128_crypt nettle_camellia128_crypt
50 #define camellia192_set_encrypt_key nettle_camellia192_set_encrypt_key
51 #define camellia192_set_decrypt_key nettle_camellia192_set_decrypt_key
53 #define camellia256_set_encrypt_key nettle_camellia256_set_encrypt_key
54 #define camellia256_set_decrypt_key nettle_camellia256_set_decrypt_key
55 #define camellia256_invert_key nettle_camellia256_invert_key
56 #define camellia256_crypt nettle_camellia256_crypt
59 #define CAMELLIA_BLOCK_SIZE 16
60 /* Valid key sizes are 128, 192 or 256 bits (16, 24 or 32 bytes) */
61 #define CAMELLIA128_KEY_SIZE 16
62 #define CAMELLIA192_KEY_SIZE 24
63 #define CAMELLIA256_KEY_SIZE 32
65 /* For 128-bit keys, there are 18 regular rounds, pre- and
66 post-whitening, and two FL and FLINV rounds, using a total of 26
67 subkeys, each of 64 bit. For 192- and 256-bit keys, there are 6
68 additional regular rounds and one additional FL and FLINV, using a
69 total of 34 subkeys. */
70 /* The clever combination of subkeys imply one of the pre- and
71 post-whitening keys is folded with the round keys, so that subkey
72 #1 and the last one (#25 or #33) is not used. The result is that we
73 have only 24 or 32 subkeys at the end of key setup. */
75 #define _CAMELLIA128_NKEYS 24
76 #define _CAMELLIA256_NKEYS 32
78 struct camellia128_ctx
80 uint64_t keys[_CAMELLIA128_NKEYS];
84 camellia128_set_encrypt_key(struct camellia128_ctx *ctx,
88 camellia128_set_decrypt_key(struct camellia128_ctx *ctx,
92 camellia128_invert_key(struct camellia128_ctx *dst,
93 const struct camellia128_ctx *src);
96 camellia128_crypt(const struct camellia128_ctx *ctx,
97 size_t length, uint8_t *dst,
100 struct camellia256_ctx
102 uint64_t keys[_CAMELLIA256_NKEYS];
106 camellia256_set_encrypt_key(struct camellia256_ctx *ctx,
110 camellia256_set_decrypt_key(struct camellia256_ctx *ctx,
114 camellia256_invert_key(struct camellia256_ctx *dst,
115 const struct camellia256_ctx *src);
118 camellia256_crypt(const struct camellia256_ctx *ctx,
119 size_t length, uint8_t *dst,
122 /* camellia192 is the same as camellia256, except for the key
124 /* Slightly ugly with a #define on a struct tag, since it might cause
125 surprises if also used as a name of a variable. */
126 #define camellia192_ctx camellia256_ctx
129 camellia192_set_encrypt_key(struct camellia256_ctx *ctx,
133 camellia192_set_decrypt_key(struct camellia256_ctx *ctx,
136 #define camellia192_invert_key camellia256_invert_key
137 #define camellia192_crypt camellia256_crypt
143 #endif /* NETTLE_CAMELLIA_H_INCLUDED */