Skip to main content
polish
Source Link
kelalaka
  • 50k
  • 12
  • 125
  • 214

If you look at the code in the Wikipedia we will see this part of the code;

  • h = (unsigned char)((signed char)r[c] >> 7);
  • b[c] = r[c] << 1;
  • [c] ^= 0x1B & h;

h stores the leftmost bit of c

c is not x-or'ed with 0x1b but not with 0x11b why why?

When shifting r left by one, the MSB value is discarded. Before discarding, we hold this value with h holds the value.

  • If h==0 than modulus operation is not required. The 0x1B & h = 0x0 so there is 0 if h=0. Nono x-or with 0x11B0x1b
  • If h=1 than modulus operation is required. The 0x1B & h is = 0x1B if h=1. The x-or with 0x1b is performed. Note that
  • Note that: it is not x-or with 0x11B0x11b it is with 0x1B0x1b since we discarded the MSB 1 while shifting therefor no. Therefore, there is no need to xorx-or with 0x11B0x11b, x-oring with 0x1B0x1b is enough. Now, it is clear that everthing is in BytsBytes.

A small example;

A small example;Here [ ] represents 8-bit.

Let multiply $a = (x^7+x^6+x^3+x)$ by $\{2\}$

  • represent $a$ as binary $a = 11001010b$representation of $a = [11001010]$
  • h = 1$h = 1 = [00000001]$
  • $b = a \ll 1 = 110010100b$$b = a \ll 1 = 1[10010100]$ but everthing is in Bytes, therefore
  • $b = 10010100b$$b = [10010100]$
  • $h \wedge 0x1b = 1 \wedge 0x1b = 0x1b$$h \wedge 0x1b = [00000001] \wedge [00011011] = [00011011] = 0x1b$
  • $b \oplus 0x1b = 1001 0100b \oplus 0x00011011b = 10001111b$$b \oplus 0x1b = [10010100] \oplus [00011011] = [10001111] = 0x8f$

If you look at the code in the Wikipedia we will see this part of the code;

  • h = (unsigned char)((signed char)r[c] >> 7);
  • b[c] = r[c] << 1;
  • [c] ^= 0x1B & h;

h stores the leftmost bit of c

c is not x-or'ed with 0x11b why?

When shifting r left by one, the MSB value is discarded. Before discarding, h holds the value.

  • The 0x1B & h is 0 if h=0. No x-or with 0x11B
  • The 0x1B & h is 0x1B if h=1. x-or is performed. Note that it is not 0x11B it is 0x1B since we discarded the 1 while shifting therefor no need to xor with 0x11B, 0x1B is enough. Now, everthing is in Byts.

A small example; multiply $a = (x^7+x^6+x^3+x)$ by $\{2\}$

  • represent $a$ as binary $a = 11001010b$
  • h = 1
  • $b = a \ll 1 = 110010100b$ but everthing is in Bytes, therefore
  • $b = 10010100b$
  • $h \wedge 0x1b = 1 \wedge 0x1b = 0x1b$
  • $b \oplus 0x1b = 1001 0100b \oplus 0x00011011b = 10001111b$

If you look at the code in the Wikipedia we will see this part of the code;

  • h = (unsigned char)((signed char)r[c] >> 7);
  • b[c] = r[c] << 1;
  • [c] ^= 0x1B & h;

h stores the leftmost bit of c

c is x-or'ed with 0x1b but not with 0x11b why?

When shifting r left by one, the MSB value is discarded. Before discarding, we hold this value with h.

  • If h==0 than modulus operation is not required. The 0x1B & h = 0x0 so there is no x-or with 0x1b
  • If h=1 than modulus operation is required. The 0x1B & h = 0x1B. The x-or with 0x1b is performed.
  • Note that: it is not x-or with 0x11b it is with 0x1b since we discarded the MSB 1 while shifting. Therefore, there is no need to x-or with 0x11b, x-oring with 0x1b is enough. Now, it is clear that everthing is in Bytes.

A small example;

Here [ ] represents 8-bit.

