unsigned long n;
unsigned long len = length;
- unsigned char tmp[CAMELLIA_BLOCK_SIZE];
const unsigned char *iv = ivec;
- u32 t32[CAMELLIA_BLOCK_SIZE/sizeof(u32)];
+ union { u32 t32[CAMELLIA_BLOCK_SIZE/sizeof(u32)];
+ u8 t8 [CAMELLIA_BLOCK_SIZE]; } tmp;
const union { long one; char little; } camellia_endian = {1};
}
if (len)
{
- memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
+ memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
if (camellia_endian.little)
- SWAP4WORD((u32 *)tmp);
- key->dec(key->rd_key, (u32 *)tmp);
+ SWAP4WORD(tmp.t32);
+ key->dec(key->rd_key, tmp.t32);
if (camellia_endian.little)
- SWAP4WORD((u32 *)tmp);
+ SWAP4WORD(tmp.t32);
for(n=0; n < len; ++n)
- out[n] = tmp[n] ^ iv[n];
+ out[n] = tmp.t8[n] ^ iv[n];
iv = in;
}
memcpy(ivec,iv,CAMELLIA_BLOCK_SIZE);
{
while (len >= CAMELLIA_BLOCK_SIZE)
{
- memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
+ memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
if (camellia_endian.little)
SWAP4WORD((u32 *)out);
key->dec(key->rd_key, (u32 *)out);
if (camellia_endian.little)
SWAP4WORD((u32 *)out);
XOR4WORD((u32 *)out, (u32 *)ivec);
- memcpy(ivec, tmp, CAMELLIA_BLOCK_SIZE);
+ memcpy(ivec, tmp.t8, CAMELLIA_BLOCK_SIZE);
len -= CAMELLIA_BLOCK_SIZE;
in += CAMELLIA_BLOCK_SIZE;
out += CAMELLIA_BLOCK_SIZE;
}
if (len)
{
- memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
+ memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
if (camellia_endian.little)
SWAP4WORD((u32 *)out);
key->dec(key->rd_key,(u32 *)out);
for(n=0; n < len; ++n)
out[n] ^= ivec[n];
for(n=len; n < CAMELLIA_BLOCK_SIZE; ++n)
- out[n] = tmp[n];
- memcpy(ivec, tmp, CAMELLIA_BLOCK_SIZE);
+ out[n] = tmp.t8[n];
+ memcpy(ivec, tmp.t8, CAMELLIA_BLOCK_SIZE);
}
}
}
while (len >= CAMELLIA_BLOCK_SIZE)
{
for(n=0; n < CAMELLIA_BLOCK_SIZE; ++n)
- out[n] = in[n] ^ iv[n];
- memcpy(t32, out, CAMELLIA_BLOCK_SIZE);
+ tmp.t8[n] = in[n] ^ iv[n];
if (camellia_endian.little)
- SWAP4WORD(t32);
- key->enc(key->rd_key, t32);
+ SWAP4WORD(tmp.t32);
+ key->enc(key->rd_key, tmp.t32);
if (camellia_endian.little)
- SWAP4WORD(t32);
- memcpy(out, t32, CAMELLIA_BLOCK_SIZE);
+ SWAP4WORD(tmp.t32);
+ memcpy(out, tmp.t8, CAMELLIA_BLOCK_SIZE);
iv = out;
len -= CAMELLIA_BLOCK_SIZE;
in += CAMELLIA_BLOCK_SIZE;
if (len)
{
for(n=0; n < len; ++n)
- out[n] = in[n] ^ iv[n];
+ tmp.t8[n] = in[n] ^ iv[n];
for(n=len; n < CAMELLIA_BLOCK_SIZE; ++n)
- out[n] = iv[n];
- memcpy(t32, out, CAMELLIA_BLOCK_SIZE);
+ tmp.t8[n] = iv[n];
if (camellia_endian.little)
- SWAP4WORD(t32);
- key->enc(key->rd_key, t32);
+ SWAP4WORD(tmp.t32);
+ key->enc(key->rd_key, tmp.t32);
if (camellia_endian.little)
- SWAP4WORD(t32);
- memcpy(out, t32, CAMELLIA_BLOCK_SIZE);
+ SWAP4WORD(tmp.t32);
+ memcpy(out, tmp.t8, CAMELLIA_BLOCK_SIZE);
iv = out;
}
memcpy(ivec,iv,CAMELLIA_BLOCK_SIZE);
{
while (len >= CAMELLIA_BLOCK_SIZE)
{
- memcpy(t32,in,CAMELLIA_BLOCK_SIZE);
+ memcpy(tmp.t8,in,CAMELLIA_BLOCK_SIZE);
if (camellia_endian.little)
- SWAP4WORD(t32);
- key->dec(key->rd_key,t32);
+ SWAP4WORD(tmp.t32);
+ key->dec(key->rd_key,tmp.t32);
if (camellia_endian.little)
- SWAP4WORD(t32);
- memcpy(out,t32,CAMELLIA_BLOCK_SIZE);
+ SWAP4WORD(tmp.t32);
for(n=0; n < CAMELLIA_BLOCK_SIZE; ++n)
- out[n] ^= iv[n];
+ out[n] = tmp.t8[n] ^ iv[n];
iv = in;
len -= CAMELLIA_BLOCK_SIZE;
in += CAMELLIA_BLOCK_SIZE;
}
if (len)
{
- memcpy(t32, in, CAMELLIA_BLOCK_SIZE);
+ memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
if (camellia_endian.little)
- SWAP4WORD(t32);
- key->dec(key->rd_key, t32);
+ SWAP4WORD(tmp.t32);
+ key->dec(key->rd_key, tmp.t32);
if (camellia_endian.little)
- SWAP4WORD(t32);
- memcpy(out, t32, CAMELLIA_BLOCK_SIZE);
+ SWAP4WORD(tmp.t32);
for(n=0; n < len; ++n)
- out[n] ^= iv[n];
+ out[n] = tmp.t8[n] ^ iv[n];
iv = in;
}
memcpy(ivec,iv,CAMELLIA_BLOCK_SIZE);
{
while (len >= CAMELLIA_BLOCK_SIZE)
{
- memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
- memcpy(t32, in, CAMELLIA_BLOCK_SIZE);
+ memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
if (camellia_endian.little)
- SWAP4WORD(t32);
- key->dec(key->rd_key, t32);
+ SWAP4WORD(tmp.t32);
+ key->dec(key->rd_key, tmp.t32);
if (camellia_endian.little)
- SWAP4WORD(t32);
- memcpy(out, t32, CAMELLIA_BLOCK_SIZE);
+ SWAP4WORD(tmp.t32);
for(n=0; n < CAMELLIA_BLOCK_SIZE; ++n)
- out[n] ^= ivec[n];
- memcpy(ivec, tmp, CAMELLIA_BLOCK_SIZE);
+ tmp.t8[n] ^= ivec[n];
+ memcpy(ivec, in, CAMELLIA_BLOCK_SIZE);
+ memcpy(out, tmp.t8, CAMELLIA_BLOCK_SIZE);
len -= CAMELLIA_BLOCK_SIZE;
in += CAMELLIA_BLOCK_SIZE;
out += CAMELLIA_BLOCK_SIZE;
}
if (len)
{
- memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
- memcpy(t32, in, CAMELLIA_BLOCK_SIZE);
+ memcpy(tmp.t8, in, CAMELLIA_BLOCK_SIZE);
if (camellia_endian.little)
- SWAP4WORD(t32);
- key->dec(key->rd_key,t32);
+ SWAP4WORD(tmp.t32);
+ key->dec(key->rd_key,tmp.t32);
if (camellia_endian.little)
- SWAP4WORD(t32);
- memcpy(out, t32, CAMELLIA_BLOCK_SIZE);
+ SWAP4WORD(tmp.t32);
for(n=0; n < len; ++n)
- out[n] ^= ivec[n];
- for(n=len; n < CAMELLIA_BLOCK_SIZE; ++n)
- out[n] = tmp[n];
- memcpy(ivec, tmp, CAMELLIA_BLOCK_SIZE);
+ tmp.t8[n] ^= ivec[n];
+ memcpy(ivec, in, CAMELLIA_BLOCK_SIZE);
+ memcpy(out,tmp.t8,len);
}
}
}