tizen 2.4 release
[external/nettle.git] / twofish.h
1 /* twofish.h
2  *
3  * The twofish block cipher.
4  */
5
6 /* nettle, low-level cryptographics library
7  *
8  * Copyright (C) 2001 Niels Möller
9  *  
10  * The nettle library is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or (at your
13  * option) any later version.
14  * 
15  * The nettle library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
18  * License for more details.
19  * 
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with the nettle library; see the file COPYING.LIB.  If not, write to
22  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23  * MA 02111-1301, USA.
24  */
25
26 /*
27  * Twofish is a 128-bit block cipher that accepts a variable-length
28  * key up to 256 bits, designed by Bruce Schneier and others.  See
29  * http://www.counterpane.com/twofish.html for details.
30  */
31
32 #ifndef NETTLE_TWOFISH_H_INCLUDED
33 #define NETTLE_TWOFISH_H_INCLUDED
34
35 #include "nettle-types.h"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /* Name mangling */
42 #define twofish_set_key nettle_twofish_set_key
43 #define twofish_encrypt nettle_twofish_encrypt
44 #define twofish_decrypt nettle_twofish_decrypt
45
46 #define TWOFISH_BLOCK_SIZE 16
47
48 /* Variable key size between 128 and 256 bits. But the only valid
49  * values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */
50 #define TWOFISH_MIN_KEY_SIZE 16
51 #define TWOFISH_MAX_KEY_SIZE 32
52
53 #define TWOFISH_KEY_SIZE 32
54
55 struct twofish_ctx
56 {
57   uint32_t keys[40];
58   uint32_t s_box[4][256];
59 };
60
61 void
62 twofish_set_key(struct twofish_ctx *ctx,
63                 unsigned length, const uint8_t *key);
64
65 void
66 twofish_encrypt(const struct twofish_ctx *ctx,
67                 unsigned length, uint8_t *dst,
68                 const uint8_t *src);
69 void
70 twofish_decrypt(const struct twofish_ctx *ctx,
71                 unsigned length, uint8_t *dst,
72                 const uint8_t *src);
73
74 #ifdef __cplusplus
75 }
76 #endif
77
78 #endif /* NETTLE_TWOFISH_H_INCLUDED */