コード例 #1
0
 private void init(ZWaveNode node)
 {
     //ZWaveNode node = null;
     if (enc == null)
     {
         enc = new AES_work();
     }
     SetupNetworkKey(node);
 }
コード例 #2
0
        private byte[] GenerateAuthentication(byte[] data, int start, int length, byte sendingNode, byte receivingNode, byte[] iv, AES_work enc)
        {
            // data should stat at 4
            byte[] buffer  = new byte[256];
            byte[] tmpauth = new byte[16];
            int    ib      = 0;

            buffer[ib]       = data[start + 0];
            ib++; buffer[ib] = sendingNode;
            ib++; buffer[ib] = receivingNode;
            ib++; buffer[ib] = (byte)(length - 19);
            Array.Copy(data, start + 9, buffer, 4, buffer[3]);

            byte[] buff = new byte[length - 19 + 4];
            Array.Copy(buffer, buff, length - 19 + 4);
//            Utility.logMessage("Raw Auth (minus IV)" + Utility.ByteArrayToString(buff));

            tmpauth = enc.ECB_EncryptMessage(authKey, iv);

            byte[] encpck = new byte[16];
            Array.Clear(encpck, 0, 16);

            int block = 0;

            for (int i = 0; i < buff.Length; i++)
            {
                encpck[block] = buff[i];
                block++;

                if (block == 16)
                {
                    for (int j = 0; j < 16; j++)
                    {
                        tmpauth[j] = (byte)(encpck[j] ^ tmpauth[j]);
                        encpck[j]  = 0;
                    }
                    block   = 0;
                    tmpauth = enc.ECB_EncryptMessage(authKey, tmpauth);
                }
            }

            /* any left over data that isn't a full block size*/
            if (block > 0)
            {
                for (int i = 0; i < 16; i++)
                {
                    tmpauth[i] = (byte)(encpck[i] ^ tmpauth[i]);
                }
                tmpauth = enc.ECB_EncryptMessage(authKey, tmpauth);
            }

            byte[] auth = new byte[8];
            Array.Copy(tmpauth, auth, 8);

//            Utility.logMessage("Computed Auth " + Utility.ByteArrayToString(auth));

            return(auth);
        }