diff options
author | appro <appro> | 2006-12-02 11:52:50 +0000 |
---|---|---|
committer | appro <appro> | 2006-12-02 11:52:50 +0000 |
commit | e313583e9437736029337c46119c4086dadd5675 (patch) | |
tree | 62a42aa1c24f143c047fef3dffefd485e3022234 /crypto/camellia | |
parent | d8af7643ffdfb8e2f5fe5d4446f48b1d58af436d (diff) | |
download | openssl-e313583e9437736029337c46119c4086dadd5675.tar.gz |
Eliminate redundant variable in Camellia CBC routine.
Diffstat (limited to 'crypto/camellia')
-rw-r--r-- | crypto/camellia/cmll_cbc.c | 102 |
1 files changed, 47 insertions, 55 deletions
diff --git a/crypto/camellia/cmll_cbc.c b/crypto/camellia/cmll_cbc.c index 932c1d1be..4141a7b59 100644 --- a/crypto/camellia/cmll_cbc.c +++ b/crypto/camellia/cmll_cbc.c @@ -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); } } } |