Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:16

0001 /* twofish.h
0002 
0003    The twofish block cipher.
0004 
0005    Copyright (C) 2001, 2014 Niels Möller
0006 
0007    This file is part of GNU Nettle.
0008 
0009    GNU Nettle is free software: you can redistribute it and/or
0010    modify it under the terms of either:
0011 
0012      * the GNU Lesser General Public License as published by the Free
0013        Software Foundation; either version 3 of the License, or (at your
0014        option) any later version.
0015 
0016    or
0017 
0018      * the GNU General Public License as published by the Free
0019        Software Foundation; either version 2 of the License, or (at your
0020        option) any later version.
0021 
0022    or both in parallel, as here.
0023 
0024    GNU Nettle is distributed in the hope that it will be useful,
0025    but WITHOUT ANY WARRANTY; without even the implied warranty of
0026    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0027    General Public License for more details.
0028 
0029    You should have received copies of the GNU General Public License and
0030    the GNU Lesser General Public License along with this program.  If
0031    not, see http://www.gnu.org/licenses/.
0032 */
0033 
0034 /*
0035  * Twofish is a 128-bit block cipher that accepts a variable-length
0036  * key up to 256 bits, designed by Bruce Schneier and others.  See
0037  * http://www.counterpane.com/twofish.html for details.
0038  */
0039 
0040 #ifndef NETTLE_TWOFISH_H_INCLUDED
0041 #define NETTLE_TWOFISH_H_INCLUDED
0042 
0043 #include "nettle-types.h"
0044 
0045 #ifdef __cplusplus
0046 extern "C" {
0047 #endif
0048 
0049 /* Name mangling */
0050 #define twofish_set_key nettle_twofish_set_key
0051 #define twofish128_set_key nettle_twofish128_set_key
0052 #define twofish192_set_key nettle_twofish192_set_key
0053 #define twofish256_set_key nettle_twofish256_set_key
0054 #define twofish_encrypt nettle_twofish_encrypt
0055 #define twofish_decrypt nettle_twofish_decrypt
0056 
0057 #define TWOFISH_BLOCK_SIZE 16
0058 
0059 /* Variable key size between 128 and 256 bits. But the only valid
0060  * values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */
0061 #define TWOFISH_MIN_KEY_SIZE 16
0062 #define TWOFISH_MAX_KEY_SIZE 32
0063 
0064 #define TWOFISH_KEY_SIZE 32
0065 #define TWOFISH128_KEY_SIZE 16
0066 #define TWOFISH192_KEY_SIZE 24
0067 #define TWOFISH256_KEY_SIZE 32
0068 
0069 struct twofish_ctx
0070 {
0071   uint32_t keys[40];
0072   uint32_t s_box[4][256];
0073 };
0074 
0075 void
0076 twofish_set_key(struct twofish_ctx *ctx,
0077         size_t length, const uint8_t *key);
0078 void
0079 twofish128_set_key(struct twofish_ctx *context, const uint8_t *key);
0080 void
0081 twofish192_set_key(struct twofish_ctx *context, const uint8_t *key);
0082 void
0083 twofish256_set_key(struct twofish_ctx *context, const uint8_t *key);
0084 
0085 void
0086 twofish_encrypt(const struct twofish_ctx *ctx,
0087         size_t length, uint8_t *dst,
0088         const uint8_t *src);
0089 void
0090 twofish_decrypt(const struct twofish_ctx *ctx,
0091         size_t length, uint8_t *dst,
0092         const uint8_t *src);
0093 
0094 #ifdef __cplusplus
0095 }
0096 #endif
0097 
0098 #endif /* NETTLE_TWOFISH_H_INCLUDED */