diff options
| author | Jussi Kivilinna <jussi.kivilinna@mbnet.fi> | 2012-03-03 06:59:00 -0500 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2012-03-14 05:25:54 -0400 |
| commit | c9b56d33b03e9d5cd5f9d8598b56e9c84386844a (patch) | |
| tree | 6c9224ca235a9ef9aa662e4d104d67c56956915a /crypto | |
| parent | 894042648902d11d579af2a936a5a9a43cd5f1e4 (diff) | |
crypto: camellia - simplify key setup and CAMELLIA_ROUNDSM macro
camellia_setup_tail() applies 'inverse of the last half of P-function' to
subkeys, which is unneeded if keys are applied directly to yl/yr in
CAMELLIA_ROUNDSM.
Patch speeds up key setup and should speed up CAMELLIA_ROUNDSM as applying
key to yl/yr early has less register dependencies.
Quick tcrypt camellia results:
x86_64, AMD Phenom II, ~5% faster
x86_64, Intel Core 2, ~0.5% faster
i386, Intel Atom N270, ~1% faster
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
| -rw-r--r-- | crypto/camellia.c | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/crypto/camellia.c b/crypto/camellia.c index 64cff46ea5e4..7ae4bcddd1de 100644 --- a/crypto/camellia.c +++ b/crypto/camellia.c | |||
| @@ -382,7 +382,6 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max) | |||
| 382 | { | 382 | { |
| 383 | u32 dw, tl, tr; | 383 | u32 dw, tl, tr; |
| 384 | u32 kw4l, kw4r; | 384 | u32 kw4l, kw4r; |
| 385 | int i; | ||
| 386 | 385 | ||
| 387 | /* absorb kw2 to other subkeys */ | 386 | /* absorb kw2 to other subkeys */ |
| 388 | /* round 2 */ | 387 | /* round 2 */ |
| @@ -557,24 +556,6 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max) | |||
| 557 | SUBKEY_L(32) = subL[32] ^ subL[31]; /* kw3 */ | 556 | SUBKEY_L(32) = subL[32] ^ subL[31]; /* kw3 */ |
| 558 | SUBKEY_R(32) = subR[32] ^ subR[31]; | 557 | SUBKEY_R(32) = subR[32] ^ subR[31]; |
| 559 | } | 558 | } |
| 560 | |||
| 561 | /* apply the inverse of the last half of P-function */ | ||
| 562 | i = 2; | ||
| 563 | do { | ||
| 564 | dw = SUBKEY_L(i + 0) ^ SUBKEY_R(i + 0); dw = rol32(dw, 8);/* round 1 */ | ||
| 565 | SUBKEY_R(i + 0) = SUBKEY_L(i + 0) ^ dw; SUBKEY_L(i + 0) = dw; | ||
| 566 | dw = SUBKEY_L(i + 1) ^ SUBKEY_R(i + 1); dw = rol32(dw, 8);/* round 2 */ | ||
| 567 | SUBKEY_R(i + 1) = SUBKEY_L(i + 1) ^ dw; SUBKEY_L(i + 1) = dw; | ||
| 568 | dw = SUBKEY_L(i + 2) ^ SUBKEY_R(i + 2); dw = rol32(dw, 8);/* round 3 */ | ||
| 569 | SUBKEY_R(i + 2) = SUBKEY_L(i + 2) ^ dw; SUBKEY_L(i + 2) = dw; | ||
| 570 | dw = SUBKEY_L(i + 3) ^ SUBKEY_R(i + 3); dw = rol32(dw, 8);/* round 4 */ | ||
| 571 | SUBKEY_R(i + 3) = SUBKEY_L(i + 3) ^ dw; SUBKEY_L(i + 3) = dw; | ||
| 572 | dw = SUBKEY_L(i + 4) ^ SUBKEY_R(i + 4); dw = rol32(dw, 8);/* round 5 */ | ||
| 573 | SUBKEY_R(i + 4) = SUBKEY_L(i + 4) ^ dw; SUBKEY_L(i + 4) = dw; | ||
| 574 | dw = SUBKEY_L(i + 5) ^ SUBKEY_R(i + 5); dw = rol32(dw, 8);/* round 6 */ | ||
| 575 | SUBKEY_R(i + 5) = SUBKEY_L(i + 5) ^ dw; SUBKEY_L(i + 5) = dw; | ||
| 576 | i += 8; | ||
| 577 | } while (i < max); | ||
| 578 | } | 559 | } |
| 579 | 560 | ||
| 580 | static void camellia_setup128(const unsigned char *key, u32 *subkey) | 561 | static void camellia_setup128(const unsigned char *key, u32 *subkey) |
| @@ -869,6 +850,8 @@ static void camellia_setup192(const unsigned char *key, u32 *subkey) | |||
| 869 | 850 | ||
| 870 | #define CAMELLIA_ROUNDSM(xl, xr, kl, kr, yl, yr, il, ir) \ | 851 | #define CAMELLIA_ROUNDSM(xl, xr, kl, kr, yl, yr, il, ir) \ |
| 871 | do { \ | 852 | do { \ |
| 853 | yl ^= kl; \ | ||
| 854 | yr ^= kr; \ | ||
| 872 | ir = camellia_sp1110[(u8)xr]; \ | 855 | ir = camellia_sp1110[(u8)xr]; \ |
| 873 | il = camellia_sp1110[ (xl >> 24)]; \ | 856 | il = camellia_sp1110[ (xl >> 24)]; \ |
| 874 | ir ^= camellia_sp0222[ (xr >> 24)]; \ | 857 | ir ^= camellia_sp0222[ (xr >> 24)]; \ |
| @@ -877,8 +860,7 @@ static void camellia_setup192(const unsigned char *key, u32 *subkey) | |||
| 877 | il ^= camellia_sp3033[(u8)(xl >> 8)]; \ | 860 | il ^= camellia_sp3033[(u8)(xl >> 8)]; \ |
| 878 | ir ^= camellia_sp4404[(u8)(xr >> 8)]; \ | 861 | ir ^= camellia_sp4404[(u8)(xr >> 8)]; \ |
| 879 | il ^= camellia_sp4404[(u8)xl]; \ | 862 | il ^= camellia_sp4404[(u8)xl]; \ |
| 880 | il ^= kl; \ | 863 | ir ^= il; \ |
| 881 | ir ^= il ^ kr; \ | ||
| 882 | yl ^= ir; \ | 864 | yl ^= ir; \ |
| 883 | yr ^= ror32(il, 8) ^ ir; \ | 865 | yr ^= ror32(il, 8) ^ ir; \ |
| 884 | } while (0) | 866 | } while (0) |
