mirror of
https://github.com/openssl/openssl.git
synced 2025-01-30 14:01:55 +08:00
Eliminate redundant variable in Camellia CBC routine.
This commit is contained in:
parent
9f8cfb1c62
commit
502aef5aaf
@ -67,9 +67,9 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
|
||||
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};
|
||||
|
||||
|
||||
@ -127,14 +127,14 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
}
|
||||
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);
|
||||
@ -143,21 +143,21 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
{
|
||||
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);
|
||||
@ -166,8 +166,8 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -178,14 +178,13 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
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;
|
||||
@ -194,16 +193,15 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
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);
|
||||
@ -212,15 +210,14 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
{
|
||||
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;
|
||||
@ -228,15 +225,14 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
}
|
||||
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);
|
||||
@ -245,36 +241,32 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user