Skip to content

Commit bd4b685

Browse files
committed
Fixed DiffieHellman issues
1 parent a7dfddf commit bd4b685

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
580580
byte[] aesKey = new byte[0];
581581
if(NetworkConfig.EnableEncryption)
582582
{
583-
ushort diffiePublicSize = reader.ReadUInt16();
584-
byte[] diffiePublic = reader.ReadBytes(diffiePublicSize);
583+
ushort diffiePublicSize = messageReader.ReadUInt16();
584+
byte[] diffiePublic = messageReader.ReadBytes(diffiePublicSize);
585585
diffieHellmanPublicKeys.Add(clientId, diffiePublic);
586586
/*
587587
EllipticDiffieHellman diffieHellman = new EllipticDiffieHellman(EllipticDiffieHellman.DEFAULT_CURVE, EllipticDiffieHellman.DEFAULT_GENERATOR, EllipticDiffieHellman.DEFAULT_ORDER);
@@ -619,8 +619,8 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
619619

620620
if (NetworkConfig.EnableEncryption)
621621
{
622-
ushort keyLength = reader.ReadUInt16();
623-
clientAesKey = clientDiffieHellman.GetSharedSecret(reader.ReadBytes(keyLength));
622+
ushort keyLength = messageReader.ReadUInt16();
623+
clientAesKey = clientDiffieHellman.GetSharedSecret(messageReader.ReadBytes(keyLength));
624624
}
625625

626626
float netTime = messageReader.ReadSingle();

MLAPI/NetworkingManagerComponents/DiffieHellman.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static byte[] ToArray(this IntX v)
8585
{
8686
v.GetInternalState(out uint[] digits, out bool negative);
8787
byte[] b = DigitConverter.ToBytes(digits);
88-
byte[] b1 = new byte[b.Length];
88+
byte[] b1 = new byte[b.Length + 1];
8989
Array.Copy(b, b1, b.Length);
9090
b1[b.Length] = (byte)(negative ? 1 : 0);
9191
return b1;
@@ -98,7 +98,7 @@ public static IntX FromArray(byte[] b)
9898
uint[] u = DigitConverter.FromBytes(b1);
9999
return new IntX(u, b[b.Length - 1]==1);
100100
}
101-
public static bool BitAt(this uint[] data, long index) => (data[index/8]&(1<<(int)(index%8)))!=0;
101+
public static bool BitAt(this uint[] data, long index) => (data[index / 32] & (1 << (int)(index % 32))) != 0;
102102
public static IntX Abs(this IntX i) => i < 0 ? -i : i;
103103
}
104104
}

0 commit comments

Comments
 (0)