b035db3da9b3ab5961f95ecdeb918e026540c0ac
[platform/upstream/nettle.git] / camellia.h
1 /* camellia.h
2
3    Copyright (C) 2006,2007 NTT
4    (Nippon Telegraph and Telephone Corporation).
5
6    Copyright (C) 2010, 2013 Niels Möller
7
8    This file is part of GNU Nettle.
9
10    GNU Nettle is free software: you can redistribute it and/or
11    modify it under the terms of either:
12
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.
16
17    or
18
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.
22
23    or both in parallel, as here.
24
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.
29
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/.
33 */
34
35 #ifndef NETTLE_CAMELLIA_H_INCLUDED
36 #define NETTLE_CAMELLIA_H_INCLUDED
37
38 #include "nettle-types.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /* Name mangling */
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
49
50 #define camellia192_set_encrypt_key nettle_camellia192_set_encrypt_key
51 #define camellia192_set_decrypt_key nettle_camellia192_set_decrypt_key
52
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
57
58
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
64
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. */
74
75 #define _CAMELLIA128_NKEYS 24
76 #define _CAMELLIA256_NKEYS 32
77
78 struct camellia128_ctx
79 {
80   uint64_t keys[_CAMELLIA128_NKEYS];
81 };
82
83 void
84 camellia128_set_encrypt_key(struct camellia128_ctx *ctx,
85                             const uint8_t *key);
86
87 void
88 camellia128_set_decrypt_key(struct camellia128_ctx *ctx,
89                             const uint8_t *key);
90
91 void
92 camellia128_invert_key(struct camellia128_ctx *dst,
93                        const struct camellia128_ctx *src);
94
95 void
96 camellia128_crypt(const struct camellia128_ctx *ctx,
97                   size_t length, uint8_t *dst,
98                   const uint8_t *src);
99
100 struct camellia256_ctx
101 {
102   uint64_t keys[_CAMELLIA256_NKEYS];
103 };
104
105 void
106 camellia256_set_encrypt_key(struct camellia256_ctx *ctx,
107                             const uint8_t *key);
108
109 void
110 camellia256_set_decrypt_key(struct camellia256_ctx *ctx,
111                             const uint8_t *key);
112
113 void
114 camellia256_invert_key(struct camellia256_ctx *dst,
115                        const struct camellia256_ctx *src);
116
117 void
118 camellia256_crypt(const struct camellia256_ctx *ctx,
119                   size_t length, uint8_t *dst,
120                   const uint8_t *src);
121
122 /* camellia192 is the same as camellia256, except for the key
123    schedule. */
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
127
128 void
129 camellia192_set_encrypt_key(struct camellia256_ctx *ctx,
130                             const uint8_t *key);
131
132 void
133 camellia192_set_decrypt_key(struct camellia256_ctx *ctx,
134                             const uint8_t *key);
135
136 #define camellia192_invert_key camellia256_invert_key
137 #define camellia192_crypt camellia256_crypt
138
139 #ifdef __cplusplus
140 }
141 #endif
142
143 #endif /* NETTLE_CAMELLIA_H_INCLUDED */