#include "common.h"
#if defined(MBEDTLS_CAMELLIA_C)
#include "mbedtls/camellia.h"
#include "mbedtls/platform_util.h"
#include <string.h>
#include "mbedtls/platform.h"
#if !defined(MBEDTLS_CAMELLIA_ALT)
static const unsigned char SIGMA_CHARS[6][8] = …;
#if defined(MBEDTLS_CAMELLIA_SMALL_MEMORY)
static const unsigned char FSb[256] =
{
112, 130, 44, 236, 179, 39, 192, 229, 228, 133, 87, 53, 234, 12, 174, 65,
35, 239, 107, 147, 69, 25, 165, 33, 237, 14, 79, 78, 29, 101, 146, 189,
134, 184, 175, 143, 124, 235, 31, 206, 62, 48, 220, 95, 94, 197, 11, 26,
166, 225, 57, 202, 213, 71, 93, 61, 217, 1, 90, 214, 81, 86, 108, 77,
139, 13, 154, 102, 251, 204, 176, 45, 116, 18, 43, 32, 240, 177, 132, 153,
223, 76, 203, 194, 52, 126, 118, 5, 109, 183, 169, 49, 209, 23, 4, 215,
20, 88, 58, 97, 222, 27, 17, 28, 50, 15, 156, 22, 83, 24, 242, 34,
254, 68, 207, 178, 195, 181, 122, 145, 36, 8, 232, 168, 96, 252, 105, 80,
170, 208, 160, 125, 161, 137, 98, 151, 84, 91, 30, 149, 224, 255, 100, 210,
16, 196, 0, 72, 163, 247, 117, 219, 138, 3, 230, 218, 9, 63, 221, 148,
135, 92, 131, 2, 205, 74, 144, 51, 115, 103, 246, 243, 157, 127, 191, 226,
82, 155, 216, 38, 200, 55, 198, 59, 129, 150, 111, 75, 19, 190, 99, 46,
233, 121, 167, 140, 159, 110, 188, 142, 41, 245, 249, 182, 47, 253, 180, 89,
120, 152, 6, 106, 231, 70, 113, 186, 212, 37, 171, 66, 136, 162, 141, 250,
114, 7, 185, 85, 248, 238, 172, 10, 54, 73, 42, 104, 60, 56, 241, 164,
64, 40, 211, 123, 187, 201, 67, 193, 21, 227, 173, 244, 119, 199, 128, 158
};
#define SBOX1 …
#define SBOX2 …
#define SBOX3 …
#define SBOX4 …
#else
static const unsigned char FSb[256] = …;
static const unsigned char FSb2[256] = …;
static const unsigned char FSb3[256] = …;
static const unsigned char FSb4[256] = …;
#define SBOX1(n) …
#define SBOX2(n) …
#define SBOX3(n) …
#define SBOX4(n) …
#endif
static const unsigned char shifts[2][4][4] = …;
static const signed char indexes[2][4][20] = …;
static const signed char transposes[2][20] = …;
#define ROTL(DEST, SRC, SHIFT) …
#define FL(XL, XR, KL, KR) …
#define FLInv(YL, YR, KL, KR) …
#define SHIFT_AND_PLACE(INDEX, OFFSET) …
static void camellia_feistel(const uint32_t x[2], const uint32_t k[2],
uint32_t z[2])
{ … }
void mbedtls_camellia_init(mbedtls_camellia_context *ctx)
{ … }
void mbedtls_camellia_free(mbedtls_camellia_context *ctx)
{ … }
int mbedtls_camellia_setkey_enc(mbedtls_camellia_context *ctx,
const unsigned char *key,
unsigned int keybits)
{ … }
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
int mbedtls_camellia_setkey_dec(mbedtls_camellia_context *ctx,
const unsigned char *key,
unsigned int keybits)
{ … }
#endif
int mbedtls_camellia_crypt_ecb(mbedtls_camellia_context *ctx,
int mode,
const unsigned char input[16],
unsigned char output[16])
{ … }
#if defined(MBEDTLS_CIPHER_MODE_CBC)
int mbedtls_camellia_crypt_cbc(mbedtls_camellia_context *ctx,
int mode,
size_t length,
unsigned char iv[16],
const unsigned char *input,
unsigned char *output)
{ … }
#endif
#if defined(MBEDTLS_CIPHER_MODE_CFB)
int mbedtls_camellia_crypt_cfb128(mbedtls_camellia_context *ctx,
int mode,
size_t length,
size_t *iv_off,
unsigned char iv[16],
const unsigned char *input,
unsigned char *output)
{ … }
#endif
#if defined(MBEDTLS_CIPHER_MODE_CTR)
int mbedtls_camellia_crypt_ctr(mbedtls_camellia_context *ctx,
size_t length,
size_t *nc_off,
unsigned char nonce_counter[16],
unsigned char stream_block[16],
const unsigned char *input,
unsigned char *output)
{ … }
#endif
#endif
#if defined(MBEDTLS_SELF_TEST)
#define CAMELLIA_TESTS_ECB …
static const unsigned char camellia_test_ecb_key[3][CAMELLIA_TESTS_ECB][32] = …;
static const unsigned char camellia_test_ecb_plain[CAMELLIA_TESTS_ECB][16] = …;
static const unsigned char camellia_test_ecb_cipher[3][CAMELLIA_TESTS_ECB][16] = …;
#if defined(MBEDTLS_CIPHER_MODE_CBC)
#define CAMELLIA_TESTS_CBC …
static const unsigned char camellia_test_cbc_key[3][32] = …;
static const unsigned char camellia_test_cbc_iv[16] = …
;
static const unsigned char camellia_test_cbc_plain[CAMELLIA_TESTS_CBC][16] = …;
static const unsigned char camellia_test_cbc_cipher[3][CAMELLIA_TESTS_CBC][16] = …;
#endif
#if defined(MBEDTLS_CIPHER_MODE_CTR)
static const unsigned char camellia_test_ctr_key[3][16] = …;
static const unsigned char camellia_test_ctr_nonce_counter[3][16] = …;
static const unsigned char camellia_test_ctr_pt[3][48] = …;
static const unsigned char camellia_test_ctr_ct[3][48] = …;
static const int camellia_test_ctr_len[3] = …;
#endif
int mbedtls_camellia_self_test(int verbose)
{ … }
#endif
#endif