From d38143cca7cebb5bb2577298f4d1cc5c727106cf Mon Sep 17 00:00:00 2001 From: lidgren Date: Fri, 10 Oct 2014 07:35:17 +0000 Subject: [PATCH] Encryption fixed --- Lidgren.Network/Encryption/INetEncryption.cs | 21 ---------- .../Encryption/NetAESEncryption.cs | 35 +++++++++++------ .../Encryption/NetBlockEncryptionBase.cs | 9 +++-- .../Encryption/NetDESEncryption.cs | 38 ++++++++++++------- Lidgren.Network/Encryption/NetEncryption.cs | 36 ++++++++++++++++++ .../Encryption/NetRC2Encryption.cs | 38 ++++++++++++------- .../Encryption/NetTripleDESEncryption.cs | 36 +++++++++++------- .../Encryption/NetXorEncryption.cs | 12 +++--- .../Encryption/NetXteaEncryption.cs | 11 +++--- Lidgren.Network/Lidgren.Network.csproj | 18 ++++++--- Lidgren.Network/NetBuffer.Read.cs | 1 + Lidgren.Network/NetIncomingMessage.cs | 2 +- Lidgren.Network/NetOutgoingMessage.cs | 2 +- Lidgren.Network/NetSRP.cs | 4 +- 14 files changed, 167 insertions(+), 96 deletions(-) delete mode 100644 Lidgren.Network/Encryption/INetEncryption.cs create mode 100644 Lidgren.Network/Encryption/NetEncryption.cs diff --git a/Lidgren.Network/Encryption/INetEncryption.cs b/Lidgren.Network/Encryption/INetEncryption.cs deleted file mode 100644 index 15e923c..0000000 --- a/Lidgren.Network/Encryption/INetEncryption.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Lidgren.Network -{ - /// - /// Interface for an encryption algorithm - /// - public interface INetEncryption - { - /// - /// Encrypt an outgoing message in place - /// - bool Encrypt(NetOutgoingMessage msg); - - /// - /// Decrypt an incoming message in place - /// - bool Decrypt(NetIncomingMessage msg); - } -} diff --git a/Lidgren.Network/Encryption/NetAESEncryption.cs b/Lidgren.Network/Encryption/NetAESEncryption.cs index 487a903..8f74ce3 100644 --- a/Lidgren.Network/Encryption/NetAESEncryption.cs +++ b/Lidgren.Network/Encryption/NetAESEncryption.cs @@ -9,7 +9,7 @@ namespace Lidgren.Network /// /// AES encryption /// - public class NetAESEncryption : INetEncryption + public class NetAESEncryption : NetEncryption { private readonly byte[] m_key; private readonly byte[] m_iv; @@ -52,7 +52,8 @@ namespace Lidgren.Network /// /// NetAESEncryption constructor /// - public NetAESEncryption(byte[] key, byte[] iv) + public NetAESEncryption(NetPeer peer, byte[] key, byte[] iv) + : base(peer) { if (!s_keysizes.Contains(key.Length * 8)) throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes))); @@ -68,7 +69,8 @@ namespace Lidgren.Network /// /// NetAESEncryption constructor /// - public NetAESEncryption(string key, int bitsize) + public NetAESEncryption(NetPeer peer, string key, int bitsize) + : base(peer) { if (!s_keysizes.Contains(bitsize)) throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes))); @@ -93,20 +95,19 @@ namespace Lidgren.Network /// /// NetAESEncryption constructor /// - public NetAESEncryption(string key) - : this(key, s_keysizes[0]) + public NetAESEncryption(NetPeer peer, string key) + : this(peer, key, s_keysizes[0]) { } /// /// Encrypt outgoing message /// - public bool Encrypt(NetOutgoingMessage msg) + public override bool Encrypt(NetOutgoingMessage msg) { #if !IOS && !__ANDROID__ && !UNITY_4_5 try { - // nested usings are fun! using (AesCryptoServiceProvider aesCryptoServiceProvider = new AesCryptoServiceProvider { KeySize = m_bitSize, Mode = CipherMode.CBC }) { using (ICryptoTransform cryptoTransform = aesCryptoServiceProvider.CreateEncryptor(m_key, m_iv)) @@ -116,14 +117,19 @@ namespace Lidgren.Network { cryptoStream.Write(msg.m_data, 0, msg.m_data.Length); cryptoStream.Close(); - msg.m_data = memoryStream.ToArray(); + + m_peer.Recycle(msg.m_data); + var arr = memoryStream.ToArray(); + msg.m_data = arr; + msg.m_bitLength = arr.Length * 8; } } } } - catch + catch(Exception ex) { + m_peer.LogWarning("Encryption failed: " + ex); return false; } return true; @@ -135,7 +141,7 @@ namespace Lidgren.Network /// /// Decrypt incoming message /// - public bool Decrypt(NetIncomingMessage msg) + public override bool Decrypt(NetIncomingMessage msg) { #if !IOS && !__ANDROID__ && !UNITY_4_5 try @@ -150,14 +156,19 @@ namespace Lidgren.Network { cryptoStream.Write(msg.m_data, 0, msg.m_data.Length); cryptoStream.Close(); - msg.m_data = memoryStream.ToArray(); + + m_peer.Recycle(msg.m_data); + var arr = memoryStream.ToArray(); + msg.m_data = arr; + msg.m_bitLength = arr.Length * 8; } } } } - catch + catch (Exception ex) { + m_peer.LogWarning("Decryption failed: " + ex); return false; } return true; diff --git a/Lidgren.Network/Encryption/NetBlockEncryptionBase.cs b/Lidgren.Network/Encryption/NetBlockEncryptionBase.cs index 07a0443..3356ada 100644 --- a/Lidgren.Network/Encryption/NetBlockEncryptionBase.cs +++ b/Lidgren.Network/Encryption/NetBlockEncryptionBase.cs @@ -6,7 +6,7 @@ namespace Lidgren.Network /// /// Base for a non-threadsafe encryption class /// - public abstract class NetBlockEncryptionBase : INetEncryption + public abstract class NetBlockEncryptionBase : NetEncryption { // temporary space for one block to avoid reallocating every time private byte[] m_tmp; @@ -19,7 +19,8 @@ namespace Lidgren.Network /// /// NetBlockEncryptionBase constructor /// - public NetBlockEncryptionBase() + public NetBlockEncryptionBase(NetPeer peer) + : base(peer) { m_tmp = new byte[BlockSize]; } @@ -27,7 +28,7 @@ namespace Lidgren.Network /// /// Encrypt am outgoing message with this algorithm; no writing can be done to the message after encryption, or message will be corrupted /// - public bool Encrypt(NetOutgoingMessage msg) + public override bool Encrypt(NetOutgoingMessage msg) { int payloadBitLength = msg.LengthBits; int numBytes = msg.LengthBytes; @@ -55,7 +56,7 @@ namespace Lidgren.Network /// /// message to decrypt /// true if successful; false if failed - public bool Decrypt(NetIncomingMessage msg) + public override bool Decrypt(NetIncomingMessage msg) { int numEncryptedBytes = msg.LengthBytes - 4; // last 4 bytes is true bit length int blockSize = BlockSize; diff --git a/Lidgren.Network/Encryption/NetDESEncryption.cs b/Lidgren.Network/Encryption/NetDESEncryption.cs index 58f5e1f..396e49a 100644 --- a/Lidgren.Network/Encryption/NetDESEncryption.cs +++ b/Lidgren.Network/Encryption/NetDESEncryption.cs @@ -9,7 +9,7 @@ namespace Lidgren.Network /// /// DES encryption /// - public class NetDESEncryption : INetEncryption + public class NetDESEncryption : NetEncryption { private readonly byte[] m_key; private readonly byte[] m_iv; @@ -51,13 +51,14 @@ namespace Lidgren.Network /// /// NetDESEncryption constructor /// - public NetDESEncryption(byte[] key, byte[] iv) + public NetDESEncryption(NetPeer peer, byte[] key, byte[] iv) + : base(peer) { if (!s_keysizes.Contains(key.Length * 8)) throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes))); if (!s_blocksizes.Contains(iv.Length * 8)) - throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_blocksizes))); + throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_blocksizes))); m_key = key; m_iv = iv; @@ -67,7 +68,8 @@ namespace Lidgren.Network /// /// NetDESEncryption constructor /// - public NetDESEncryption(string key, int bitsize) + public NetDESEncryption(NetPeer peer, string key, int bitsize) + : base(peer) { if (!s_keysizes.Contains(bitsize)) throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes))); @@ -92,19 +94,18 @@ namespace Lidgren.Network /// /// NetDESEncryption constructor /// - public NetDESEncryption(string key) - : this(key, s_keysizes[0]) + public NetDESEncryption(NetPeer peer, string key) + : this(peer, key, s_keysizes[0]) { } /// /// Encrypt outgoing message /// - public bool Encrypt(NetOutgoingMessage msg) + public override bool Encrypt(NetOutgoingMessage msg) { try { - // nested usings are fun! using (DESCryptoServiceProvider desCryptoServiceProvider = new DESCryptoServiceProvider { KeySize = m_bitSize, Mode = CipherMode.CBC }) { using (ICryptoTransform cryptoTransform = desCryptoServiceProvider.CreateEncryptor(m_key, m_iv)) @@ -114,14 +115,19 @@ namespace Lidgren.Network { cryptoStream.Write(msg.m_data, 0, msg.m_data.Length); cryptoStream.Close(); - msg.m_data = memoryStream.ToArray(); + + m_peer.Recycle(msg.m_data); + var arr = memoryStream.ToArray(); + msg.m_data = arr; + msg.m_bitLength = arr.Length * 8; } } } } - catch + catch (Exception ex) { + m_peer.LogWarning("Encryption failed: " + ex); return false; } return true; @@ -130,11 +136,10 @@ namespace Lidgren.Network /// /// Decrypt incoming message /// - public bool Decrypt(NetIncomingMessage msg) + public override bool Decrypt(NetIncomingMessage msg) { try { - // nested usings are fun! using (DESCryptoServiceProvider desCryptoServiceProvider = new DESCryptoServiceProvider { KeySize = m_bitSize, Mode = CipherMode.CBC }) { using (ICryptoTransform cryptoTransform = desCryptoServiceProvider.CreateDecryptor(m_key, m_iv)) @@ -144,14 +149,19 @@ namespace Lidgren.Network { cryptoStream.Write(msg.m_data, 0, msg.m_data.Length); cryptoStream.Close(); - msg.m_data = memoryStream.ToArray(); + + m_peer.Recycle(msg.m_data); + var arr = memoryStream.ToArray(); + msg.m_data = arr; + msg.m_bitLength = arr.Length * 8; } } } } - catch + catch (Exception ex) { + m_peer.LogWarning("Decryption failed: " + ex); return false; } return true; diff --git a/Lidgren.Network/Encryption/NetEncryption.cs b/Lidgren.Network/Encryption/NetEncryption.cs new file mode 100644 index 0000000..80e3942 --- /dev/null +++ b/Lidgren.Network/Encryption/NetEncryption.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; + +namespace Lidgren.Network +{ + /// + /// Interface for an encryption algorithm + /// + public abstract class NetEncryption + { + /// + /// NetPeer + /// + protected NetPeer m_peer; + + /// + /// Constructor + /// + public NetEncryption(NetPeer peer) + { + if (peer == null) + throw new NetException("Peer must not be null"); + m_peer = peer; + } + + /// + /// Encrypt an outgoing message in place + /// + public abstract bool Encrypt(NetOutgoingMessage msg); + + /// + /// Decrypt an incoming message in place + /// + public abstract bool Decrypt(NetIncomingMessage msg); + } +} diff --git a/Lidgren.Network/Encryption/NetRC2Encryption.cs b/Lidgren.Network/Encryption/NetRC2Encryption.cs index 35b752f..3886ccb 100644 --- a/Lidgren.Network/Encryption/NetRC2Encryption.cs +++ b/Lidgren.Network/Encryption/NetRC2Encryption.cs @@ -9,7 +9,7 @@ namespace Lidgren.Network /// /// RC2 encryption /// - public class NetRC2Encryption : INetEncryption + public class NetRC2Encryption : NetEncryption { private readonly byte[] m_key; private readonly byte[] m_iv; @@ -51,7 +51,8 @@ namespace Lidgren.Network /// /// NetRC2Encryption constructor /// - public NetRC2Encryption(byte[] key, byte[] iv) + public NetRC2Encryption(NetPeer peer, byte[] key, byte[] iv) + : base(peer) { if (!s_keysizes.Contains(key.Length * 8)) throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes))); @@ -67,11 +68,12 @@ namespace Lidgren.Network /// /// NetRC2Encryption constructor /// - public NetRC2Encryption(string key, int bitsize) + public NetRC2Encryption(NetPeer peer, string key, int bitsize) + : base(peer) { if (!s_keysizes.Contains(bitsize)) throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes))); - + byte[] entropy = Encoding.UTF32.GetBytes(key); // I know hardcoding salts is bad, but in this case I think it is acceptable. HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL==")); @@ -92,20 +94,20 @@ namespace Lidgren.Network /// /// NetRC2Encryption constructor /// + /// /// - public NetRC2Encryption(string key) - : this(key, s_keysizes[0]) + public NetRC2Encryption(NetPeer peer, string key) + : this(peer, key, s_keysizes[0]) { } /// /// Encrypt outgoing message /// - public bool Encrypt(NetOutgoingMessage msg) + public override bool Encrypt(NetOutgoingMessage msg) { try { - // nested usings are fun! using (RC2CryptoServiceProvider rc2CryptoServiceProvider = new RC2CryptoServiceProvider { KeySize = m_bitSize, Mode = CipherMode.CBC }) { using (ICryptoTransform cryptoTransform = rc2CryptoServiceProvider.CreateEncryptor(m_key, m_iv)) @@ -115,14 +117,19 @@ namespace Lidgren.Network { cryptoStream.Write(msg.m_data, 0, msg.m_data.Length); cryptoStream.Close(); - msg.m_data = memoryStream.ToArray(); + + m_peer.Recycle(msg.m_data); + var arr = memoryStream.ToArray(); + msg.m_data = arr; + msg.m_bitLength = arr.Length * 8; } } } } - catch + catch (Exception ex) { + m_peer.LogWarning("Encryption failed: " + ex); return false; } return true; @@ -131,7 +138,7 @@ namespace Lidgren.Network /// /// Decrypt incoming message /// - public bool Decrypt(NetIncomingMessage msg) + public override bool Decrypt(NetIncomingMessage msg) { try { @@ -145,14 +152,19 @@ namespace Lidgren.Network { cryptoStream.Write(msg.m_data, 0, msg.m_data.Length); cryptoStream.Close(); - msg.m_data = memoryStream.ToArray(); + + m_peer.Recycle(msg.m_data); + var arr = memoryStream.ToArray(); + msg.m_data = arr; + msg.m_bitLength = arr.Length * 8; } } } } - catch + catch (Exception ex) { + m_peer.LogWarning("Decryption failed: " + ex); return false; } return true; diff --git a/Lidgren.Network/Encryption/NetTripleDESEncryption.cs b/Lidgren.Network/Encryption/NetTripleDESEncryption.cs index 1c9c00d..ed64c5b 100644 --- a/Lidgren.Network/Encryption/NetTripleDESEncryption.cs +++ b/Lidgren.Network/Encryption/NetTripleDESEncryption.cs @@ -9,7 +9,7 @@ namespace Lidgren.Network /// /// Triple DES encryption /// - public class NetTripleDESEncryption : INetEncryption + public class NetTripleDESEncryption : NetEncryption { private readonly byte[] m_key; private readonly byte[] m_iv; @@ -19,7 +19,6 @@ namespace Lidgren.Network static NetTripleDESEncryption() { - TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider(); List temp = new List(); foreach (KeySizes keysize in tripleDES.LegalKeySizes) @@ -51,7 +50,8 @@ namespace Lidgren.Network /// /// NetTriplsDESEncryption constructor /// - public NetTripleDESEncryption(byte[] key, byte[] iv) + public NetTripleDESEncryption(NetPeer peer, byte[] key, byte[] iv) + : base(peer) { if (!s_keysizes.Contains(key.Length * 8)) throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes))); @@ -67,7 +67,8 @@ namespace Lidgren.Network /// /// NetTriplsDESEncryption constructor /// - public NetTripleDESEncryption(string key, int bitsize) + public NetTripleDESEncryption(NetPeer peer, string key, int bitsize) + : base(peer) { if (!s_keysizes.Contains(bitsize)) throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes))); @@ -92,19 +93,18 @@ namespace Lidgren.Network /// /// NetTriplsDESEncryption constructor /// - public NetTripleDESEncryption(string key) - : this(key, s_keysizes[0]) + public NetTripleDESEncryption(NetPeer peer, string key) + : this(peer, key, s_keysizes[0]) { } /// /// Encrypt outgoing message /// - public bool Encrypt(NetOutgoingMessage msg) + public override bool Encrypt(NetOutgoingMessage msg) { try { - // nested usings are fun! using (TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider { KeySize = m_bitSize, Mode = CipherMode.CBC }) { using (ICryptoTransform cryptoTransform = tripleDESCryptoServiceProvider.CreateEncryptor(m_key, m_iv)) @@ -114,14 +114,19 @@ namespace Lidgren.Network { cryptoStream.Write(msg.m_data, 0, msg.m_data.Length); cryptoStream.Close(); - msg.m_data = memoryStream.ToArray(); + + m_peer.Recycle(msg.m_data); + var arr = memoryStream.ToArray(); + msg.m_data = arr; + msg.m_bitLength = arr.Length * 8; } } } } - catch + catch (Exception ex) { + m_peer.LogWarning("Encryption failed: " + ex); return false; } return true; @@ -130,7 +135,7 @@ namespace Lidgren.Network /// /// Decrypt incoming message /// - public bool Decrypt(NetIncomingMessage msg) + public override bool Decrypt(NetIncomingMessage msg) { try { @@ -144,14 +149,19 @@ namespace Lidgren.Network { cryptoStream.Write(msg.m_data, 0, msg.m_data.Length); cryptoStream.Close(); - msg.m_data = memoryStream.ToArray(); + + m_peer.Recycle(msg.m_data); + var arr = memoryStream.ToArray(); + msg.m_data = arr; + msg.m_bitLength = arr.Length * 8; } } } } - catch + catch (Exception ex) { + m_peer.LogWarning("Decryption failed: " + ex); return false; } return true; diff --git a/Lidgren.Network/Encryption/NetXorEncryption.cs b/Lidgren.Network/Encryption/NetXorEncryption.cs index 980f116..b94b337 100644 --- a/Lidgren.Network/Encryption/NetXorEncryption.cs +++ b/Lidgren.Network/Encryption/NetXorEncryption.cs @@ -7,14 +7,15 @@ namespace Lidgren.Network /// /// Example class; not very good encryption /// - public class NetXorEncryption : INetEncryption + public class NetXorEncryption : NetEncryption { private byte[] m_key; /// /// NetXorEncryption constructor /// - public NetXorEncryption(byte[] key) + public NetXorEncryption(NetPeer peer, byte[] key) + : base(peer) { m_key = key; } @@ -22,7 +23,8 @@ namespace Lidgren.Network /// /// NetXorEncryption constructor /// - public NetXorEncryption(string key) + public NetXorEncryption(NetPeer peer, string key) + : base(peer) { m_key = Encoding.UTF8.GetBytes(key); } @@ -30,7 +32,7 @@ namespace Lidgren.Network /// /// Encrypt an outgoing message /// - public bool Encrypt(NetOutgoingMessage msg) + public override bool Encrypt(NetOutgoingMessage msg) { int numBytes = msg.LengthBytes; for (int i = 0; i < numBytes; i++) @@ -44,7 +46,7 @@ namespace Lidgren.Network /// /// Decrypt an incoming message /// - public bool Decrypt(NetIncomingMessage msg) + public override bool Decrypt(NetIncomingMessage msg) { int numBytes = msg.LengthBytes; for (int i = 0; i < numBytes; i++) diff --git a/Lidgren.Network/Encryption/NetXteaEncryption.cs b/Lidgren.Network/Encryption/NetXteaEncryption.cs index 504b773..69cd347 100644 --- a/Lidgren.Network/Encryption/NetXteaEncryption.cs +++ b/Lidgren.Network/Encryption/NetXteaEncryption.cs @@ -44,7 +44,8 @@ namespace Lidgren.Network /// /// 16 byte key /// - public NetXtea(byte[] key, int rounds) + public NetXtea(NetPeer peer, byte[] key, int rounds) + : base(peer) { if (key.Length < c_keySize) throw new NetException("Key too short!"); @@ -73,16 +74,16 @@ namespace Lidgren.Network /// /// 16 byte key /// - public NetXtea(byte[] key) - : this(key, 32) + public NetXtea(NetPeer peer, byte[] key) + : this(peer, key, 32) { } /// /// String to hash for key /// - public NetXtea(string key) - : this(NetUtility.CreateSHA1Hash(key), 32) + public NetXtea(NetPeer peer, string key) + : this(peer, NetUtility.CreateSHA1Hash(key), 32) { } diff --git a/Lidgren.Network/Lidgren.Network.csproj b/Lidgren.Network/Lidgren.Network.csproj index 7f3bdf8..d217b5d 100644 --- a/Lidgren.Network/Lidgren.Network.csproj +++ b/Lidgren.Network/Lidgren.Network.csproj @@ -59,13 +59,21 @@ - + - - - - + + Code + + + Code + + + Code + + + Code + diff --git a/Lidgren.Network/NetBuffer.Read.cs b/Lidgren.Network/NetBuffer.Read.cs index 1361d3b..c6ec6a6 100644 --- a/Lidgren.Network/NetBuffer.Read.cs +++ b/Lidgren.Network/NetBuffer.Read.cs @@ -558,6 +558,7 @@ namespace Lidgren.Network { // not enough data #if DEBUG + throw new NetException(c_readOverflowError); #else m_readPosition = m_bitLength; diff --git a/Lidgren.Network/NetIncomingMessage.cs b/Lidgren.Network/NetIncomingMessage.cs index 4885a30..617c0f5 100644 --- a/Lidgren.Network/NetIncomingMessage.cs +++ b/Lidgren.Network/NetIncomingMessage.cs @@ -90,7 +90,7 @@ namespace Lidgren.Network /// /// The encryption algorithm used to encrypt the message /// true on success - public bool Decrypt(INetEncryption encryption) + public bool Decrypt(NetEncryption encryption) { return encryption.Decrypt(this); } diff --git a/Lidgren.Network/NetOutgoingMessage.cs b/Lidgren.Network/NetOutgoingMessage.cs index 00b493d..55e54a8 100644 --- a/Lidgren.Network/NetOutgoingMessage.cs +++ b/Lidgren.Network/NetOutgoingMessage.cs @@ -116,7 +116,7 @@ namespace Lidgren.Network /// /// Encrypt this message using the provided algorithm; no more writing can be done before sending it or the message will be corrupt! /// - public bool Encrypt(INetEncryption encryption) + public bool Encrypt(NetEncryption encryption) { return encryption.Encrypt(this); } diff --git a/Lidgren.Network/NetSRP.cs b/Lidgren.Network/NetSRP.cs index e9852ff..4e2f6f0 100644 --- a/Lidgren.Network/NetSRP.cs +++ b/Lidgren.Network/NetSRP.cs @@ -185,7 +185,7 @@ namespace Lidgren.Network /// /// Create XTEA symmetrical encryption object from sessionValue /// - public static NetXtea CreateEncryption(byte[] sessionValue) + public static NetXtea CreateEncryption(NetPeer peer, byte[] sessionValue) { var sha = GetHashAlgorithm(); var hash = sha.ComputeHash(sessionValue); @@ -198,7 +198,7 @@ namespace Lidgren.Network key[i] ^= hash[i + (j * 16)]; } - return new NetXtea(key); + return new NetXtea(peer, key); } } }