Revert "Merge branch 'upstream' into tizen"
[platform/upstream/nettle.git] / camellia.h
1 /* camellia.h
2  *
3  * Copyright (C) 2006,2007
4  * NTT (Nippon Telegraph and Telephone Corporation).
5  *
6  * Copyright (C) 2010 Niels Möller
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef NETTLE_CAMELLIA_H_INCLUDED
24 #define NETTLE_CAMELLIA_H_INCLUDED
25
26 #include "nettle-types.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /* Name mangling */
33 #define camellia_set_encrypt_key nettle_camellia_set_encrypt_key
34 #define camellia_set_decrypt_key nettle_camellia_set_decrypt_key
35 #define camellia_invert_key nettle_camellia_invert_key
36 #define camellia_crypt nettle_camellia_crypt
37 #define camellia_crypt nettle_camellia_crypt
38
39 #define CAMELLIA_BLOCK_SIZE 16
40 /* Valid key sizes are 128, 192 or 256 bits (16, 24 or 32 bytes) */
41 #define CAMELLIA_MIN_KEY_SIZE 16
42 #define CAMELLIA_MAX_KEY_SIZE 32
43 #define CAMELLIA_KEY_SIZE 32
44
45 struct camellia_ctx
46 {
47   /* Number of subkeys. */
48   unsigned nkeys;
49   
50   /* For 128-bit keys, there are 18 regular rounds, pre- and
51      post-whitening, and two FL and FLINV rounds, using a total of 26
52      subkeys, each of 64 bit. For 192- and 256-bit keys, there are 6
53      additional regular rounds and one additional FL and FLINV, using
54      a total of 34 subkeys. */
55   /* The clever combination of subkeys imply one of the pre- and
56      post-whitening keys is folded with the round keys, so that subkey
57      #1 and the last one (#25 or #33) is not used. The result is that
58      we have only 24 or 32 subkeys at the end of key setup. */
59   uint64_t keys[32];
60 };
61
62 void
63 camellia_set_encrypt_key(struct camellia_ctx *ctx,
64                          unsigned length, const uint8_t *key);
65
66 void
67 camellia_set_decrypt_key(struct camellia_ctx *ctx,
68                          unsigned length, const uint8_t *key);
69
70 void
71 camellia_invert_key(struct camellia_ctx *dst,
72                     const struct camellia_ctx *src);
73   
74 void
75 camellia_crypt(const struct camellia_ctx *ctx,
76                unsigned length, uint8_t *dst,
77                const uint8_t *src);
78 #ifdef  __cplusplus
79 }
80 #endif
81
82 #endif /* NETTLE_CAMELLIA_H_INCLUDED */