Let multiply $a = (x^7+x^6+x^3+x)$ by $\{2\}$

  • binary representation of $a = [11001010]$
  • $h = 1 = [00000001]$
  • $b = a \ll 1 = 1[10010100]$ but everthing is in Bytes, therefore
  • $b = [10010100]$
  • $h \wedge 0x1b = [00000001] \wedge [00011011] = [00011011] = 0x1b$
  • $b \oplus 0x1b = [10010100] \oplus [00011011] = [10001111] = 0x8f$
added example
Source Link
kelalaka
  • 50k
  • 12
  • 125
  • 214

If you look at the code in the Wikipedia we will see this part of the code;

  • h = (unsigned char)((signed char)r[c] >> 7);
  • b[c] = r[c] << 1;
  • [c] ^= 0x1B & h;

h stores the leftmost bit of c

c is not x-or'ed with 0x11b why?

When shifting r left by one, the MSB value is discarded. Before discarding, h holds the value.

  • The 0x1B & h is 0 if h=0. No x-or with 0x11B
  • The 0x1B & h is 0x1B if h=1. x-or is performed. Note that it is not 0x11B it is 0x1B since we discarded the 1 while shifting therefor no need to xor with 0x11B, 0x1B is enough. Now, everthing is in Byts.

A small example; multiply $a = (x^7+x^6+x^3+x)$ by $\{2\}$

  • represent $a$ as binary $a = 11001010b$
  • h = 1
  • $b = a \ll 1 = 110010100b$ but everthing is in Bytes, therefore
  • $b = 10010100b$
  • $h \wedge 0x1b = 1 \wedge 0x1b = 0x1b$
  • $b \oplus 0x1b = 1001 0100b \oplus 0x00011011b = 10001111b$

If you look at the code in the Wikipedia we will see this part of the code;

  • h = (unsigned char)((signed char)r[c] >> 7);
  • b[c] = r[c] << 1;
  • [c] ^= 0x1B & h;

h stores the leftmost bit of c

c is not x-or'ed with 0x11b why?

When shifting r left by one, the MSB value is discarded. Before discarding, h holds the value.

  • The 0x1B & h is 0 if h=0. No x-or with 0x11B
  • The 0x1B & h is 0x1B if h=1. x-or is performed. Note that it is not 0x11B it is 0x1B since we discarded the 1 while shifting therefor no need to xor with 0x11B, 0x1B is enough. Now, everthing is in Byts.

If you look at the code in the Wikipedia we will see this part of the code;

  • h = (unsigned char)((signed char)r[c] >> 7);
  • b[c] = r[c] << 1;
  • [c] ^= 0x1B & h;

h stores the leftmost bit of c

c is not x-or'ed with 0x11b why?

When shifting r left by one, the MSB value is discarded. Before discarding, h holds the value.

  • The 0x1B & h is 0 if h=0. No x-or with 0x11B
  • The 0x1B & h is 0x1B if h=1. x-or is performed. Note that it is not 0x11B it is 0x1B since we discarded the 1 while shifting therefor no need to xor with 0x11B, 0x1B is enough. Now, everthing is in Byts.

A small example; multiply $a = (x^7+x^6+x^3+x)$ by $\{2\}$

  • represent $a$ as binary $a = 11001010b$
  • h = 1
  • $b = a \ll 1 = 110010100b$ but everthing is in Bytes, therefore
  • $b = 10010100b$
  • $h \wedge 0x1b = 1 \wedge 0x1b = 0x1b$
  • $b \oplus 0x1b = 1001 0100b \oplus 0x00011011b = 10001111b$
Source Link
kelalaka
  • 50k
  • 12
  • 125
  • 214

If you look at the code in the Wikipedia we will see this part of the code;

  • h = (unsigned char)((signed char)r[c] >> 7);
  • b[c] = r[c] << 1;
  • [c] ^= 0x1B & h;

h stores the leftmost bit of c

c is not x-or'ed with 0x11b why?

When shifting r left by one, the MSB value is discarded. Before discarding, h holds the value.

  • The 0x1B & h is 0 if h=0. No x-or with 0x11B
  • The 0x1B & h is 0x1B if h=1. x-or is performed. Note that it is not 0x11B it is 0x1B since we discarded the 1 while shifting therefor no need to xor with 0x11B, 0x1B is enough. Now, everthing is in Byts.