Use SHA256 instead of MD5 in some places

This only works in places where the actual choice of hashing function
doesn't matter.
This commit is contained in:
heinrich5991 2019-04-06 02:47:00 +02:00
parent e44b1ca986
commit e3657ab2d5
2 changed files with 10 additions and 10 deletions

View file

@ -92,11 +92,11 @@ const CServerInfo *CServerBrowser::SortedGet(int Index) const
int CServerBrowser::GenerateToken(const NETADDR &Addr) const int CServerBrowser::GenerateToken(const NETADDR &Addr) const
{ {
MD5_CTX Md5; SHA256_CTX Sha256;
md5_init(&Md5); sha256_init(&Sha256);
md5_update(&Md5, m_aTokenSeed, sizeof(m_aTokenSeed)); sha256_update(&Sha256, m_aTokenSeed, sizeof(m_aTokenSeed));
md5_update(&Md5, (unsigned char *)&Addr, sizeof(Addr)); sha256_update(&Sha256, (unsigned char *)&Addr, sizeof(Addr));
MD5_DIGEST Digest = md5_finish(&Md5); SHA256_DIGEST Digest = sha256_finish(&Sha256);
return (Digest.data[0] << 16) | (Digest.data[1] << 8) | Digest.data[2]; return (Digest.data[0] << 16) | (Digest.data[1] << 8) | Digest.data[2];
} }

View file

@ -145,12 +145,12 @@ int CNetServer::Update()
SECURITY_TOKEN CNetServer::GetToken(const NETADDR &Addr) SECURITY_TOKEN CNetServer::GetToken(const NETADDR &Addr)
{ {
MD5_CTX Md5; SHA256_CTX Sha256;
md5_init(&Md5); sha256_init(&Sha256);
md5_update(&Md5, (unsigned char*)m_SecurityTokenSeed, sizeof(m_SecurityTokenSeed)); sha256_update(&Sha256, (unsigned char*)m_SecurityTokenSeed, sizeof(m_SecurityTokenSeed));
md5_update(&Md5, (unsigned char*)&Addr, sizeof(Addr)); sha256_update(&Sha256, (unsigned char*)&Addr, sizeof(Addr));
SECURITY_TOKEN SecurityToken = ToSecurityToken(md5_finish(&Md5).data); SECURITY_TOKEN SecurityToken = ToSecurityToken(sha256_finish(&Sha256).data);
if (SecurityToken == NET_SECURITY_TOKEN_UNKNOWN || if (SecurityToken == NET_SECURITY_TOKEN_UNKNOWN ||
SecurityToken == NET_SECURITY_TOKEN_UNSUPPORTED) SecurityToken == NET_SECURITY_TOKEN_UNSUPPORTED)