-
set testing code
I have a S-Box(lookup table) that I'm trying to test. The test involved creating a set (the details are very small and in the attachment, so its formated nicely) and checking its size. Since I'm working in a GF(2^4), that means additions and subtraction are both equivalent to a XOR.
I ran my code on a S-Box I'm sure is supposed to pass. I cant figure out why.
Anyone mind taking a look?
Thanks?
Code:
int testCond1(unsigned char *sbox) {
int count;
for(unsigned char d_input = 1; d_input < 16; ++d_input) {
for(unsigned char d_output = 1; d_output < 16; ++d_output) {
count = 0;
for(unsigned char x = 0; x < 16; ++x) {
if(sbox[x] ^ sbox[x ^ d_input] == d_output)
++count;
}
if(count > 4)
return 1;
}
}
return 0;
}
-
The code matches the text perfectly, on the assumption that you intend 1 to be "false" and 0 to be "true" (or 0 means "passes the test" and 1 means "fails the test").
-
Maybe a example would make this alittle more clear. Im using this S-Box:
Code:
unsigned char sbox4[16] = {0xC, 0x5, 0x6, 0xB, 0x9, 0x0, 0xA, 0xD, 0x3, 0xE, 0xF, 0x8, 0x4, 0x7, 0x1, 0x2};
Let d_input = d_output = 1
Let x = 0;
sbox4[0] ^ sbox4[0 ^ 1] == 1
sbox4[0] ^ sbox4[1] == 1
0xC ^ 0x5 == 1
0b1100 ^ 0b101 == 1
0x1001 == 1 // false! it passes... unless you use my code
-
Also, this:
Code:
if(sbox[x] ^ sbox[x ^ d_input] == d_output)
is not the same as this:
Code:
if((sbox[x] ^ sbox[x ^ d_input]) == d_output)
as your compiler mentioned. Guess which one you want.
-
Yes! That did it!
Thanks. I never seem to catch one to things like that....
-
Alright, hate to say it but I think I have a new and hopefully not related problem. This time I think its related to my FC function.
Code:
unsigned char gf_mult(unsigned char a, unsigned char b) {
unsigned char p = a;
int wt = (b >> 3) ^ (1 & (b >> 2)) ^ (1 & (b >> 1)) ^ (1 & b);
p ^= a << (3 * (1 & ( b >> 3)));
p ^= a << (2 * (1 & ( b >> 2)));
p ^= a << (1 & ( b >> 1));
p ^= a*wt;
return (0x0F & p);
}
char fc(unsigned char *sbox, unsigned char a, unsigned char b) {
char retval = 0;
unsigned char x;
for(x = 0; x < 16; ++x) {
if((gf_mult(b, sbox[x]) ^ gf_mult(a, x)) % 2 == 0)
++retval;
else
--retval;
}
return retval;
}
-
What does <pointy brackets> represent in this case -- or equivalently to what do a and b belong?
-
Im fairly sure <A, B> means the inner product, so in this case just A*B.
A and B are both in the GF(2^4) and change, so I made them variables in my code.
Hope that helps
-
Inner product as a 4-vector over F_2? Technically, that's not possible since F_2 doesn't form any inner product spaces. I would suggest going back to check that.