Opps sha256 needed for worldsocket.

This commit is contained in:
hondacrx
2022-11-01 17:04:11 -04:00
parent d42acc0640
commit b5cd2f5422
2 changed files with 54 additions and 4 deletions
@@ -19,16 +19,16 @@ using System.Security.Cryptography;
namespace Framework.Cryptography
{
public class SessionKeyGenerator
public class SessionKeyGenerator256
{
public SessionKeyGenerator(byte[] buff, int size = 0)
public SessionKeyGenerator256(byte[] buff, int size = 0)
{
if (size == 0)
size = buff.Length;
int halfSize = size / 2;
sh = SHA1.Create();
sh = SHA256.Create();
sh.TransformFinalBlock(buff, 0, halfSize);
o1 = sh.Hash;
@@ -62,6 +62,56 @@ namespace Framework.Cryptography
taken = 0;
}
SHA256 sh;
uint taken;
byte[] o0 = new byte[32];
byte[] o1 = new byte[32];
byte[] o2 = new byte[32];
}
public class SessionKeyGenerator
{
public SessionKeyGenerator(byte[] buff, int size = 0)
{
if (size == 0)
size = buff.Length;
int halfSize = size / 2;
sh = SHA1.Create();
sh.TransformFinalBlock(buff, 0, halfSize);
o1 = sh.Hash;
sh.Initialize();
sh.TransformFinalBlock(buff, halfSize, size - halfSize);
o2 = sh.Hash;
FillUp();
}
public void Generate(byte[] buf, uint sz)
{
for (uint i = 0; i < sz; ++i)
{
if (taken == 20)
FillUp();
buf[i] = o0[taken];
taken++;
}
}
void FillUp()
{
sh.Initialize();
sh.TransformBlock(o1, 0, 20, o1, 0);
sh.TransformBlock(o0, 0, 20, o0, 0);
sh.TransformFinalBlock(o2, 0, 20);
o0 = sh.Hash;
taken = 0;
}
SHA1 sh;
uint taken;
byte[] o0 = new byte[32];
+1 -1
View File
@@ -537,7 +537,7 @@ namespace Game.Networking
sessionKeyHmac.Finish(SessionKeySeed, 16);
_sessionKey = new byte[40];
var sessionKeyGenerator = new SessionKeyGenerator(sessionKeyHmac.Digest, 32);
var sessionKeyGenerator = new SessionKeyGenerator256(sessionKeyHmac.Digest, 32);
sessionKeyGenerator.Generate(_sessionKey, 40);
HmacSha256 encryptKeyGen = new(_sessionKey);