Skip to content

Commit ff6f16a

Browse files
committed
Fixed DiffieHellman issues
1 parent 8dd5a36 commit ff6f16a

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
@@ -585,8 +585,8 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
585585
byte[] aesKey = new byte[0];
586586
if(NetworkConfig.EnableEncryption)
587587
{
588-
ushort diffiePublicSize = reader.ReadUInt16();
589-
byte[] diffiePublic = reader.ReadBytes(diffiePublicSize);
588+
ushort diffiePublicSize = messageReader.ReadUInt16();
589+
byte[] diffiePublic = messageReader.ReadBytes(diffiePublicSize);
590590
diffieHellmanPublicKeys.Add(clientId, diffiePublic);
591591
/*
592592
EllipticDiffieHellman diffieHellman = new EllipticDiffieHellman(EllipticDiffieHellman.DEFAULT_CURVE, EllipticDiffieHellman.DEFAULT_GENERATOR, EllipticDiffieHellman.DEFAULT_ORDER);
@@ -624,8 +624,8 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
624624

625625
if (NetworkConfig.EnableEncryption)
626626
{
627-
ushort keyLength = reader.ReadUInt16();
628-
clientAesKey = clientDiffieHellman.GetSharedSecret(reader.ReadBytes(keyLength));
627+
ushort keyLength = messageReader.ReadUInt16();
628+
clientAesKey = clientDiffieHellman.GetSharedSecret(messageReader.ReadBytes(keyLength));
629629
}
630630

631631
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)