diff --git a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs index 96ea2bd..8dffd93 100644 --- a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs +++ b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs @@ -580,8 +580,8 @@ namespace MLAPI byte[] aesKey = new byte[0]; if(NetworkConfig.EnableEncryption) { - ushort diffiePublicSize = reader.ReadUInt16(); - byte[] diffiePublic = reader.ReadBytes(diffiePublicSize); + ushort diffiePublicSize = messageReader.ReadUInt16(); + byte[] diffiePublic = messageReader.ReadBytes(diffiePublicSize); diffieHellmanPublicKeys.Add(clientId, diffiePublic); /* EllipticDiffieHellman diffieHellman = new EllipticDiffieHellman(EllipticDiffieHellman.DEFAULT_CURVE, EllipticDiffieHellman.DEFAULT_GENERATOR, EllipticDiffieHellman.DEFAULT_ORDER); @@ -619,8 +619,8 @@ namespace MLAPI if (NetworkConfig.EnableEncryption) { - ushort keyLength = reader.ReadUInt16(); - clientAesKey = clientDiffieHellman.GetSharedSecret(reader.ReadBytes(keyLength)); + ushort keyLength = messageReader.ReadUInt16(); + clientAesKey = clientDiffieHellman.GetSharedSecret(messageReader.ReadBytes(keyLength)); } float netTime = messageReader.ReadSingle(); diff --git a/MLAPI/NetworkingManagerComponents/DiffieHellman.cs b/MLAPI/NetworkingManagerComponents/DiffieHellman.cs index d7885f9..4915ddf 100644 --- a/MLAPI/NetworkingManagerComponents/DiffieHellman.cs +++ b/MLAPI/NetworkingManagerComponents/DiffieHellman.cs @@ -85,7 +85,7 @@ namespace MLAPI.NetworkingManagerComponents { v.GetInternalState(out uint[] digits, out bool negative); byte[] b = DigitConverter.ToBytes(digits); - byte[] b1 = new byte[b.Length]; + byte[] b1 = new byte[b.Length + 1]; Array.Copy(b, b1, b.Length); b1[b.Length] = (byte)(negative ? 1 : 0); return b1; @@ -98,7 +98,7 @@ namespace MLAPI.NetworkingManagerComponents uint[] u = DigitConverter.FromBytes(b1); return new IntX(u, b[b.Length - 1]==1); } - public static bool BitAt(this uint[] data, long index) => (data[index/8]&(1<<(int)(index%8)))!=0; + public static bool BitAt(this uint[] data, long index) => (data[index / 32] & (1 << (int)(index % 32))) != 0; public static IntX Abs(this IntX i) => i < 0 ? -i : i; } }