Skip to contentSkip to conversation

crypto/aes.c remove operator ? and variable t in bf_setkey

PATCH In review Frederik Sdun 2 participants 6 messages Jul 16, 2007 – Jul 25, 2007 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto/aes.c remove operator ? and variable t in bf_setkey

Hi,

this removes the the ? operator which is false nearly all the time.

aes.c 2007-07-16 01:56:49.000000000 +0200 renamed from aes.c.orig 2007-07-15 11:43:21.000000000 +0200 +5 -2
@@ -156,9 +156,12 @@
 
                p = (p << 1) ^ (p & 0x80 ? 0x01b : 0);
        }
+
+       sbx_tab[0] = 0x63;
+       isb_tab[0x63] = (u8) 0;
 
-       for (i = 0; i < 256; ++i) {
-               p = (i ? pow_tab[255 - log_tab[i]] : 0);
+       for (i = 1; i < 256; ++i) {
+               p = pow_tab[255 - log_tab[i]];
                q = ((p >> 7) | (p << 1)) ^ ((p >> 6) | (p << 2));
                p ^= 0x63 ^ q ^ ((q >> 6) | (q << 2));
                sbx_tab[i] = p;

this removes the variable t which is only a working copy of p, but you do not need a copy

@@ -135,7 +135,7 @@
static void __init
gen_tabs (void)
{
- u32 i, t;

+       u32 i;
        u8 p, q;
 
        /* log and power tables for GF(2**8) finite field with
@@ -168,38 +171,38 @@
        for (i = 0; i < 256; ++i) {
                p = sbx_tab[i];
-               t = p;
-               fl_tab[0][i] = t;
-               fl_tab[1][i] = rol32(t, 8);
-               fl_tab[2][i] = rol32(t, 16);
-               fl_tab[3][i] = rol32(t, 24);
+
+               fl_tab[0][i] = p;
+               fl_tab[1][i] = rol32(p, 8);
+               fl_tab[2][i] = rol32(p, 16);
+               fl_tab[3][i] = rol32(p, 24);
-               t = ((u32) ff_mult (2, p)) |
+               p = ((u32) ff_mult (2, p)) |
                    ((u32) p << 8) |
                    ((u32) p << 16) | ((u32) ff_mult (3, p) << 24);
-               ft_tab[0][i] = t;
-               ft_tab[1][i] = rol32(t, 8);
-               ft_tab[2][i] = rol32(t, 16);
-               ft_tab[3][i] = rol32(t, 24);
+               ft_tab[0][i] = p;
+               ft_tab[1][i] = rol32(p, 8);
+               ft_tab[2][i] = rol32(p, 16);
+               ft_tab[3][i] = rol32(p, 24);
                p = isb_tab[i];
-               t = p;
-               il_tab[0][i] = t;
-               il_tab[1][i] = rol32(t, 8);
-               il_tab[2][i] = rol32(t, 16);
-               il_tab[3][i] = rol32(t, 24);
+
+               il_tab[0][i] = p;
+               il_tab[1][i] = rol32(p, 8);
+               il_tab[2][i] = rol32(p, 16);
+               il_tab[3][i] = rol32(p, 24);
-               t = ((u32) ff_mult (14, p)) |
+               p = ((u32) ff_mult (14, p)) |
                    ((u32) ff_mult (9, p) << 8) |
                    ((u32) ff_mult (13, p) << 16) |
                    ((u32) ff_mult (11, p) << 24);
-               it_tab[0][i] = t;
-               it_tab[1][i] = rol32(t, 8);
-               it_tab[2][i] = rol32(t, 16);
-               it_tab[3][i] = rol32(t, 24);
+               it_tab[0][i] = p;
+               it_tab[1][i] = rol32(p, 8);
+               it_tab[2][i] = rol32(p, 16);
+               it_tab[3][i] = rol32(p, 24);
        }

}

Frederik

maintainer
#1 lore raw
Quoted 2 lines · Frederik Sdun

this removes the the ? operator which is false nearly all the time.

These changes look good. Could you please resend them as patches that can be directly applied and add a sign-off? You can refer to Documentation/SubmittingPatches for detailed instructions.

aes.c 2007-07-16 01:56:49.000000000 +0200 line 161

Quoted 9 lines
aes.c 2007-07-16 01:56:49.000000000 +0200 renamed from aes.c.orig 2007-07-15 11:43:21.000000000 +0200 +3 -0
@@ -156,9 +156,12 @@
 
                p = (p << 1) ^ (p & 0x80 ? 0x01b : 0);
        }
+
+       sbx_tab[0] = 0x63;
+       isb_tab[0x63] = (u8) 0;

Please kill that cast.

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw

Removed the temporary variable t.
Operator ? removed out of loop by false case.

aes.c 2007-07-16 14:38:57.000000000 +0200 renamed from aes.c.orig 2007-07-15 11:43:21.000000000 +0200 +24 -23
@@ -135,7 +135,7 @@ f_mult (u8 a, u8 b)
 static void __init
 gen_tabs (void)
 {
-       u32 i, t;
+       u32 i;
        u8 p, q;
 
        /* log and power tables for GF(2**8) finite field with
@@ -157,8 +157,11 @@ gen_tabs (void)
                p = (p << 1) ^ (p & 0x80 ? 0x01b : 0);
        }
 
-       for (i = 0; i < 256; ++i) {
-               p = (i ? pow_tab[255 - log_tab[i]] : 0);
+       sbx_tab[0] = 0x63;
+       isb_tab[0x63] = 0;
+
+       for (i = 1; i < 256; ++i) {
+               p = pow_tab[255 - log_tab[i]];
                q = ((p >> 7) | (p << 1)) ^ ((p >> 6) | (p << 2));
                p ^= 0x63 ^ q ^ ((q >> 6) | (q << 2));
                sbx_tab[i] = p;
@@ -168,38 +171,36 @@ gen_tabs (void)
        for (i = 0; i < 256; ++i) {
                p = sbx_tab[i];
 
-               t = p;
-               fl_tab[0][i] = t;
-               fl_tab[1][i] = rol32(t, 8);
-               fl_tab[2][i] = rol32(t, 16);
-               fl_tab[3][i] = rol32(t, 24);
+               fl_tab[0][i] = p;
+               fl_tab[1][i] = rol32(p, 8);
+               fl_tab[2][i] = rol32(p, 16);
+               fl_tab[3][i] = rol32(p, 24);
 
-               t = ((u32) ff_mult (2, p)) |
+               p = ((u32) ff_mult (2, p)) |
                    ((u32) p << 8) |
                    ((u32) p << 16) | ((u32) ff_mult (3, p) << 24);
 
-               ft_tab[0][i] = t;
-               ft_tab[1][i] = rol32(t, 8);
-               ft_tab[2][i] = rol32(t, 16);
-               ft_tab[3][i] = rol32(t, 24);
+               ft_tab[0][i] = p;
+               ft_tab[1][i] = rol32(p, 8);
+               ft_tab[2][i] = rol32(p, 16);
+               ft_tab[3][i] = rol32(p, 24);
 
                p = isb_tab[i];
 
-               t = p;
-               il_tab[0][i] = t;
-               il_tab[1][i] = rol32(t, 8);
-               il_tab[2][i] = rol32(t, 16);
-               il_tab[3][i] = rol32(t, 24);
+               il_tab[0][i] = p;
+               il_tab[1][i] = rol32(p, 8);
+               il_tab[2][i] = rol32(p, 16);
+               il_tab[3][i] = rol32(p, 24);
 
-               t = ((u32) ff_mult (14, p)) |
+               p = ((u32) ff_mult (14, p)) |
                    ((u32) ff_mult (9, p) << 8) |
                    ((u32) ff_mult (13, p) << 16) |
                    ((u32) ff_mult (11, p) << 24);
 
-               it_tab[0][i] = t;
-               it_tab[1][i] = rol32(t, 8);
-               it_tab[2][i] = rol32(t, 16);
-               it_tab[3][i] = rol32(t, 24);
+               it_tab[0][i] = p;
+               it_tab[1][i] = rol32(p, 8);
+               it_tab[2][i] = rol32(p, 16);
+               it_tab[3][i] = rol32(p, 24);
        }
 }
maintainer
#3 lore raw

Sorry, your patch doesn't apply.

aes.c 2007-07-16 14:38:57.000000000 +0200

Quoted 3 lines · Frederik Sdun
aes.c 2007-07-16 14:38:57.000000000 +0200 renamed from aes.c.orig 2007-07-15 11:43:21.000000000 +0200 +0 -0

Please make sure your patch can be applied with patch -p1.

aes.c 2007-07-16 14:38:57.000000000 +0200 f_mult (u8 a, u8 b) · line 138

Quoted 6 lines
aes.c 2007-07-16 14:38:57.000000000 +0200 renamed from aes.c.orig 2007-07-15 11:43:21.000000000 +0200 +1 -1
@@ -135,7 +135,7 @@ f_mult (u8 a, u8 b)
 static void __init
 gen_tabs (void)
 {
-       u32 i, t;
+       u32 i;

Your mailer has corrupted the tabs.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#4 lore raw

Hi
now i have the failure in my patch. i excuse for the spamming and foolness.

happy coding Frederik

Removed the temporary variable t which is not needed working copy of p. Operator ? removed out of loop by false case.

crypto/aes.c 2007-07-18 23:40:49.000000000 +0200 renamed from crypto/aes.c.orig 2007-07-15 11:43:21.000000000 +0200 +24 -23
@@ -135,7 +135,7 @@ f_mult (u8 a, u8 b)
 static void __init
 gen_tabs (void)
 {
-       u32 i, t;
+       u32 i;
        u8 p, q;
 
        /* log and power tables for GF(2**8) finite field with
@@ -157,8 +157,11 @@ gen_tabs (void)
                p = (p << 1) ^ (p & 0x80 ? 0x01b : 0);
        }
 
-       for (i = 0; i < 256; ++i) {
-               p = (i ? pow_tab[255 - log_tab[i]] : 0);
+       sbx_tab[0] = 0x63;
+       isb_tab[0x63] = 0;
+
+       for (i = 1; i < 256; ++i) {
+               p = pow_tab[255 - log_tab[i]];
                q = ((p >> 7) | (p << 1)) ^ ((p >> 6) | (p << 2));
                p ^= 0x63 ^ q ^ ((q >> 6) | (q << 2));
                sbx_tab[i] = p;
@@ -168,38 +171,36 @@ gen_tabs (void)
        for (i = 0; i < 256; ++i) {
                p = sbx_tab[i];
 
-               t = p;
-               fl_tab[0][i] = t;
-               fl_tab[1][i] = rol32(t, 8);
-               fl_tab[2][i] = rol32(t, 16);
-               fl_tab[3][i] = rol32(t, 24);
+               fl_tab[0][i] = p;
+               fl_tab[1][i] = rol32(p, 8);
+               fl_tab[2][i] = rol32(p, 16);
+               fl_tab[3][i] = rol32(p, 24);
 
-               t = ((u32) ff_mult (2, p)) |
+               p = ((u32) ff_mult (2, p)) |
                    ((u32) p << 8) |
                    ((u32) p << 16) | ((u32) ff_mult (3, p) << 24);
 
-               ft_tab[0][i] = t;
-               ft_tab[1][i] = rol32(t, 8);
-               ft_tab[2][i] = rol32(t, 16);
-               ft_tab[3][i] = rol32(t, 24);
+               ft_tab[0][i] = p;
+               ft_tab[1][i] = rol32(p, 8);
+               ft_tab[2][i] = rol32(p, 16);
+               ft_tab[3][i] = rol32(p, 24);
 
                p = isb_tab[i];
 
-               t = p;
-               il_tab[0][i] = t;
-               il_tab[1][i] = rol32(t, 8);
-               il_tab[2][i] = rol32(t, 16);
-               il_tab[3][i] = rol32(t, 24);
+               il_tab[0][i] = p;
+               il_tab[1][i] = rol32(p, 8);
+               il_tab[2][i] = rol32(p, 16);
+               il_tab[3][i] = rol32(p, 24);
 
-               t = ((u32) ff_mult (14, p)) |
+               p = ((u32) ff_mult (14, p)) |
                    ((u32) ff_mult (9, p) << 8) |
                    ((u32) ff_mult (13, p) << 16) |
                    ((u32) ff_mult (11, p) << 24);
 
-               it_tab[0][i] = t;
-               it_tab[1][i] = rol32(t, 8);
-               it_tab[2][i] = rol32(t, 16);
-               it_tab[3][i] = rol32(t, 24);
+               it_tab[0][i] = p;
+               it_tab[1][i] = rol32(p, 8);
+               it_tab[2][i] = rol32(p, 16);
+               it_tab[3][i] = rol32(p, 24);
        }
 }
maintainer
#5 lore raw
Quoted 3 lines · Frederik Sdun

Removed the temporary variable t which is not needed working copy of p. Operator ? removed out of loop by false case.

Sorry, the tabs are still coming across as spaces.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt