Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /* camellia.h
0002 
0003    Copyright (C) 2006,2007 NTT
0004    (Nippon Telegraph and Telephone Corporation).
0005 
0006    Copyright (C) 2010, 2013 Niels Möller
0007 
0008    This file is part of GNU Nettle.
0009 
0010    GNU Nettle is free software: you can redistribute it and/or
0011    modify it under the terms of either:
0012 
0013      * the GNU Lesser General Public License as published by the Free
0014        Software Foundation; either version 3 of the License, or (at your
0015        option) any later version.
0016 
0017    or
0018 
0019      * the GNU General Public License as published by the Free
0020        Software Foundation; either version 2 of the License, or (at your
0021        option) any later version.
0022 
0023    or both in parallel, as here.
0024 
0025    GNU Nettle is distributed in the hope that it will be useful,
0026    but WITHOUT ANY WARRANTY; without even the implied warranty of
0027    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0028    General Public License for more details.
0029 
0030    You should have received copies of the GNU General Public License and
0031    the GNU Lesser General Public License along with this program.  If
0032    not, see http://www.gnu.org/licenses/.
0033 */
0034 
0035 #ifndef NETTLE_CAMELLIA_H_INCLUDED
0036 #define NETTLE_CAMELLIA_H_INCLUDED
0037 
0038 #include "nettle-types.h"
0039 
0040 #ifdef __cplusplus
0041 extern "C" {
0042 #endif
0043 
0044 /* Name mangling */
0045 #define camellia128_set_encrypt_key nettle_camellia128_set_encrypt_key
0046 #define camellia128_set_decrypt_key nettle_camellia_set_decrypt_key
0047 #define camellia128_invert_key nettle_camellia128_invert_key
0048 #define camellia128_crypt nettle_camellia128_crypt
0049 
0050 #define camellia192_set_encrypt_key nettle_camellia192_set_encrypt_key
0051 #define camellia192_set_decrypt_key nettle_camellia192_set_decrypt_key
0052 
0053 #define camellia256_set_encrypt_key nettle_camellia256_set_encrypt_key
0054 #define camellia256_set_decrypt_key nettle_camellia256_set_decrypt_key
0055 #define camellia256_invert_key nettle_camellia256_invert_key
0056 #define camellia256_crypt nettle_camellia256_crypt
0057 
0058 
0059 #define CAMELLIA_BLOCK_SIZE 16
0060 /* Valid key sizes are 128, 192 or 256 bits (16, 24 or 32 bytes) */
0061 #define CAMELLIA128_KEY_SIZE 16
0062 #define CAMELLIA192_KEY_SIZE 24
0063 #define CAMELLIA256_KEY_SIZE 32
0064 
0065 /* For 128-bit keys, there are 18 regular rounds, pre- and
0066    post-whitening, and two FL and FLINV rounds, using a total of 26
0067    subkeys, each of 64 bit. For 192- and 256-bit keys, there are 6
0068    additional regular rounds and one additional FL and FLINV, using a
0069    total of 34 subkeys. */
0070 /* The clever combination of subkeys imply one of the pre- and
0071    post-whitening keys is folded with the round keys, so that subkey
0072    #1 and the last one (#25 or #33) is not used. The result is that we
0073    have only 24 or 32 subkeys at the end of key setup. */
0074 
0075 #define _CAMELLIA128_NKEYS 24
0076 #define _CAMELLIA256_NKEYS 32
0077 
0078 struct camellia128_ctx
0079 {
0080   uint64_t keys[_CAMELLIA128_NKEYS];
0081 };
0082 
0083 void
0084 camellia128_set_encrypt_key(struct camellia128_ctx *ctx,
0085                 const uint8_t *key);
0086 
0087 void
0088 camellia128_set_decrypt_key(struct camellia128_ctx *ctx,
0089                 const uint8_t *key);
0090 
0091 void
0092 camellia128_invert_key(struct camellia128_ctx *dst,
0093                const struct camellia128_ctx *src);
0094 
0095 void
0096 camellia128_crypt(const struct camellia128_ctx *ctx,
0097           size_t length, uint8_t *dst,
0098           const uint8_t *src);
0099 
0100 struct camellia256_ctx
0101 {
0102   uint64_t keys[_CAMELLIA256_NKEYS];
0103 };
0104 
0105 void
0106 camellia256_set_encrypt_key(struct camellia256_ctx *ctx,
0107                 const uint8_t *key);
0108 
0109 void
0110 camellia256_set_decrypt_key(struct camellia256_ctx *ctx,
0111                 const uint8_t *key);
0112 
0113 void
0114 camellia256_invert_key(struct camellia256_ctx *dst,
0115                const struct camellia256_ctx *src);
0116 
0117 void
0118 camellia256_crypt(const struct camellia256_ctx *ctx,
0119           size_t length, uint8_t *dst,
0120           const uint8_t *src);
0121 
0122 /* camellia192 is the same as camellia256, except for the key
0123    schedule. */
0124 /* Slightly ugly with a #define on a struct tag, since it might cause
0125    surprises if also used as a name of a variable. */
0126 #define camellia192_ctx camellia256_ctx
0127 
0128 void
0129 camellia192_set_encrypt_key(struct camellia256_ctx *ctx,
0130                 const uint8_t *key);
0131 
0132 void
0133 camellia192_set_decrypt_key(struct camellia256_ctx *ctx,
0134                 const uint8_t *key);
0135 
0136 #define camellia192_invert_key camellia256_invert_key
0137 #define camellia192_crypt camellia256_crypt
0138 
0139 #ifdef __cplusplus
0140 }
0141 #endif
0142 
0143 #endif /* NETTLE_CAMELLIA_H_INCLUDED */