aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/camellia.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2007-11-06 09:13:40 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2008-01-10 16:16:07 -0500
commit1ce73e8d6d95ceb860184c34fa1a91a82e51cbb3 (patch)
tree9c6c9b99f46b74f329e4ad850273c023b85f78c0 /crypto/camellia.c
parent3a5e5f8108fe440657e8041afd973d2fe72180bb (diff)
[CRYPTO] camellia: Code cleanup
Optimize GETU32 to use 4-byte memcpy (modern gcc will convert such memcpy to single move instruction on i386). Original GETU32 did four byte fetches, and shifted/XORed those. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> Acked-by: Noriaki TAKAMIYA <takamiya@po.ntts.co.jp> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/camellia.c')
-rw-r--r--crypto/camellia.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/crypto/camellia.c b/crypto/camellia.c
index ac372e43e2a3..16529dddee72 100644
--- a/crypto/camellia.c
+++ b/crypto/camellia.c
@@ -330,10 +330,12 @@ static const u32 camellia_sp4404[256] = {
330 * macros 330 * macros
331 */ 331 */
332 332
333# define GETU32(pt) (((u32)(pt)[0] << 24) \ 333# define GETU32(v, pt) \
334 ^ ((u32)(pt)[1] << 16) \ 334 do { \
335 ^ ((u32)(pt)[2] << 8) \ 335 /* latest breed of gcc is clever enough to use move */ \
336 ^ ((u32)(pt)[3])) 336 memcpy(&(v), (pt), 4); \
337 (v) = be32_to_cpu(v); \
338 } while(0)
337 339
338/* rotation right shift 1byte */ 340/* rotation right shift 1byte */
339#define ROR8(x) (((x) >> 8) + ((x) << 24)) 341#define ROR8(x) (((x) >> 8) + ((x) << 24))
@@ -433,10 +435,11 @@ static void camellia_setup128(const unsigned char *key, u32 *subkey)
433 /** 435 /**
434 * k == kll || klr || krl || krr (|| is concatination) 436 * k == kll || klr || krl || krr (|| is concatination)
435 */ 437 */
436 kll = GETU32(key ); 438 GETU32(kll, key );
437 klr = GETU32(key + 4); 439 GETU32(klr, key + 4);
438 krl = GETU32(key + 8); 440 GETU32(krl, key + 8);
439 krr = GETU32(key + 12); 441 GETU32(krr, key + 12);
442
440 /** 443 /**
441 * generate KL dependent subkeys 444 * generate KL dependent subkeys
442 */ 445 */
@@ -687,8 +690,8 @@ static void camellia_setup128(const unsigned char *key, u32 *subkey)
687 690
688static void camellia_setup256(const unsigned char *key, u32 *subkey) 691static void camellia_setup256(const unsigned char *key, u32 *subkey)
689{ 692{
690 u32 kll,klr,krl,krr; /* left half of key */ 693 u32 kll, klr, krl, krr; /* left half of key */
691 u32 krll,krlr,krrl,krrr; /* right half of key */ 694 u32 krll, krlr, krrl, krrr; /* right half of key */
692 u32 il, ir, t0, t1, w0, w1; /* temporary variables */ 695 u32 il, ir, t0, t1, w0, w1; /* temporary variables */
693 u32 kw4l, kw4r, dw, tl, tr; 696 u32 kw4l, kw4r, dw, tl, tr;
694 u32 subL[34]; 697 u32 subL[34];
@@ -698,14 +701,14 @@ static void camellia_setup256(const unsigned char *key, u32 *subkey)
698 * key = (kll || klr || krl || krr || krll || krlr || krrl || krrr) 701 * key = (kll || klr || krl || krr || krll || krlr || krrl || krrr)
699 * (|| is concatination) 702 * (|| is concatination)
700 */ 703 */
701 kll = GETU32(key ); 704 GETU32(kll, key );
702 klr = GETU32(key + 4); 705 GETU32(klr, key + 4);
703 krl = GETU32(key + 8); 706 GETU32(krl, key + 8);
704 krr = GETU32(key + 12); 707 GETU32(krr, key + 12);
705 krll = GETU32(key + 16); 708 GETU32(krll, key + 16);
706 krlr = GETU32(key + 20); 709 GETU32(krlr, key + 20);
707 krrl = GETU32(key + 24); 710 GETU32(krrl, key + 24);
708 krrr = GETU32(key + 28); 711 GETU32(krrr, key + 28);
709 712
710 /* generate KL dependent subkeys */ 713 /* generate KL dependent subkeys */
711 /* kw1 */ 714 /* kw1 */