1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-15 06:36:30 +09:00

Net encryption generalized to support more algorithms

This commit is contained in:
lidgren
2011-04-16 22:37:15 +00:00
parent 6976177f94
commit a4503d22e1
11 changed files with 317 additions and 63 deletions

View File

@@ -115,22 +115,11 @@ namespace Lidgren.Network
}
/// <summary>
/// Encrypt this message using the XTEA algorithm; no more writing can be done before sending it
/// Encrypt this message using the provided algorithm; no more writing can be done before sending it or the message will be corrupt!
/// </summary>
public void Encrypt(NetXtea tea)
public bool Encrypt(INetEncryption encryption)
{
// need blocks of 8 bytes
WritePadBits();
int blocksNeeded = (m_bitLength + 63) / 64;
int missingBits = (blocksNeeded * 64) - m_bitLength;
int missingBytes = NetUtility.BytesToHoldBits(missingBits);
for (int i = 0; i < missingBytes; i++)
Write((byte)0);
byte[] result = new byte[m_data.Length];
for (int i = 0; i < blocksNeeded; i++)
tea.EncryptBlock(m_data, (i * 8), result, (i * 8));
m_data = result;
return encryption.Encrypt(this);
}
/// <summary>