Exemple #1
0
        private static uint GFExp7(uint b, uint m)
        {
            if (b == 0u)
            {
                return(0u);
            }
            uint x = IceCryptoTransform.GFMultiply(b, b, m);

            x = IceCryptoTransform.GFMultiply(b, x, m);
            x = IceCryptoTransform.GFMultiply(x, x, m);
            return(IceCryptoTransform.GFMultiply(b, x, m));
        }
Exemple #2
0
 private static void InitializeSBox()
 {
     if (IceCryptoTransform.SBox == null)
     {
         IceCryptoTransform.SBox = new uint[4, 1024];
         for (int i = 0; i < 1024; i++)
         {
             int col = i >> 1 & 255;
             int row = (i & 1) | (i & 512) >> 8;
             IceCryptoTransform.SBox[0, i] = IceCryptoTransform.Perm32(IceCryptoTransform.GFExp7((uint)(col ^ IceCryptoTransform.SXor[0, row]), (uint)IceCryptoTransform.SMod[0, row]) << 24);
             IceCryptoTransform.SBox[1, i] = IceCryptoTransform.Perm32(IceCryptoTransform.GFExp7((uint)(col ^ IceCryptoTransform.SXor[1, row]), (uint)IceCryptoTransform.SMod[1, row]) << 16);
             IceCryptoTransform.SBox[2, i] = IceCryptoTransform.Perm32(IceCryptoTransform.GFExp7((uint)(col ^ IceCryptoTransform.SXor[2, row]), (uint)IceCryptoTransform.SMod[2, row]) << 8);
             IceCryptoTransform.SBox[3, i] = IceCryptoTransform.Perm32(IceCryptoTransform.GFExp7((uint)(col ^ IceCryptoTransform.SXor[3, row]), (uint)IceCryptoTransform.SMod[3, row]));
         }
     }
 }
Exemple #3
0
 internal IceCryptoTransform(int n, byte[] key, bool encrypt)
 {
     this.encrypt = encrypt;
     IceCryptoTransform.InitializeSBox();
     if (n == 0)
     {
         this.size   = 1;
         this.rounds = 8;
     }
     else
     {
         this.size   = n;
         this.rounds = n << 4;
     }
     this.keySchedule = new uint[this.rounds, 3];
     this.SetKey(key);
 }