Fixed DiffieHellman issues

This commit is contained in:
Albin Corén 2018-03-30 23:38:10 +02:00
parent 8dd5a36b78
commit ff6f16a265
2 changed files with 6 additions and 6 deletions

View File

@ -585,8 +585,8 @@ namespace MLAPI
byte[] aesKey = new byte[0]; byte[] aesKey = new byte[0];
if(NetworkConfig.EnableEncryption) if(NetworkConfig.EnableEncryption)
{ {
ushort diffiePublicSize = reader.ReadUInt16(); ushort diffiePublicSize = messageReader.ReadUInt16();
byte[] diffiePublic = reader.ReadBytes(diffiePublicSize); byte[] diffiePublic = messageReader.ReadBytes(diffiePublicSize);
diffieHellmanPublicKeys.Add(clientId, diffiePublic); diffieHellmanPublicKeys.Add(clientId, diffiePublic);
/* /*
EllipticDiffieHellman diffieHellman = new EllipticDiffieHellman(EllipticDiffieHellman.DEFAULT_CURVE, EllipticDiffieHellman.DEFAULT_GENERATOR, EllipticDiffieHellman.DEFAULT_ORDER); EllipticDiffieHellman diffieHellman = new EllipticDiffieHellman(EllipticDiffieHellman.DEFAULT_CURVE, EllipticDiffieHellman.DEFAULT_GENERATOR, EllipticDiffieHellman.DEFAULT_ORDER);
@ -624,8 +624,8 @@ namespace MLAPI
if (NetworkConfig.EnableEncryption) if (NetworkConfig.EnableEncryption)
{ {
ushort keyLength = reader.ReadUInt16(); ushort keyLength = messageReader.ReadUInt16();
clientAesKey = clientDiffieHellman.GetSharedSecret(reader.ReadBytes(keyLength)); clientAesKey = clientDiffieHellman.GetSharedSecret(messageReader.ReadBytes(keyLength));
} }
float netTime = messageReader.ReadSingle(); float netTime = messageReader.ReadSingle();

View File

@ -85,7 +85,7 @@ namespace MLAPI.NetworkingManagerComponents
{ {
v.GetInternalState(out uint[] digits, out bool negative); v.GetInternalState(out uint[] digits, out bool negative);
byte[] b = DigitConverter.ToBytes(digits); byte[] b = DigitConverter.ToBytes(digits);
byte[] b1 = new byte[b.Length]; byte[] b1 = new byte[b.Length + 1];
Array.Copy(b, b1, b.Length); Array.Copy(b, b1, b.Length);
b1[b.Length] = (byte)(negative ? 1 : 0); b1[b.Length] = (byte)(negative ? 1 : 0);
return b1; return b1;
@ -98,7 +98,7 @@ namespace MLAPI.NetworkingManagerComponents
uint[] u = DigitConverter.FromBytes(b1); uint[] u = DigitConverter.FromBytes(b1);
return new IntX(u, b[b.Length - 1]==1); 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; public static IntX Abs(this IntX i) => i < 0 ? -i : i;
} }
} }