3 The camellia block cipher.
5 Copyright (C) 2006,2007 NTT
6 (Nippon Telegraph and Telephone Corporation).
8 Copyright (C) 2010 Niels Möller
10 This file is part of GNU Nettle.
12 GNU Nettle is free software: you can redistribute it and/or
13 modify it under the terms of either:
15 * the GNU Lesser General Public License as published by the Free
16 Software Foundation; either version 3 of the License, or (at your
17 option) any later version.
21 * the GNU General Public License as published by the Free
22 Software Foundation; either version 2 of the License, or (at your
23 option) any later version.
25 or both in parallel, as here.
27 GNU Nettle is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 General Public License for more details.
32 You should have received copies of the GNU General Public License and
33 the GNU Lesser General Public License along with this program. If
34 not, see http://www.gnu.org/licenses/.
38 * Algorithm Specification
39 * http://info.isl.ntt.co.jp/crypt/eng/camellia/specifications.html
42 /* Based on camellia.c ver 1.2.0, see
43 http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/camellia-LGPL-1.2.0.tar.gz.
46 #ifndef NETTLE_CAMELLIA_INTERNAL_H_INCLUDED
47 #define NETTLE_CAMELLIA_INTERNAL_H_INCLUDED
52 #define _camellia_crypt _nettle_camellia_crypt
53 #define _camellia_absorb _nettle_camellia_absorb
54 #define _camellia_invert_key _nettle_camellia_invert_key
55 #define _camellia_table _nettle_camellia_table
61 /* Destructive rotation of 128 bit values. */
62 #define ROTL128(bits, xl, xr) do { \
63 uint64_t __rol128_t = (xl); \
64 (xl) = ((xl) << (bits)) | ((xr) >> (64 - (bits))); \
65 (xr) = ((xr) << (bits)) | (__rol128_t >> (64 - (bits))); \
78 #define SIGMA1 0xA09E667F3BCC908BULL
79 #define SIGMA2 0xB67AE8584CAA73B2ULL
80 #define SIGMA3 0xC6EF372FE94F82BEULL
81 #define SIGMA4 0x54FF53A5F1D36F1CULL
82 #define SIGMA5 0x10E527FADE682D1DULL
83 #define SIGMA6 0xB05688C2B3E6C1FDULL
85 #define CAMELLIA_SP1110(INDEX) (_nettle_camellia_table.sp1110[(int)(INDEX)])
86 #define CAMELLIA_SP0222(INDEX) (_nettle_camellia_table.sp0222[(int)(INDEX)])
87 #define CAMELLIA_SP3033(INDEX) (_nettle_camellia_table.sp3033[(int)(INDEX)])
88 #define CAMELLIA_SP4404(INDEX) (_nettle_camellia_table.sp4404[(int)(INDEX)])
90 #define CAMELLIA_F(x, k, y) do { \
91 uint32_t __yl, __yr; \
92 uint64_t __i = (x) ^ (k); \
94 = CAMELLIA_SP1110( __i & 0xff) \
95 ^ CAMELLIA_SP0222((__i >> 24) & 0xff) \
96 ^ CAMELLIA_SP3033((__i >> 16) & 0xff) \
97 ^ CAMELLIA_SP4404((__i >> 8) & 0xff); \
99 = CAMELLIA_SP1110( __i >> 56) \
100 ^ CAMELLIA_SP0222((__i >> 48) & 0xff) \
101 ^ CAMELLIA_SP3033((__i >> 40) & 0xff) \
102 ^ CAMELLIA_SP4404((__i >> 32) & 0xff); \
104 __yr = ROTL32(24, __yr); \
106 (y) = ((uint64_t) __yl << 32) | __yr; \
109 #if ! HAVE_NATIVE_64_BIT
110 #define CAMELLIA_F_HALF_INV(x) do { \
114 __w = ROTL32(8, __w); \
115 (x) = ((uint64_t) __w << 32) | (__t ^ __w); \
120 _camellia_crypt(unsigned nkeys, const uint64_t *keys,
121 const struct camellia_table *T,
122 size_t length, uint8_t *dst,
125 /* The initial NKEYS + 2 subkeys in SUBKEY are reduced to the final
126 NKEYS subkeys stored in DST. SUBKEY data is modified in the
129 _camellia_absorb(unsigned nkeys, uint64_t *dst, uint64_t *subkey);
132 _camellia_invert_key(unsigned nkeys,
133 uint64_t *dst, const uint64_t *src);
135 extern const struct camellia_table _camellia_table;
137 #endif /* NETTLE_CAMELLIA_INTERNAL_H_INCLUDED */