Commit c1552ab2 authored by Niels Möller's avatar Niels Möller

* camellia-set-encrypt-key.c (camellia_setup128): Generate

unmodified subkeys according to the spec. Moved clever combination
of subkeys to camellia_set_encrypt_key.
(camellia_setup256): Likewise.
(camellia_set_encrypt_key): Moved subkey post-processing code
here, and reduce code duplication between 128-bit keys and larger
keys.

* camellia.c: Deleted file, split into several new files...
* camellia-table.c (_camellia_table): New file with the constant
sbox tables.
* camellia-set-encrypt-key.c: New file.
(camellia_setup128): Generate unmodified subkeys according to the
spec. Moved clever combination of subkeys to camellia_set_encrypt_key.
(camellia_setup256): Likewise.

* camellia-set-decrypt-key.c: New file.
(camellia_invert_key): Key inversion function.
(camellia_set_decrypt_key): New key setup function.
* camellia-internal.h: New file.
* camellia-crypt.c (camellia_crypt): New file, new wrapper
function passing the sbox table to _camellia_crypt.
* camellia-crypt-internal.c (_camellia_crypt): New file, with main
encrypt/decrypt function.
* Makefile.in (nettle_SOURCES): Updated list of camellia source files.
(DISTFILES): Added camellia-internal.h.

