Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /* serpent.h
0002 
0003    The serpent block cipher.
0004 
0005    Copyright (C) 2001 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 /* Serpent is a 128-bit block cipher that accepts a key size of 256
0035  * bits, designed by Ross Anderson, Eli Biham, and Lars Knudsen. See
0036  * http://www.cl.cam.ac.uk/~rja14/serpent.html for details.
0037  */
0038 
0039 #ifndef NETTLE_SERPENT_H_INCLUDED
0040 #define NETTLE_SERPENT_H_INCLUDED
0041 
0042 #include "nettle-types.h"
0043 
0044 #ifdef __cplusplus
0045 extern "C" {
0046 #endif
0047 
0048 /* Name mangling */
0049 #define serpent_set_key nettle_serpent_set_key
0050 #define serpent128_set_key nettle_serpent128_set_key
0051 #define serpent192_set_key nettle_serpent192_set_key
0052 #define serpent256_set_key nettle_serpent256_set_key
0053 #define serpent_encrypt nettle_serpent_encrypt
0054 #define serpent_decrypt nettle_serpent_decrypt
0055 
0056 #define SERPENT_BLOCK_SIZE 16
0057 
0058 /* Other key lengths are possible, but the design of Serpent makes
0059  * smaller key lengths quite pointless; they cheated with the AES
0060  * requirements, using a 256-bit key length exclusively and just
0061  * padding it out if the desired key length was less, so there really
0062  * is no advantage to using key lengths less than 256 bits. */
0063 #define SERPENT_KEY_SIZE 32
0064 
0065 /* Allow keys of size 128 <= bits <= 256 */
0066 
0067 #define SERPENT_MIN_KEY_SIZE 16
0068 #define SERPENT_MAX_KEY_SIZE 32
0069 
0070 #define SERPENT128_KEY_SIZE 16
0071 #define SERPENT192_KEY_SIZE 24
0072 #define SERPENT256_KEY_SIZE 32
0073 
0074 struct serpent_ctx
0075 {
0076   uint32_t keys[33][4];  /* key schedule */
0077 };
0078 
0079 void
0080 serpent_set_key(struct serpent_ctx *ctx,
0081                 size_t length, const uint8_t *key);
0082 void
0083 serpent128_set_key(struct serpent_ctx *ctx, const uint8_t *key);
0084 void
0085 serpent192_set_key(struct serpent_ctx *ctx, const uint8_t *key);
0086 void
0087 serpent256_set_key(struct serpent_ctx *ctx, const uint8_t *key);
0088 
0089 void
0090 serpent_encrypt(const struct serpent_ctx *ctx,
0091                 size_t length, uint8_t *dst,
0092                 const uint8_t *src);
0093 void
0094 serpent_decrypt(const struct serpent_ctx *ctx,
0095                 size_t length, uint8_t *dst,
0096                 const uint8_t *src);
0097 
0098 #ifdef __cplusplus
0099 }
0100 #endif
0101 
0102 #endif /* NETTLE_SERPENT_H_INCLUDED */