| 1 | /* twofish.h |
| 2 | |
| 3 | The twofish block cipher. |
| 4 | |
| 5 | Copyright (C) 2001, 2014 Niels Möller |
| 6 | |
| 7 | This file is part of GNU Nettle. |
| 8 | |
| 9 | GNU Nettle is free software: you can redistribute it and/or |
| 10 | modify it under the terms of either: |
| 11 | |
| 12 | * the GNU Lesser General Public License as published by the Free |
| 13 | Software Foundation; either version 3 of the License, or (at your |
| 14 | option) any later version. |
| 15 | |
| 16 | or |
| 17 | |
| 18 | * the GNU General Public License as published by the Free |
| 19 | Software Foundation; either version 2 of the License, or (at your |
| 20 | option) any later version. |
| 21 | |
| 22 | or both in parallel, as here. |
| 23 | |
| 24 | GNU Nettle is distributed in the hope that it will be useful, |
| 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 27 | General Public License for more details. |
| 28 | |
| 29 | You should have received copies of the GNU General Public License and |
| 30 | the GNU Lesser General Public License along with this program. If |
| 31 | not, see http://www.gnu.org/licenses/. |
| 32 | */ |
| 33 | |
| 34 | /* |
| 35 | * Twofish is a 128-bit block cipher that accepts a variable-length |
| 36 | * key up to 256 bits, designed by Bruce Schneier and others. See |
| 37 | * http://www.counterpane.com/twofish.html for details. |
| 38 | */ |
| 39 | |
| 40 | #ifndef NETTLE_TWOFISH_H_INCLUDED |
| 41 | #define NETTLE_TWOFISH_H_INCLUDED |
| 42 | |
| 43 | #include "nettle-types.h" |
| 44 | |
| 45 | #ifdef __cplusplus |
| 46 | extern "C" { |
| 47 | #endif |
| 48 | |
| 49 | /* Name mangling */ |
| 50 | #define twofish_set_key nettle_twofish_set_key |
| 51 | #define twofish128_set_key nettle_twofish128_set_key |
| 52 | #define twofish192_set_key nettle_twofish192_set_key |
| 53 | #define twofish256_set_key nettle_twofish256_set_key |
| 54 | #define twofish_encrypt nettle_twofish_encrypt |
| 55 | #define twofish_decrypt nettle_twofish_decrypt |
| 56 | |
| 57 | #define TWOFISH_BLOCK_SIZE 16 |
| 58 | |
| 59 | /* Variable key size between 128 and 256 bits. But the only valid |
| 60 | * values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */ |
| 61 | #define TWOFISH_MIN_KEY_SIZE 16 |
| 62 | #define TWOFISH_MAX_KEY_SIZE 32 |
| 63 | |
| 64 | #define TWOFISH_KEY_SIZE 32 |
| 65 | #define TWOFISH128_KEY_SIZE 16 |
| 66 | #define TWOFISH192_KEY_SIZE 24 |
| 67 | #define TWOFISH256_KEY_SIZE 32 |
| 68 | |
| 69 | struct twofish_ctx |
| 70 | { |
| 71 | uint32_t keys[40]; |
| 72 | uint32_t s_box[4][256]; |
| 73 | }; |
| 74 | |
| 75 | void |
| 76 | twofish_set_key(struct twofish_ctx *ctx, |
| 77 | size_t length, const uint8_t *key); |
| 78 | void |
| 79 | twofish128_set_key(struct twofish_ctx *context, const uint8_t *key); |
| 80 | void |
| 81 | twofish192_set_key(struct twofish_ctx *context, const uint8_t *key); |
| 82 | void |
| 83 | twofish256_set_key(struct twofish_ctx *context, const uint8_t *key); |
| 84 | |
| 85 | void |
| 86 | twofish_encrypt(const struct twofish_ctx *ctx, |
| 87 | size_t length, uint8_t *dst, |
| 88 | const uint8_t *src); |
| 89 | void |
| 90 | twofish_decrypt(const struct twofish_ctx *ctx, |
| 91 | size_t length, uint8_t *dst, |
| 92 | const uint8_t *src); |
| 93 | |
| 94 | #ifdef __cplusplus |
| 95 | } |
| 96 | #endif |
| 97 | |
| 98 | #endif /* NETTLE_TWOFISH_H_INCLUDED */ |
| 99 | |