Rev: nettle/ChangeLog:1.96
Rev: nettle/Makefile.in:1.26
Rev: nettle/camellia-crypt-internal.c:1.1
Rev: nettle/camellia-crypt.c:1.1
Rev: nettle/camellia-internal.h:1.1
Rev: nettle/camellia-set-decrypt-key.c:1.1
Rev: nettle/camellia-set-encrypt-key.c:1.1
Rev: nettle/camellia-table.c:1.1
Rev: nettle/camellia.c:1.5(DEAD)
parent 5af86074
2010-07-24 Niels Mller <nisse@lysator.liu.se>
* camellia-set-encrypt-key.c (camellia_setup128): Generate
unmodified subkeys according to the spec. Moved clever combination
of subkeys to camellia_set_encrypt_key.
(camellia_setup256): Likewise.
(camellia_set_encrypt_key): Moved subkey post-processing code
here, and reduce code duplication between 128-bit keys and larger
keys.
* camellia.c: Deleted file, split into several new files...
* camellia-table.c (_camellia_table): New file with the constant
sbox tables.
* camellia-set-encrypt-key.c: New file.
(camellia_setup128): Generate unmodified subkeys according to the
spec. Moved clever combination of subkeys to camellia_set_encrypt_key.
(camellia_setup256): Likewise.
* camellia-set-decrypt-key.c: New file.
(camellia_invert_key): Key inversion function.
(camellia_set_decrypt_key): New key setup function.
* camellia-internal.h: New file.
* camellia-crypt.c (camellia_crypt): New file, new wrapper
function passing the sbox table to _camellia_crypt.
* camellia-crypt-internal.c (_camellia_crypt): New file, with main
encrypt/decrypt function.
* Makefile.in (nettle_SOURCES): Updated list of camellia source files.
(DISTFILES): Added camellia-internal.h.
2010-07-20 Niels Mller <nisse@lysator.liu.se>
* camellia-meta.c: Use _NETTLE_CIPHER_SEP_SET_KEY.
* camellia.h (struct camellia_ctx): Replaced flag camellia128 by
expanded key length nkeys.
......
......@@ -55,7 +55,10 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
arctwo.c arctwo-meta.c \
base16-encode.c base16-decode.c base16-meta.c \
base64-encode.c base64-decode.c base64-meta.c \
camellia.c camellia-meta.c cast128.c cast128-meta.c \
camellia-crypt.c camellia-crypt-internal.c \
camellia-set-encrypt-key.c camellia-set-decrypt-key.c \
camellia-table.c camellia-meta.c \
cast128.c cast128-meta.c \
blowfish.c \
cbc.c ctr.c \
des.c \
......@@ -122,7 +125,7 @@ DISTFILES = $(SOURCES) $(HEADERS) .bootstrap aclocal.m4 configure.ac \
config.h.in config.m4.in config.make.in Makefile.in \
README AUTHORS COPYING COPYING.LIB INSTALL NEWS TODO ChangeLog \
memxor.c $(des_headers) descore.README \
aes-internal.h cast128_sboxes.h desinfo.h desCode.h \
aes-internal.h camellia-internal.h cast128_sboxes.h desinfo.h desCode.h \
serpent_sboxes.h nettle-internal.h nettle-write.h prime-list.h \
asm.m4 \
nettle.texinfo nettle.info nettle.html nettle.pdf sha-example.c
......
/* camellia-crypt-internal.c
*
* Copyright (C) 2006,2007
* NTT (Nippon Telegraph and Telephone Corporation).
*
* Copyright (C) 2010 Niels Mller
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Algorithm Specification
* http://info.isl.ntt.co.jp/crypt/eng/camellia/specifications.html
*/
/* Based on camellia.c ver 1.2.0, see
http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/camellia-LGPL-1.2.0.tar.gz.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include "camellia-internal.h"
#include "macros.h"
#define CAMELLIA_FL(x, k) do { \
uint32_t __xl, __xr, __kl, __kr, __t; \
__xl = (x) >> 32; \
__xr = (x) & 0xffffffff; \
__kl = (k) >> 32; \
__kr = (k) & 0xffffffff; \
__t = __xl & __kl; \
__xr ^= ROL32(1, __t); \
__xl ^= (__xr | __kr); \
(x) = ((uint64_t) __xl << 32) | __xr; \
} while (0)
#define CAMELLIA_FLINV(x, k) do { \
uint32_t __xl, __xr, __kl, __kr, __t; \
__xl = (x) >> 32; \
__xr = (x) & 0xffffffff; \
__kl = (k) >> 32; \
__kr = (k) & 0xffffffff; \
__xl ^= (__xr | __kr); \
__t = __xl & __kl; \
__xr ^= ROL32(1, __t); \
(x) = ((uint64_t) __xl << 32) | __xr; \
} while (0)
#define CAMELLIA_ROUNDSM(T, x, k, y) do { \
uint32_t __il, __ir; \
__ir \
= T->sp1110[(x) & 0xff] \
^ T->sp0222[((x) >> 24) & 0xff] \
^ T->sp3033[((x) >> 16) & 0xff] \
^ T->sp4404[((x) >> 8) & 0xff]; \
/* ir == (t6^t7^t8),(t5^t7^t8),(t5^t6^t8),(t5^t6^t7) */ \
__il \
= T->sp1110[ (x) >> 56] \
^ T->sp0222[((x) >> 48) & 0xff] \
^ T->sp3033[((x) >> 40) & 0xff] \
^ T->sp4404[((x) >> 32) & 0xff]; \
/* il == (t1^t3^t4),(t1^t2^t4),(t1^t2^t3),(t2^t3^t4) */ \
__il ^= (k) >> 32; \
__ir ^= (k) & 0xffffffff; \
__ir ^= __il; \
/* ir == (t1^t3^t4^t6^t7^t8),(t1^t2^t4^t5^t7^t8), \
(t1^t2^t3^t5^t6^t8),(t2^t3^t4^t5^t6^t7) \
== y1,y2,y3,y4 */ \
__il = ROL32(24, __il); \
/* il == (t2^t3^t4),(t1^t3^t4),(t1^t2^t4),(t1^t2^t3) */ \
__il ^= __ir; \
/* il == (t1^t2^t6^t7^t8),(t2^t3^t5^t7^t8), \
(t3^t4^t5^t6^t8),(t1^t4^t5^t6^t7) \
== y5,y6,y7,y8 */ \
y ^= ((uint64_t) __ir << 32) | __il; \
} while (0)
void
_camellia_crypt(const struct camellia_ctx *ctx,
const struct camellia_table *T,
unsigned length, uint8_t *dst,
const uint8_t *src)
{
FOR_BLOCKS(length, dst, src, CAMELLIA_BLOCK_SIZE)
{
uint64_t i0,i1;
unsigned i;
i0 = READ_UINT64(src);
i1 = READ_UINT64(src + 8);
/* pre whitening but absorb kw2*/
i0 ^= ctx->keys[0];
/* main iteration */
CAMELLIA_ROUNDSM(T, i0,ctx->keys[2], i1);
CAMELLIA_ROUNDSM(T, i1,ctx->keys[3], i0);
CAMELLIA_ROUNDSM(T, i0,ctx->keys[4], i1);
CAMELLIA_ROUNDSM(T, i1,ctx->keys[5], i0);
CAMELLIA_ROUNDSM(T, i0,ctx->keys[6], i1);
CAMELLIA_ROUNDSM(T, i1,ctx->keys[7], i0);
for (i = 0; i < ctx->nkeys - 10; i+= 8)
{
CAMELLIA_FL(i0, ctx->keys[i+8]);
CAMELLIA_FLINV(i1, ctx->keys[i+9]);
CAMELLIA_ROUNDSM(T, i0,ctx->keys[i+10], i1);
CAMELLIA_ROUNDSM(T, i1,ctx->keys[i+11], i0);
CAMELLIA_ROUNDSM(T, i0,ctx->keys[i+12], i1);
CAMELLIA_ROUNDSM(T, i1,ctx->keys[i+13], i0);
CAMELLIA_ROUNDSM(T, i0,ctx->keys[i+14], i1);
CAMELLIA_ROUNDSM(T, i1,ctx->keys[i+15], i0);
}
/* post whitening but kw4 */
i1 ^= ctx->keys[i+8];
WRITE_UINT64(dst , i1);
WRITE_UINT64(dst + 8, i0);
}
}
/* camellia-encrypt.c
*
* Crypt function for the camellia block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2010 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include "camellia-internal.h"
/* The main point on this function is to help the assembler
implementations of _nettle_camellia_crypt to get the table pointer.
For PIC code, the details can be complex and system dependent. */
void
camellia_crypt(const struct camellia_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src)
{
assert(!(length % CAMELLIA_BLOCK_SIZE) );
_camellia_crypt(ctx, &_camellia_table,
length, dst, src);
}
/* camellia-internal.h
*
* The camellia block cipher.
*/
/* Copyright (C) 2006,2007
* NTT (Nippon Telegraph and Telephone Corporation).
*
* Copyright (C) 2010 Niels Mller
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Algorithm Specification
* http://info.isl.ntt.co.jp/crypt/eng/camellia/specifications.html
*/
/* Based on camellia.c ver 1.2.0, see
http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/camellia-LGPL-1.2.0.tar.gz.
*/
#ifndef NETTLE_CAMELLIA_INTERNAL_H_INCLUDED
#define NETTLE_CAMELLIA_INTERNAL_H_INCLUDED
#include "camellia.h"
/* Name mangling */
#define _camellia_crypt _nettle_camellia_crypt
#define _camellia_table _nettle_camellia_table
/*
* macros
*/
/* Rotation of 32-bit values. */
#define ROL32(bits, x) (((x) << (bits)) | ((x) >> (32 - (bits))))
/* Destructive rotation of 128 bit values. */
#define ROL128(bits, xl, xr) do { \
uint64_t __rol128_t = (xl); \
(xl) = ((xl) << (bits)) | ((xr) >> (64 - (bits))); \
(xr) = ((xr) << (bits)) | (__rol128_t >> (64 - (bits))); \
} while (0)
struct camellia_table
{
uint32_t sp1110[256];
uint32_t sp0222[256];
uint32_t sp3033[256];
uint32_t sp4404[256];
};
void
_camellia_crypt(const struct camellia_ctx *ctx,
const struct camellia_table *T,
unsigned length, uint8_t *dst,
const uint8_t *src);
extern const struct camellia_table _camellia_table;
#endif /* NETTLE_CAMELLIA_INTERNAL_H_INCLUDED */
/* camellia-set-decrypt-key.c
*
* Inverse key setup for the camellia block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2010 Niels Mller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "camellia.h"
#define SWAP(a, b) \
do { uint64_t t_swap = (a); (a) = (b); (b) = t_swap; } while(0)
void
camellia_invert_key(struct camellia_ctx *dst,
const struct camellia_ctx *src)
{
unsigned nkeys = src->nkeys;
unsigned i;
if (dst == src)
{
SWAP(dst->keys[0], dst->keys[nkeys - 2]);
for (i = 2; i < nkeys - 1 - i; i++)
SWAP(dst->keys[i], dst->keys[nkeys - 1 - i]);
}
else
{
dst->nkeys = nkeys;
dst->keys[0] = src->keys[nkeys - 2];
for (i = 2; i < nkeys - 2; i++)
dst->keys[i] = src->keys[nkeys - 1 - i];
dst->keys[nkeys - 2] = src->keys[0];
}
}
void
camellia_set_decrypt_key(struct camellia_ctx *ctx,
unsigned length, const uint8_t *key)
{
camellia_set_encrypt_key(ctx, length, key);
camellia_invert_key(ctx, ctx);
}
/* camellia-set-encrypt-key.c
*
* Key setup for the camellia block cipher.
*/
/*
* Copyright (C) 2006,2007
* NTT (Nippon Telegraph and Telephone Corporation).
*
* Copyright (C) 2010 Niels Mller
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Algorithm Specification
* http://info.isl.ntt.co.jp/crypt/eng/camellia/specifications.html
*/
/* Based on camellia.c ver 1.2.0, see
http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/camellia-LGPL-1.2.0.tar.gz.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include "camellia-internal.h"
#include "macros.h"
/* key constants */
#define SIGMA1 0xA09E667F3BCC908BULL
#define SIGMA2 0xB67AE8584CAA73B2ULL
#define SIGMA3 0xC6EF372FE94F82BEULL
#define SIGMA4 0x54FF53A5F1D36F1CULL
#define SIGMA5 0x10E527FADE682D1DULL
#define SIGMA6 0xB05688C2B3E6C1FDULL
#define CAMELLIA_SP1110(INDEX) (_nettle_camellia_table.sp1110[(int)(INDEX)])
#define CAMELLIA_SP0222(INDEX) (_nettle_camellia_table.sp0222[(int)(INDEX)])
#define CAMELLIA_SP3033(INDEX) (_nettle_camellia_table.sp3033[(int)(INDEX)])
#define CAMELLIA_SP4404(INDEX) (_nettle_camellia_table.sp4404[(int)(INDEX)])
#define CAMELLIA_F(x, k, y) do { \
uint32_t __yl, __yr; \
uint64_t __i = (x) ^ (k); \
__yl \
= CAMELLIA_SP1110( __i & 0xff) \
^ CAMELLIA_SP0222((__i >> 24) & 0xff) \
^ CAMELLIA_SP3033((__i >> 16) & 0xff) \
^ CAMELLIA_SP4404((__i >> 8) & 0xff); \
__yr \
= CAMELLIA_SP1110( __i >> 56) \
^ CAMELLIA_SP0222((__i >> 48) & 0xff) \
^ CAMELLIA_SP3033((__i >> 40) & 0xff) \
^ CAMELLIA_SP4404((__i >> 32) & 0xff); \
__yl ^= __yr; \
__yr = ROL32(24, __yr); \
__yr ^= __yl; \
(y) = ((uint64_t) __yl << 32) | __yr; \
} while (0)
#define CAMELLIA_F_HALF_INV(x) do { \
uint32_t __t, __w; \
__t = (x) >> 32; \
__w = __t ^(x); \
__w = ROL32(8, __w); \
(x) = ((uint64_t) __w << 32) | (__t ^ __w); \
} while (0)
static void
camellia_setup128(uint64_t *subkey, const uint64_t *key)
{
uint64_t k0, k1, w;
/**
* k == k0 || k1 (|| is concatenation)
*/
k0 = key[0];
k1 = key[1];
/**
* generate KL dependent subkeys
*/
subkey[0] = k0; subkey[1] = k1;
ROL128(15, k0, k1);
subkey[4] = k0; subkey[5] = k1;
ROL128(30, k0, k1);
subkey[10] = k0; subkey[11] = k1;
ROL128(15, k0, k1);
subkey[13] = k1;
ROL128(17, k0, k1);
subkey[16] = k0; subkey[17] = k1;
ROL128(17, k0, k1);
subkey[18] = k0; subkey[19] = k1;
ROL128(17, k0, k1);
subkey[22] = k0; subkey[23] = k1;
/* generate KA. D1 is k0, d2 is k1. */
/* FIXME: Make notation match the spec better. */
/* For the 128-bit case, KR = 0, the construvtion of KA reduces to:
D1 = KL >> 64;
W = KL & MASK64;
D2 = F(D1, Sigma1);
W = D2 ^ W
D1 = F(W, Sigma2)
D2 = D2 ^ F(D1, Sigma3);
D1 = D1 ^ F(D2, Sigma4);
KA = (D1 << 64) | D2;
*/
k0 = subkey[0]; w = subkey[1];
CAMELLIA_F(k0, SIGMA1, k1);
w ^= k1;
CAMELLIA_F(w, SIGMA2, k0);
CAMELLIA_F(k0, SIGMA3, w);
k1 ^= w;
CAMELLIA_F(k1, SIGMA4, w);
k0 ^= w;
/* generate KA dependent subkeys */
subkey[2] = k0; subkey[3] = k1;
ROL128(15, k0, k1);
subkey[6] = k0; subkey[7] = k1;
ROL128(15, k0, k1);
subkey[8] = k0; subkey[9] = k1;
ROL128(15, k0, k1);
subkey[12] = k0;
ROL128(15, k0, k1);
subkey[14] = k0; subkey[15] = k1;
ROL128(34, k0, k1);
subkey[20] = k0; subkey[21] = k1;
ROL128(17, k0, k1);
subkey[24] = k0; subkey[25] = k1;
return;
}
static void
camellia_setup256(uint64_t *subkey, const uint64_t *key)
{
uint64_t k0, k1, k2, k3;
uint64_t w;
/**
* key = (kll || klr || krl || krr || krll || krlr || krrl || krrr)
* (|| is concatenation)
*/
k0 = key[0];
k1 = key[1];
k2 = key[2];
k3 = key[3];
/* generate KL dependent subkeys */
subkey[0] = k0; subkey[1] = k1;
ROL128(45, k0, k1);
subkey[12] = k0; subkey[13] = k1;
ROL128(15, k0, k1);
subkey[16] = k0; subkey[17] = k1;
ROL128(17, k0, k1);
subkey[22] = k0; subkey[23] = k1;
ROL128(34, k0, k1);
subkey[30] = k0; subkey[31] = k1;
/* generate KR dependent subkeys */
ROL128(15, k2, k3);
subkey[4] = k2; subkey[5] = k3;
ROL128(15, k2, k3);
subkey[8] = k2; subkey[9] = k3;
ROL128(30, k2, k3);
subkey[18] = k2; subkey[19] = k3;
ROL128(34, k2, k3);
subkey[26] = k2; subkey[27] = k3;
ROL128(34, k2, k3);
/* generate KA */
/* The construction of KA is done as
D1 = (KL ^ KR) >> 64
D2 = (KL ^ KR) & MASK64
W = F(D1, SIGMA1)
D2 = D2 ^ W
D1 = F(D2, SIGMA2) ^ (KR >> 64)
D2 = F(D1, SIGMA3) ^ W ^ (KR & MASK64)
D1 = D1 ^ F(W, SIGMA2)
D2 = D2 ^ F(D1, SIGMA3)
D1 = D1 ^ F(D2, SIGMA4)
*/
k0 = subkey[0] ^ k2;
k1 = subkey[1] ^ k3;
CAMELLIA_F(k0, SIGMA1, w);
k1 ^= w;
CAMELLIA_F(k1, SIGMA2, k0);
k0 ^= k2;
CAMELLIA_F(k0, SIGMA3, k1);
k1 ^= w ^ k3;
CAMELLIA_F(k1, SIGMA4, w);
k0 ^= w;
/* generate KB */
k2 ^= k0; k3 ^= k1;
CAMELLIA_F(k2, SIGMA5, w);
k3 ^= w;
CAMELLIA_F(k3, SIGMA6, w);
k2 ^= w;
/* generate KA dependent subkeys */
ROL128(15, k0, k1);
subkey[6] = k0; subkey[7] = k1;
ROL128(30, k0, k1);
subkey[14] = k0; subkey[15] = k1;
ROL128(32, k0, k1);
subkey[24] = k0; subkey[25] = k1;
ROL128(17, k0, k1);
subkey[28] = k0; subkey[29] = k1;
/* generate KB dependent subkeys */
subkey[2] = k2; subkey[3] = k3;
ROL128(30, k2, k3);
subkey[10] = k2; subkey[11] = k3;
ROL128(30, k2, k3);
subkey[20] = k2; subkey[21] = k3;
ROL128(51, k2, k3);
subkey[32] = k2; subkey[33] = k3;
return;
}
void
camellia_set_encrypt_key(struct camellia_ctx *ctx,
unsigned length, const uint8_t *key)
{
uint64_t k[4];
/* Subkeys according to the spec, 26 for short keys and 34 for large
keys */
uint64_t subkey[34];
uint64_t kw4;
uint32_t dw, tl, tr;
unsigned i;
k[0] = READ_UINT64(key);
k[1] = READ_UINT64(key + 8);
if (length == 16)
{
ctx->nkeys = 26;
camellia_setup128(subkey, k);
}
else
{
ctx->nkeys = 34;