From ff6f16a265ddd9684499ac9d336d6e8f93f8f762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Cor=C3=A9n?= <2108U9@gmail.com> Date: Fri, 30 Mar 2018 23:38:10 +0200 Subject: [PATCH] Fixed DiffieHellman issues --- MLAPI/MonoBehaviours/Core/NetworkingManager.cs | 8 ++++---- MLAPI/NetworkingManagerComponents/DiffieHellman.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs index 6678155..2136191 100644 --- a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs +++ b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs @@ -585,8 +585,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); @@ -624,8 +624,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; } }