mirror of
https://github.com/FWGS/xash3d-fwgs
synced 2024-11-22 01:45:19 +01:00
3rdparty: MultiEmulator: move it to submodule
This commit is contained in:
parent
6a1f502d25
commit
ffe7b1f4a1
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -22,3 +22,6 @@
|
||||
[submodule "3rdparty/bzip2/bzip2"]
|
||||
path = 3rdparty/bzip2/bzip2
|
||||
url = https://gitlab.com/bzip2/bzip2
|
||||
[submodule "3rdparty/MultiEmulator"]
|
||||
path = 3rdparty/MultiEmulator
|
||||
url = https://github.com/FWGS/MultiEmulator
|
||||
|
1
3rdparty/MultiEmulator
vendored
Submodule
1
3rdparty/MultiEmulator
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 63f9145bd03def93dae3b7fe977b78e4ab312189
|
21
3rdparty/MultiEmulator/LICENSE
vendored
21
3rdparty/MultiEmulator/LICENSE
vendored
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017-2018 Alexander Belkin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
25
3rdparty/MultiEmulator/README.md
vendored
25
3rdparty/MultiEmulator/README.md
vendored
@ -1,25 +0,0 @@
|
||||
# MultiEmulator
|
||||
|
||||
**MultiEmulator** - project for GoldSource Engine, which provides ability to generate tickets with a specific SteamID key, using all available emulators for this engine.
|
||||
|
||||
Ticket is processed by the game server of Half-Life 1 and modifications using **DProto** or **ReUnion** modules. If the server does not have these modules, then MultiEmulator won't work.
|
||||
|
||||
# Ticket generators
|
||||
|
||||
Currently available ticket generators:
|
||||
* OldRevEmu
|
||||
* AVSMP
|
||||
* Setti
|
||||
* SteamEmu
|
||||
* RevEmu
|
||||
* SC2009
|
||||
* RevEmu2013
|
||||
|
||||
Currently under development generators:
|
||||
* SmartSteamEmu (SSE3)
|
||||
|
||||
# How to use?
|
||||
Each file in the **MultiEmulator\Source\Emulators** folder contains a **Generate** function that writes a ticket to the **pDest** argument for the emulator of the same name as a header file. As a result of the function, the size of the written ticket is returned. If the generator can set an arbitrary SteamID, the function will have the **nSteamID** argument, in which the required SteamID is specified.
|
||||
|
||||
# Examples
|
||||
As an example, the DLL was developed that searches InitiateGameConnection method in ISteamUser interface, which generates Steam ticket, and inserts in its place own generator, which creates RevEmu2013 ticket with SteamID equal to 3333333. You can find this project in **Example** folder, you just need to compile it and perform DLL injection in hl.exe process with any known injection method.
|
37
3rdparty/MultiEmulator/include/multi_emulator.h
vendored
37
3rdparty/MultiEmulator/include/multi_emulator.h
vendored
@ -1,37 +0,0 @@
|
||||
#ifndef MULTI_EMULATOR_H
|
||||
#define MULTI_EMULATOR_H
|
||||
|
||||
#if defined( __GNUC__ )
|
||||
#if defined( __i386__ )
|
||||
#define ME_EXPORT __attribute__(( visibility( "default" ), force_align_arg_pointer ))
|
||||
#else
|
||||
#define ME_EXPORT __attribute__(( visibility ( "default" )))
|
||||
#endif
|
||||
#else
|
||||
#if defined( _MSC_VER )
|
||||
#define ME_EXPORT __declspec( dllexport )
|
||||
#else
|
||||
#define ME_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int ME_EXPORT GenerateRevEmu2013( void *pDest, int nSteamID );
|
||||
int ME_EXPORT GenerateSC2009( void *pDest, int nSteamID );
|
||||
int ME_EXPORT GenerateOldRevEmu( void *pDest, int nSteamID );
|
||||
int ME_EXPORT GenerateSteamEmu( void *pDest, int nSteamID );
|
||||
int ME_EXPORT GenerateRevEmu( void *pDest, int nSteamID );
|
||||
int ME_EXPORT GenerateSetti( void *pDest );
|
||||
int ME_EXPORT GenerateAVSMP( void *pDest, int nSteamID, int bUniverse );
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // MULTI_EMULATOR_H
|
13
3rdparty/MultiEmulator/src/AVSMP.cpp
vendored
13
3rdparty/MultiEmulator/src/AVSMP.cpp
vendored
@ -1,13 +0,0 @@
|
||||
#include "multi_emulator.h"
|
||||
|
||||
/* bUniverse param is "y" value in "STEAM_x:y:z" */
|
||||
int GenerateAVSMP(void *pDest, int nSteamID, int bUniverse)
|
||||
{
|
||||
auto pTicket = (int *)pDest;
|
||||
|
||||
pTicket[0] = 0x14; // +0, header
|
||||
pTicket[3] = (nSteamID << 1) | (bUniverse ? 1 : 0); // +12, SteamId, Low part
|
||||
pTicket[4] = 0x01100001; // +16, SteamId, High part
|
||||
|
||||
return 28;
|
||||
}
|
1376
3rdparty/MultiEmulator/src/CRijndael.cpp
vendored
1376
3rdparty/MultiEmulator/src/CRijndael.cpp
vendored
File diff suppressed because it is too large
Load Diff
187
3rdparty/MultiEmulator/src/CRijndael.h
vendored
187
3rdparty/MultiEmulator/src/CRijndael.h
vendored
@ -1,187 +0,0 @@
|
||||
#ifndef __RIJNDAEL_H__
|
||||
#define __RIJNDAEL_H__
|
||||
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//Rijndael (pronounced Reindaal) is a block cipher, designed by Joan Daemen and Vincent Rijmen as a candidate algorithm for the AES.
|
||||
//The cipher has a variable block length and key length. The authors currently specify how to use keys with a length
|
||||
//of 128, 192, or 256 bits to encrypt blocks with al length of 128, 192 or 256 bits (all nine combinations of
|
||||
//key length and block length are possible). Both block length and key length can be extended very easily to
|
||||
// multiples of 32 bits.
|
||||
//Rijndael can be implemented very efficiently on a wide range of processors and in hardware.
|
||||
//This implementation is based on the Java Implementation used with the Cryptix toolkit found at:
|
||||
//http://www.esat.kuleuven.ac.be/~rijmen/rijndael/rijndael.zip
|
||||
//Java code authors: Raif S. Naffah, Paulo S. L. M. Barreto
|
||||
//This Implementation was tested against KAT test published by the authors of the method and the
|
||||
//results were identical.
|
||||
class CRijndael
|
||||
{
|
||||
public:
|
||||
//Operation Modes
|
||||
//The Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback Block (CFB) modes
|
||||
//are implemented.
|
||||
//In ECB mode if the same block is encrypted twice with the same key, the resulting
|
||||
//ciphertext blocks are the same.
|
||||
//In CBC Mode a ciphertext block is obtained by first xoring the
|
||||
//plaintext block with the previous ciphertext block, and encrypting the resulting value.
|
||||
//In CFB mode a ciphertext block is obtained by encrypting the previous ciphertext block
|
||||
//and xoring the resulting value with the plaintext.
|
||||
enum { ECB = 0, CBC = 1, CFB = 2 };
|
||||
|
||||
private:
|
||||
enum { DEFAULT_BLOCK_SIZE = 16 };
|
||||
enum { MAX_BLOCK_SIZE = 32, MAX_ROUNDS = 14, MAX_KC = 8, MAX_BC = 8 };
|
||||
|
||||
//Auxiliary Functions
|
||||
//Multiply two elements of GF(2^m)
|
||||
static int Mul(int a, int b)
|
||||
{
|
||||
return (a != 0 && b != 0) ? sm_alog[(sm_log[a & 0xFF] + sm_log[b & 0xFF]) % 255] : 0;
|
||||
}
|
||||
|
||||
//Convenience method used in generating Transposition Boxes
|
||||
static int Mul4(int a, char b[])
|
||||
{
|
||||
if (a == 0)
|
||||
return 0;
|
||||
a = sm_log[a & 0xFF];
|
||||
int a0 = (b[0] != 0) ? sm_alog[(a + sm_log[b[0] & 0xFF]) % 255] & 0xFF : 0;
|
||||
int a1 = (b[1] != 0) ? sm_alog[(a + sm_log[b[1] & 0xFF]) % 255] & 0xFF : 0;
|
||||
int a2 = (b[2] != 0) ? sm_alog[(a + sm_log[b[2] & 0xFF]) % 255] & 0xFF : 0;
|
||||
int a3 = (b[3] != 0) ? sm_alog[(a + sm_log[b[3] & 0xFF]) % 255] & 0xFF : 0;
|
||||
return a0 << 24 | a1 << 16 | a2 << 8 | a3;
|
||||
}
|
||||
|
||||
public:
|
||||
//CONSTRUCTOR
|
||||
CRijndael();
|
||||
|
||||
//DESTRUCTOR
|
||||
virtual ~CRijndael();
|
||||
|
||||
//Expand a user-supplied key material into a session key.
|
||||
// key - The 128/192/256-bit user-key to use.
|
||||
// chain - initial chain block for CBC and CFB modes.
|
||||
// keylength - 16, 24 or 32 bytes
|
||||
// blockSize - The block size in bytes of this Rijndael (16, 24 or 32 bytes).
|
||||
void MakeKey(char const* key, char const* chain, int keylength = DEFAULT_BLOCK_SIZE, int blockSize = DEFAULT_BLOCK_SIZE);
|
||||
|
||||
private:
|
||||
//Auxiliary Function
|
||||
void Xor(char* buff, char const* chain)
|
||||
{
|
||||
if (false == m_bKeyInit)
|
||||
throw runtime_error(sm_szErrorMsg1);
|
||||
for (int i = 0; i<m_blockSize; i++)
|
||||
*(buff++) ^= *(chain++);
|
||||
}
|
||||
|
||||
//Convenience method to encrypt exactly one block of plaintext, assuming
|
||||
//Rijndael's default block size (128-bit).
|
||||
// in - The plaintext
|
||||
// result - The ciphertext generated from a plaintext using the key
|
||||
void DefEncryptBlock(char const* in, char* result);
|
||||
|
||||
//Convenience method to decrypt exactly one block of plaintext, assuming
|
||||
//Rijndael's default block size (128-bit).
|
||||
// in - The ciphertext.
|
||||
// result - The plaintext generated from a ciphertext using the session key.
|
||||
void DefDecryptBlock(char const* in, char* result);
|
||||
|
||||
public:
|
||||
//Encrypt exactly one block of plaintext.
|
||||
// in - The plaintext.
|
||||
// result - The ciphertext generated from a plaintext using the key.
|
||||
void EncryptBlock(char const* in, char* result);
|
||||
|
||||
//Decrypt exactly one block of ciphertext.
|
||||
// in - The ciphertext.
|
||||
// result - The plaintext generated from a ciphertext using the session key.
|
||||
void DecryptBlock(char const* in, char* result);
|
||||
|
||||
void Encrypt(char const* in, char* result, size_t n, int iMode = ECB);
|
||||
|
||||
void Decrypt(char const* in, char* result, size_t n, int iMode = ECB);
|
||||
|
||||
//Get Key Length
|
||||
int GetKeyLength()
|
||||
{
|
||||
if (false == m_bKeyInit)
|
||||
throw runtime_error(sm_szErrorMsg1);
|
||||
return m_keylength;
|
||||
}
|
||||
|
||||
//Block Size
|
||||
int GetBlockSize()
|
||||
{
|
||||
if (false == m_bKeyInit)
|
||||
throw runtime_error(sm_szErrorMsg1);
|
||||
return m_blockSize;
|
||||
}
|
||||
|
||||
//Number of Rounds
|
||||
int GetRounds()
|
||||
{
|
||||
if (false == m_bKeyInit)
|
||||
throw runtime_error(sm_szErrorMsg1);
|
||||
return m_iROUNDS;
|
||||
}
|
||||
|
||||
void ResetChain()
|
||||
{
|
||||
memcpy(m_chain, m_chain0, m_blockSize);
|
||||
}
|
||||
|
||||
public:
|
||||
//Null chain
|
||||
static char const* sm_chain0;
|
||||
|
||||
private:
|
||||
static const int sm_alog[256];
|
||||
static const int sm_log[256];
|
||||
static const signed char sm_S[256];
|
||||
static const signed char sm_Si[256];
|
||||
static const int sm_T1[256];
|
||||
static const int sm_T2[256];
|
||||
static const int sm_T3[256];
|
||||
static const int sm_T4[256];
|
||||
static const int sm_T5[256];
|
||||
static const int sm_T6[256];
|
||||
static const int sm_T7[256];
|
||||
static const int sm_T8[256];
|
||||
static const int sm_U1[256];
|
||||
static const int sm_U2[256];
|
||||
static const int sm_U3[256];
|
||||
static const int sm_U4[256];
|
||||
static const signed char sm_rcon[30];
|
||||
static const int sm_shifts[3][4][2];
|
||||
//Error Messages
|
||||
static char const* sm_szErrorMsg1;
|
||||
static char const* sm_szErrorMsg2;
|
||||
//Key Initialization Flag
|
||||
bool m_bKeyInit;
|
||||
//Encryption (m_Ke) round key
|
||||
int m_Ke[MAX_ROUNDS + 1][MAX_BC];
|
||||
//Decryption (m_Kd) round key
|
||||
int m_Kd[MAX_ROUNDS + 1][MAX_BC];
|
||||
//Key Length
|
||||
int m_keylength;
|
||||
//Block Size
|
||||
int m_blockSize;
|
||||
//Number of Rounds
|
||||
int m_iROUNDS;
|
||||
//Chain Block
|
||||
char m_chain0[MAX_BLOCK_SIZE];
|
||||
char m_chain[MAX_BLOCK_SIZE];
|
||||
//Auxiliary private use buffers
|
||||
int tk[MAX_KC];
|
||||
int a[MAX_BC];
|
||||
int t[MAX_BC];
|
||||
};
|
||||
|
||||
#endif // __RIJNDAEL_H__
|
45
3rdparty/MultiEmulator/src/MessageDigest.h
vendored
45
3rdparty/MultiEmulator/src/MessageDigest.h
vendored
@ -1,45 +0,0 @@
|
||||
//MessageDigest.h
|
||||
|
||||
#ifndef __MESSAGEDIGEST_H__
|
||||
#define __MESSAGEDIGEST_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//Typical DISCLAIMER:
|
||||
//The code in this project is Copyright (C) 2003 by George Anescu. You have the right to
|
||||
//use and distribute the code in any way you see fit as long as this paragraph is included
|
||||
//with the distribution. No warranties or claims are made as to the validity of the
|
||||
//information and code contained herein, so use it at your own risk.
|
||||
|
||||
//General Message Digest Interface
|
||||
class IMessageDigest
|
||||
{
|
||||
public:
|
||||
//CONSTRUCTOR
|
||||
IMessageDigest() : m_bAddData(false) {}
|
||||
//DESTRUCTOR
|
||||
virtual ~IMessageDigest() {}
|
||||
//Update context to reflect the concatenation of another buffer of bytes
|
||||
virtual void AddData(char const* pcData, int iDataLength) = 0;
|
||||
//Final wrapup - pad to BLOCKSIZE-byte boundary with the bit pattern
|
||||
//10000...(64-bit count of bits processed, MSB-first)
|
||||
virtual void FinalDigest(char* pcDigest) = 0;
|
||||
//Reset current operation in order to prepare for a new one
|
||||
virtual void Reset() = 0;
|
||||
|
||||
protected:
|
||||
enum { BLOCKSIZE=64 };
|
||||
//Control Flag
|
||||
bool m_bAddData;
|
||||
//The core of the MessageDigest algorithm, this alters an existing MessageDigest hash to
|
||||
//reflect the addition of 64 bytes of new data
|
||||
virtual void Transform() = 0;
|
||||
|
||||
private:
|
||||
enum { DATA_LEN=384, BUFF_LEN=1024 };
|
||||
};
|
||||
|
||||
#endif // __MESSAGEDIGEST_H__
|
||||
|
13
3rdparty/MultiEmulator/src/OldRevEmu.cpp
vendored
13
3rdparty/MultiEmulator/src/OldRevEmu.cpp
vendored
@ -1,13 +0,0 @@
|
||||
#include "multi_emulator.h"
|
||||
|
||||
int GenerateOldRevEmu(void* pDest, int nSteamID)
|
||||
{
|
||||
auto pTicket = (int*)pDest;
|
||||
auto pbTicket = (unsigned char*)pDest;
|
||||
|
||||
pTicket[0] = 0xFFFF; // +0, header
|
||||
pTicket[1] = (nSteamID ^ 0xC9710266) << 1; // +4, SteamId
|
||||
*(short *)&pbTicket[8] = 0; // +8, unknown, in original emulator must be 0
|
||||
|
||||
return 10;
|
||||
}
|
27
3rdparty/MultiEmulator/src/RevEmu.cpp
vendored
27
3rdparty/MultiEmulator/src/RevEmu.cpp
vendored
@ -1,27 +0,0 @@
|
||||
#include "multi_emulator.h"
|
||||
#include "StrUtils.h"
|
||||
#include "RevSpoofer.h"
|
||||
|
||||
int GenerateRevEmu(void *pDest, int nSteamID)
|
||||
{
|
||||
char szhwid[64];
|
||||
|
||||
CreateRandomString(szhwid, 16);
|
||||
if (!RevSpoofer::Spoof(szhwid, nSteamID))
|
||||
return 0;
|
||||
|
||||
auto pTicket = (int *)pDest;
|
||||
auto revHash = RevSpoofer::Hash(szhwid);
|
||||
|
||||
pTicket[0] = 'J'; // +0, header
|
||||
pTicket[1] = revHash; // +4, hash of string at +24 offset
|
||||
pTicket[2] = 'r' << 16 | 'e' << 8 | 'v';// +8, magic number
|
||||
pTicket[3] = 0; // +12, unknown number, must always be 0
|
||||
|
||||
pTicket[4] = revHash << 1; // +16, SteamId, Low part
|
||||
pTicket[5] = 0x01100001; // +20, SteamId, High part
|
||||
|
||||
strcpy((char *)&pTicket[6], szhwid); // +24, string for hash
|
||||
|
||||
return 152;
|
||||
}
|
55
3rdparty/MultiEmulator/src/RevEmu2013.cpp
vendored
55
3rdparty/MultiEmulator/src/RevEmu2013.cpp
vendored
@ -1,55 +0,0 @@
|
||||
#include "multi_emulator.h"
|
||||
#include "StrUtils.h"
|
||||
#include "RevSpoofer.h"
|
||||
#include "CRijndael.h"
|
||||
#include "SHA.h"
|
||||
#include <time.h>
|
||||
|
||||
int GenerateRevEmu2013(void *pDest, int nSteamID)
|
||||
{
|
||||
char szhwid[64];
|
||||
|
||||
CreateRandomString(szhwid, 32);
|
||||
if (!RevSpoofer::Spoof(szhwid, nSteamID))
|
||||
return 0;
|
||||
|
||||
auto pTicket = (int *)pDest;
|
||||
auto pbTicket = (unsigned char *)pDest;
|
||||
|
||||
auto revHash = RevSpoofer::Hash(szhwid);
|
||||
|
||||
pTicket[0] = 'S'; // +0
|
||||
pTicket[1] = revHash; // +4
|
||||
pTicket[2] = 'r' << 16 | 'e' << 8 | 'v';;// +8
|
||||
pTicket[3] = 0; // +12
|
||||
pTicket[4] = revHash << 1; // +16
|
||||
pTicket[5] = 0x01100001; // +20
|
||||
pTicket[6] = (int)time(0) + 90123; // +24
|
||||
pbTicket[27] = ~(pbTicket[27] + pbTicket[24]);
|
||||
pTicket[7] = ~(int)time(0); // +28
|
||||
pTicket[8] = revHash * 2 >> 3; // +32
|
||||
pTicket[9] = 0; // +36
|
||||
|
||||
static const char c_szAESKeyRand[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
||||
|
||||
char szAESHashRand[32];
|
||||
auto AESRand = CRijndael();
|
||||
AESRand.MakeKey(c_szAESKeyRand, CRijndael::sm_chain0, 32, 32);
|
||||
AESRand.EncryptBlock(szhwid, szAESHashRand);
|
||||
memcpy(&pbTicket[40], szAESHashRand, 32);
|
||||
|
||||
static const char c_szAESKeyRev[] = "_YOU_SERIOUSLY_NEED_TO_GET_LAID_";
|
||||
char AESHashRev[32];
|
||||
auto AESRev = CRijndael();
|
||||
AESRev.MakeKey(c_szAESKeyRev, CRijndael::sm_chain0, 32, 32);
|
||||
AESRev.EncryptBlock(c_szAESKeyRand, AESHashRev);
|
||||
memcpy(&pbTicket[72], AESHashRev, 32);
|
||||
|
||||
char szSHAHash[32];
|
||||
auto sha = CSHA(CSHA::SHA256);
|
||||
sha.AddData(szhwid, 32);
|
||||
sha.FinalDigest(szSHAHash);
|
||||
memcpy(&pbTicket[104], szSHAHash, 32);
|
||||
|
||||
return 194;
|
||||
}
|
96
3rdparty/MultiEmulator/src/RevSpoofer.cpp
vendored
96
3rdparty/MultiEmulator/src/RevSpoofer.cpp
vendored
@ -1,96 +0,0 @@
|
||||
#include "RevSpoofer.h"
|
||||
#include <string.h>
|
||||
|
||||
#define astrlen(x) sizeof(x) - 1
|
||||
|
||||
static char s_szDictionary[] = { "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" };
|
||||
|
||||
static int iInputLen;
|
||||
static unsigned int uTreasure;
|
||||
|
||||
bool ScanLast3(char *pszInput, unsigned int uPrevHash)
|
||||
{
|
||||
unsigned int h1, h2, h3, hh;
|
||||
for (int i1 = 0; i1 < astrlen(s_szDictionary); i1++)
|
||||
{
|
||||
h1 = uPrevHash ^ ((uPrevHash >> 2) + (uPrevHash << 5) + s_szDictionary[i1]);
|
||||
hh = h1 ^ ((h1 >> 2) + (h1 << 5));
|
||||
hh = hh ^ ((hh >> 2) + (hh << 5));
|
||||
|
||||
if ((hh ^ uTreasure) >> (8 + 5 + 3))
|
||||
continue;
|
||||
|
||||
for (int i2 = 0; i2 < astrlen(s_szDictionary); i2++)
|
||||
{
|
||||
h2 = h1 ^ ((h1 >> 2) + (h1 << 5) + s_szDictionary[i2]);
|
||||
hh = h2 ^ ((h2 >> 2) + (h2 << 5));
|
||||
if ((hh ^ uTreasure) >> (8 + 3))
|
||||
continue;
|
||||
|
||||
for (int i3 = 0; i3 < astrlen(s_szDictionary); i3++)
|
||||
{
|
||||
h3 = h2 ^ ((h2 >> 2) + (h2 << 5) + s_szDictionary[i3]);
|
||||
if (h3 == uTreasure)
|
||||
{
|
||||
pszInput[iInputLen - 3] = s_szDictionary[i1];
|
||||
pszInput[iInputLen - 2] = s_szDictionary[i2];
|
||||
pszInput[iInputLen - 1] = s_szDictionary[i3];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ScanNext(char* pszInput, int uIndex, unsigned int uPrevHash)
|
||||
{
|
||||
bool res;
|
||||
|
||||
for (int i = 0; i < astrlen(s_szDictionary); i++)
|
||||
{
|
||||
auto h = uPrevHash ^ ((uPrevHash >> 2) + (uPrevHash << 5) + s_szDictionary[i]);
|
||||
|
||||
if (uIndex + 1 < iInputLen - 3)
|
||||
res = ScanNext(pszInput, uIndex + 1, h);
|
||||
else
|
||||
res = ScanLast3(pszInput, h);
|
||||
|
||||
if (res)
|
||||
{
|
||||
pszInput[uIndex] = s_szDictionary[i];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace RevSpoofer
|
||||
{
|
||||
bool Spoof(char *pszDest, int uSID)
|
||||
{
|
||||
uTreasure = uSID;
|
||||
iInputLen = strlen(pszDest);
|
||||
|
||||
auto i = iInputLen - 7;
|
||||
i = (i < 0) ? 0 : i;
|
||||
pszDest[i] = '\0';
|
||||
auto h = Hash(pszDest);
|
||||
return ScanNext(pszDest, i, h);
|
||||
}
|
||||
|
||||
unsigned int Hash(char *pszString)
|
||||
{
|
||||
int i = 0;
|
||||
unsigned int nHash = 0x4E67C6A7;
|
||||
int c = pszString[i++];
|
||||
|
||||
while (c)
|
||||
{
|
||||
nHash = nHash ^ ((nHash >> 2) + (nHash << 5) + c);
|
||||
c = pszString[i++];
|
||||
}
|
||||
|
||||
return nHash;
|
||||
}
|
||||
}
|
7
3rdparty/MultiEmulator/src/RevSpoofer.h
vendored
7
3rdparty/MultiEmulator/src/RevSpoofer.h
vendored
@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace RevSpoofer
|
||||
{
|
||||
bool Spoof(char *pszDest, int uSID);
|
||||
unsigned int Hash(char *pszString);
|
||||
}
|
52
3rdparty/MultiEmulator/src/SC2009.cpp
vendored
52
3rdparty/MultiEmulator/src/SC2009.cpp
vendored
@ -1,52 +0,0 @@
|
||||
#include "multi_emulator.h"
|
||||
#include "StrUtils.h"
|
||||
#include "RevSpoofer.h"
|
||||
#include "CRijndael.h"
|
||||
#include "SHA.h"
|
||||
|
||||
int GenerateSC2009(void* pDest, int nSteamID)
|
||||
{
|
||||
char hwid[64];
|
||||
|
||||
CreateRandomString(hwid, 32);
|
||||
if (!RevSpoofer::Spoof(hwid, nSteamID))
|
||||
return 0;
|
||||
|
||||
auto pTicket = (int*)pDest;
|
||||
auto pbTicket = (unsigned char*)pDest;
|
||||
|
||||
auto revHash = RevSpoofer::Hash(hwid);
|
||||
|
||||
pTicket[0] = 'S'; // +0
|
||||
pTicket[1] = revHash; // +4
|
||||
pTicket[2] = 'r' << 16 | 'e' << 8 | 'v';;// +8
|
||||
pTicket[3] = 0; // +12
|
||||
pTicket[4] = revHash << 1; // +16
|
||||
pTicket[5] = 0x01100001; // +20
|
||||
|
||||
/* Encrypt HWID with AESKeyRand key and save it in the ticket. */
|
||||
static const char AESKeyRand[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
||||
char AESHashRand[32];
|
||||
auto AESRand = CRijndael();
|
||||
AESRand.MakeKey(AESKeyRand, CRijndael::sm_chain0, 32, 32);
|
||||
AESRand.EncryptBlock(hwid, AESHashRand);
|
||||
memcpy(&pbTicket[24], AESHashRand, 32);
|
||||
|
||||
/* Encrypt AESKeyRand with AESKeyRev key and save it in the ticket.
|
||||
* AESKeyRev key is identical to the key in dproto/reunion. */
|
||||
static const char AESKeyRev[] = "_YOU_SERIOUSLY_NEED_TO_GET_LAID_";
|
||||
char AESHashRev[32];
|
||||
auto AESRev = CRijndael();
|
||||
AESRev.MakeKey(AESKeyRev, CRijndael::sm_chain0, 32, 32);
|
||||
AESRev.EncryptBlock(AESKeyRand, AESHashRev);
|
||||
memcpy(&pbTicket[56], AESHashRev, 32);
|
||||
|
||||
/* Perform HWID hashing and save hash to the ticket. */
|
||||
char SHAHash[32];
|
||||
auto sha = CSHA(CSHA::SHA256);
|
||||
sha.AddData(hwid, 32);
|
||||
sha.FinalDigest(SHAHash);
|
||||
memcpy(&pbTicket[88], SHAHash, 32);
|
||||
|
||||
return 178;
|
||||
}
|
734
3rdparty/MultiEmulator/src/SHA.cpp
vendored
734
3rdparty/MultiEmulator/src/SHA.cpp
vendored
@ -1,734 +0,0 @@
|
||||
//SHA.cpp
|
||||
#include "SHA.h"
|
||||
#include <exception>
|
||||
#include <strstream>
|
||||
#include <string.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const unsigned int CSHA::sm_K160[4] =
|
||||
{
|
||||
0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6
|
||||
};
|
||||
|
||||
const unsigned int CSHA::sm_H160[SHA160LENGTH] =
|
||||
{
|
||||
0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0
|
||||
};
|
||||
|
||||
const unsigned int CSHA::sm_K256[64] =
|
||||
{
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
|
||||
const unsigned int CSHA::sm_H256[SHA256LENGTH] =
|
||||
{
|
||||
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
||||
};
|
||||
|
||||
const SUI64 CSHA::sm_H384[SHA512LENGTH] =
|
||||
{
|
||||
{0xcbbb9d5d, 0xc1059ed8},
|
||||
{0x629a292a, 0x367cd507},
|
||||
{0x9159015a, 0x3070dd17},
|
||||
{0x152fecd8, 0xf70e5939},
|
||||
{0x67332667, 0xffc00b31},
|
||||
{0x8eb44a87, 0x68581511},
|
||||
{0xdb0c2e0d, 0x64f98fa7},
|
||||
{0x47b5481d, 0xbefa4fa4}
|
||||
};
|
||||
|
||||
const SUI64 CSHA::sm_K512[80] =
|
||||
{
|
||||
{0x428a2f98, 0xd728ae22}, {0x71374491, 0x23ef65cd},
|
||||
{0xb5c0fbcf, 0xec4d3b2f}, {0xe9b5dba5, 0x8189dbbc},
|
||||
{0x3956c25b, 0xf348b538}, {0x59f111f1, 0xb605d019},
|
||||
{0x923f82a4, 0xaf194f9b}, {0xab1c5ed5, 0xda6d8118},
|
||||
{0xd807aa98, 0xa3030242}, {0x12835b01, 0x45706fbe},
|
||||
{0x243185be, 0x4ee4b28c}, {0x550c7dc3, 0xd5ffb4e2},
|
||||
{0x72be5d74, 0xf27b896f}, {0x80deb1fe, 0x3b1696b1},
|
||||
{0x9bdc06a7, 0x25c71235}, {0xc19bf174, 0xcf692694},
|
||||
{0xe49b69c1, 0x9ef14ad2}, {0xefbe4786, 0x384f25e3},
|
||||
{0x0fc19dc6, 0x8b8cd5b5}, {0x240ca1cc, 0x77ac9c65},
|
||||
{0x2de92c6f, 0x592b0275}, {0x4a7484aa, 0x6ea6e483},
|
||||
{0x5cb0a9dc, 0xbd41fbd4}, {0x76f988da, 0x831153b5},
|
||||
{0x983e5152, 0xee66dfab}, {0xa831c66d, 0x2db43210},
|
||||
{0xb00327c8, 0x98fb213f}, {0xbf597fc7, 0xbeef0ee4},
|
||||
{0xc6e00bf3, 0x3da88fc2}, {0xd5a79147, 0x930aa725},
|
||||
{0x06ca6351, 0xe003826f}, {0x14292967, 0x0a0e6e70},
|
||||
{0x27b70a85, 0x46d22ffc}, {0x2e1b2138, 0x5c26c926},
|
||||
{0x4d2c6dfc, 0x5ac42aed}, {0x53380d13, 0x9d95b3df},
|
||||
{0x650a7354, 0x8baf63de}, {0x766a0abb, 0x3c77b2a8},
|
||||
{0x81c2c92e, 0x47edaee6}, {0x92722c85, 0x1482353b},
|
||||
{0xa2bfe8a1, 0x4cf10364}, {0xa81a664b, 0xbc423001},
|
||||
{0xc24b8b70, 0xd0f89791}, {0xc76c51a3, 0x0654be30},
|
||||
{0xd192e819, 0xd6ef5218}, {0xd6990624, 0x5565a910},
|
||||
{0xf40e3585, 0x5771202a}, {0x106aa070, 0x32bbd1b8},
|
||||
{0x19a4c116, 0xb8d2d0c8}, {0x1e376c08, 0x5141ab53},
|
||||
{0x2748774c, 0xdf8eeb99}, {0x34b0bcb5, 0xe19b48a8},
|
||||
{0x391c0cb3, 0xc5c95a63}, {0x4ed8aa4a, 0xe3418acb},
|
||||
{0x5b9cca4f, 0x7763e373}, {0x682e6ff3, 0xd6b2b8a3},
|
||||
{0x748f82ee, 0x5defb2fc}, {0x78a5636f, 0x43172f60},
|
||||
{0x84c87814, 0xa1f0ab72}, {0x8cc70208, 0x1a6439ec},
|
||||
{0x90befffa, 0x23631e28}, {0xa4506ceb, 0xde82bde9},
|
||||
{0xbef9a3f7, 0xb2c67915}, {0xc67178f2, 0xe372532b},
|
||||
{0xca273ece, 0xea26619c}, {0xd186b8c7, 0x21c0c207},
|
||||
{0xeada7dd6, 0xcde0eb1e}, {0xf57d4f7f, 0xee6ed178},
|
||||
{0x06f067aa, 0x72176fba}, {0x0a637dc5, 0xa2c898a6},
|
||||
{0x113f9804, 0xbef90dae}, {0x1b710b35, 0x131c471b},
|
||||
{0x28db77f5, 0x23047d84}, {0x32caab7b, 0x40c72493},
|
||||
{0x3c9ebe0a, 0x15c9bebc}, {0x431d67c4, 0x9c100d4c},
|
||||
{0x4cc5d4be, 0xcb3e42b6}, {0x597f299c, 0xfc657e2a},
|
||||
{0x5fcb6fab, 0x3ad6faec}, {0x6c44198c, 0x4a475817}
|
||||
};
|
||||
|
||||
const SUI64 CSHA::sm_H512[SHA512LENGTH] =
|
||||
{
|
||||
{0x6a09e667, 0xf3bcc908},
|
||||
{0xbb67ae85, 0x84caa73b},
|
||||
{0x3c6ef372, 0xfe94f82b},
|
||||
{0xa54ff53a, 0x5f1d36f1},
|
||||
{0x510e527f, 0xade682d1},
|
||||
{0x9b05688c, 0x2b3e6c1f},
|
||||
{0x1f83d9ab, 0xfb41bd6b},
|
||||
{0x5be0cd19, 0x137e2179}
|
||||
};
|
||||
|
||||
//CONSTRUCTOR
|
||||
CSHA::CSHA(int iMethod)
|
||||
{
|
||||
//Check the method
|
||||
switch(iMethod)
|
||||
{
|
||||
case SHA160:
|
||||
{
|
||||
for(int i=0; i<SHA160LENGTH; i++)
|
||||
m_auiBuf[i] = sm_H160[i];
|
||||
m_auiBits[0] = 0;
|
||||
m_auiBits[1] = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA256:
|
||||
{
|
||||
for(int i=0; i<SHA256LENGTH; i++)
|
||||
m_auiBuf[i] = sm_H256[i];
|
||||
m_auiBits[0] = 0;
|
||||
m_auiBits[1] = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA384:
|
||||
{
|
||||
for(int i=0; i<SHA512LENGTH; i++)
|
||||
m_aoui64Buf[i] = sm_H384[i];
|
||||
m_aoui64Bits[0].m_uiLeft = 0;
|
||||
m_aoui64Bits[0].m_uiRight = 0;
|
||||
m_aoui64Bits[1].m_uiLeft = 0;
|
||||
m_aoui64Bits[1].m_uiRight = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA512:
|
||||
{
|
||||
for(int i=0; i<SHA512LENGTH; i++)
|
||||
m_aoui64Buf[i] = sm_H512[i];
|
||||
m_aoui64Bits[0].m_uiLeft = 0;
|
||||
m_aoui64Bits[0].m_uiRight = 0;
|
||||
m_aoui64Bits[1].m_uiLeft = 0;
|
||||
m_aoui64Bits[1].m_uiRight = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
ostrstream ostr;
|
||||
ostr << "FileDigest ERROR: in CSHA() Constructor, Illegal Method " << iMethod << "!" << ends;
|
||||
string ostrMsg = ostr.str();
|
||||
ostr.freeze(false);
|
||||
throw runtime_error(ostrMsg);
|
||||
}
|
||||
}
|
||||
m_iMethod = iMethod;
|
||||
}
|
||||
|
||||
//Update context to reflect the concatenation of another buffer of bytes.
|
||||
void CSHA::AddData(char const* pcData, int iDataLength)
|
||||
{
|
||||
if(iDataLength < 0)
|
||||
throw runtime_error(string("FileDigest ERROR: in CSHA::AddData(), Data Length should be >= 0!"));
|
||||
unsigned int uiT;
|
||||
switch(m_iMethod)
|
||||
{
|
||||
case SHA160:
|
||||
case SHA256:
|
||||
{
|
||||
//Update bitcount
|
||||
uiT = m_auiBits[0];
|
||||
if((m_auiBits[0] = uiT + ((unsigned int)iDataLength << 3)) < uiT)
|
||||
m_auiBits[1]++; //Carry from low to high
|
||||
m_auiBits[1] += iDataLength >> 29;
|
||||
uiT = (uiT >> 3) & (BLOCKSIZE-1); //Bytes already
|
||||
//Handle any leading odd-sized chunks
|
||||
if(uiT != 0)
|
||||
{
|
||||
unsigned char* puc = (unsigned char*)m_aucIn + uiT;
|
||||
uiT = BLOCKSIZE - uiT;
|
||||
if(iDataLength < uiT)
|
||||
{
|
||||
memcpy(puc, pcData, iDataLength);
|
||||
return;
|
||||
}
|
||||
memcpy(puc, pcData, uiT);
|
||||
Transform();
|
||||
pcData += uiT;
|
||||
iDataLength -= uiT;
|
||||
}
|
||||
//Process data in 64-byte chunks
|
||||
while(iDataLength >= BLOCKSIZE)
|
||||
{
|
||||
memcpy(m_aucIn, pcData, BLOCKSIZE);
|
||||
Transform();
|
||||
pcData += BLOCKSIZE;
|
||||
iDataLength -= BLOCKSIZE;
|
||||
}
|
||||
//Handle any remaining bytes of data
|
||||
memcpy(m_aucIn, pcData, iDataLength);
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA384:
|
||||
case SHA512:
|
||||
{
|
||||
uiT = m_aoui64Bits[0].m_uiRight;
|
||||
unsigned int uiU = m_aoui64Bits[0].m_uiLeft;
|
||||
if((m_aoui64Bits[0].m_uiRight = uiT + ((unsigned int)iDataLength << 3)) < uiT)
|
||||
m_aoui64Bits[0].m_uiLeft++; //Carry from low to high
|
||||
unsigned int uiV = m_aoui64Bits[1].m_uiRight;
|
||||
if((m_aoui64Bits[0].m_uiLeft += iDataLength >> 29) < uiU)
|
||||
m_aoui64Bits[1].m_uiRight++;
|
||||
if(m_aoui64Bits[1].m_uiRight < uiV)
|
||||
m_aoui64Bits[1].m_uiLeft++;
|
||||
uiT = (uiT >> 3) & (BLOCKSIZE2-1); //Bytes already
|
||||
//Handle any leading odd-sized chunks
|
||||
if(uiT != 0)
|
||||
{
|
||||
unsigned char* puc = (unsigned char*)m_aucIn + uiT;
|
||||
uiT = BLOCKSIZE2 - uiT;
|
||||
if(iDataLength < uiT)
|
||||
{
|
||||
memcpy(puc, pcData, iDataLength);
|
||||
return;
|
||||
}
|
||||
memcpy(puc, pcData, uiT);
|
||||
Transform();
|
||||
pcData += uiT;
|
||||
iDataLength -= uiT;
|
||||
}
|
||||
//Process data in 64-byte chunks
|
||||
while(iDataLength >= BLOCKSIZE2)
|
||||
{
|
||||
memcpy(m_aucIn, pcData, BLOCKSIZE2);
|
||||
Transform();
|
||||
pcData += BLOCKSIZE2;
|
||||
iDataLength -= BLOCKSIZE2;
|
||||
}
|
||||
//Handle any remaining bytes of data
|
||||
memcpy(m_aucIn, pcData, iDataLength);
|
||||
}
|
||||
break;
|
||||
}
|
||||
//Set the flag
|
||||
m_bAddData = true;
|
||||
}
|
||||
|
||||
//Final wrapup - pad to 64-byte boundary with the bit pattern
|
||||
//1 0*(64-bit count of bits processed, MSB-first)
|
||||
void CSHA::FinalDigest(char* pcDigest)
|
||||
{
|
||||
//Is the User's responsability to ensure that pcDigest is properly allocated 20, 32,
|
||||
//48 or 64 bytes, depending on the method
|
||||
if(false == m_bAddData)
|
||||
throw runtime_error(string("FileDigest ERROR: in CSHA::FinalDigest(), No data Added before call!"));
|
||||
switch(m_iMethod)
|
||||
{
|
||||
case SHA160:
|
||||
case SHA256:
|
||||
{
|
||||
unsigned int uiCount;
|
||||
unsigned char *puc;
|
||||
//Compute number of bytes mod 64
|
||||
uiCount = (m_auiBits[0] >> 3) & (BLOCKSIZE-1);
|
||||
//Set the first char of padding to 0x80. This is safe since there is
|
||||
//always at least one byte free
|
||||
puc = m_aucIn + uiCount;
|
||||
*puc++ = 0x80;
|
||||
//Bytes of padding needed to make 64 bytes
|
||||
uiCount = BLOCKSIZE - uiCount - 1;
|
||||
//Pad out to 56 mod 64
|
||||
if(uiCount < 8)
|
||||
{
|
||||
//Two lots of padding: Pad the first block to 64 bytes
|
||||
memset(puc, 0, uiCount);
|
||||
Transform();
|
||||
//Now fill the next block with 56 bytes
|
||||
memset(m_aucIn, 0, BLOCKSIZE-8);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Pad block to 56 bytes
|
||||
memset(puc, 0, uiCount - 8);
|
||||
}
|
||||
//Append length in bits and transform
|
||||
Word2Bytes(m_auiBits[1], &m_aucIn[BLOCKSIZE-8]);
|
||||
Word2Bytes(m_auiBits[0], &m_aucIn[BLOCKSIZE-4]);
|
||||
Transform();
|
||||
switch(m_iMethod)
|
||||
{
|
||||
case SHA160:
|
||||
{
|
||||
for(int i=0; i<SHA160LENGTH; i++,pcDigest+=4)
|
||||
Word2Bytes(m_auiBuf[i], reinterpret_cast<unsigned char*>(pcDigest));
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA256:
|
||||
{
|
||||
for(int i=0; i<SHA256LENGTH; i++,pcDigest+=4)
|
||||
Word2Bytes(m_auiBuf[i], reinterpret_cast<unsigned char*>(pcDigest));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA384:
|
||||
case SHA512:
|
||||
{
|
||||
unsigned char *puc;
|
||||
//Compute number of bytes mod 128
|
||||
unsigned int uiCount = (m_aoui64Bits[0].m_uiRight >> 3) & (BLOCKSIZE2-1);
|
||||
//Set the first char of padding to 0x80. This is safe since there is
|
||||
//always at least one byte free
|
||||
puc = m_aucIn + uiCount;
|
||||
*puc++ = 0x80;
|
||||
//Bytes of padding needed to make 128 bytes
|
||||
uiCount = BLOCKSIZE2 - uiCount - 1;
|
||||
//Pad out to 112 mod 128
|
||||
if(uiCount < 16)
|
||||
{
|
||||
//Two lots of padding: Pad the first block to 128 bytes
|
||||
memset(puc, 0, uiCount);
|
||||
Transform();
|
||||
//Now fill the next block with 112 bytes
|
||||
memset(m_aucIn, 0, BLOCKSIZE2-16);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Pad block to 112 bytes
|
||||
memset(puc, 0, uiCount - 16);
|
||||
}
|
||||
//Append length in bits and transform
|
||||
Word2Bytes(m_aoui64Bits[1], &m_aucIn[BLOCKSIZE2-16]);
|
||||
Word2Bytes(m_aoui64Bits[0], &m_aucIn[BLOCKSIZE2-8]);
|
||||
Transform();
|
||||
switch(m_iMethod)
|
||||
{
|
||||
case SHA384:
|
||||
{
|
||||
for(int i=0; i<SHA384LENGTH; i++,pcDigest+=8)
|
||||
Word2Bytes(m_aoui64Buf[i], reinterpret_cast<unsigned char*>(pcDigest));
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA512:
|
||||
{
|
||||
for(int i=0; i<SHA512LENGTH; i++,pcDigest+=8)
|
||||
Word2Bytes(m_aoui64Buf[i], reinterpret_cast<unsigned char*>(pcDigest));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
//Reinitialize
|
||||
Reset();
|
||||
}
|
||||
|
||||
//Reset current operation in order to prepare a new one
|
||||
void CSHA::Reset()
|
||||
{
|
||||
//Reinitialize
|
||||
switch(m_iMethod)
|
||||
{
|
||||
case SHA160:
|
||||
{
|
||||
for(int i=0; i<SHA160LENGTH; i++)
|
||||
m_auiBuf[i] = sm_H160[i];
|
||||
m_auiBits[0] = 0;
|
||||
m_auiBits[1] = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA256:
|
||||
{
|
||||
for(int i=0; i<SHA256LENGTH; i++)
|
||||
m_auiBuf[i] = sm_H256[i];
|
||||
m_auiBits[0] = 0;
|
||||
m_auiBits[1] = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA384:
|
||||
{
|
||||
for(int i=0; i<SHA512LENGTH; i++)
|
||||
m_aoui64Buf[i] = sm_H384[i];
|
||||
m_aoui64Bits[0].m_uiLeft = 0;
|
||||
m_aoui64Bits[0].m_uiRight = 0;
|
||||
m_aoui64Bits[1].m_uiLeft = 0;
|
||||
m_aoui64Bits[1].m_uiRight = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA512:
|
||||
{
|
||||
for(int i=0; i<SHA512LENGTH; i++)
|
||||
m_aoui64Buf[i] = sm_H512[i];
|
||||
m_aoui64Bits[0].m_uiLeft = 0;
|
||||
m_aoui64Bits[0].m_uiRight = 0;
|
||||
m_aoui64Bits[1].m_uiLeft = 0;
|
||||
m_aoui64Bits[1].m_uiRight = 0;
|
||||
}
|
||||
}
|
||||
//Reset the flag
|
||||
m_bAddData = false;
|
||||
}
|
||||
|
||||
//The core of the SHA algorithm, this alters an existing SHA hash to
|
||||
//reflect the addition of 16 longwords of new data.
|
||||
void CSHA::Transform()
|
||||
{
|
||||
switch(m_iMethod)
|
||||
{
|
||||
case SHA160:
|
||||
{
|
||||
//Expansion of m_aucIn
|
||||
unsigned char* pucIn = m_aucIn;
|
||||
unsigned int auiW[80];
|
||||
int i;
|
||||
for(i=0; i<16; i++,pucIn+=4)
|
||||
Bytes2Word(pucIn, auiW[i]);
|
||||
for(i=16; i<80; i++)
|
||||
auiW[i] = CircularShift(1, auiW[i-3]^auiW[i-8]^auiW[i-14]^auiW[i-16]);
|
||||
unsigned int temp;
|
||||
unsigned int A, B, C, D, E;
|
||||
A = m_auiBuf[0];
|
||||
B = m_auiBuf[1];
|
||||
C = m_auiBuf[2];
|
||||
D = m_auiBuf[3];
|
||||
E = m_auiBuf[4];
|
||||
for(i=0; i<20; i++)
|
||||
{
|
||||
temp = CircularShift(5, A) + ((B & C) | ((~B) & D)) + E + auiW[i] + sm_K160[0];
|
||||
E = D;
|
||||
D = C;
|
||||
C = CircularShift(30, B);
|
||||
B = A;
|
||||
A = temp;
|
||||
}
|
||||
for(i=20; i<40; i++)
|
||||
{
|
||||
temp = CircularShift(5, A) + (B ^ C ^ D) + E + auiW[i] + sm_K160[1];
|
||||
E = D;
|
||||
D = C;
|
||||
C = CircularShift(30, B);
|
||||
B = A;
|
||||
A = temp;
|
||||
}
|
||||
for(i=40; i<60; i++)
|
||||
{
|
||||
temp = CircularShift(5, A) + ((B & C) | (B & D) | (C & D)) + E + auiW[i] + sm_K160[2];
|
||||
E = D;
|
||||
D = C;
|
||||
C = CircularShift(30, B);
|
||||
B = A;
|
||||
A = temp;
|
||||
}
|
||||
for(i=60; i<80; i++)
|
||||
{
|
||||
temp = CircularShift(5, A) + (B ^ C ^ D) + E + auiW[i] + sm_K160[3];
|
||||
E = D;
|
||||
D = C;
|
||||
C = CircularShift(30, B);
|
||||
B = A;
|
||||
A = temp;
|
||||
}
|
||||
m_auiBuf[0] += A;
|
||||
m_auiBuf[1] += B;
|
||||
m_auiBuf[2] += C;
|
||||
m_auiBuf[3] += D;
|
||||
m_auiBuf[4] += E;
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA256:
|
||||
{
|
||||
//Expansion of m_aucIn
|
||||
unsigned char* pucIn = m_aucIn;
|
||||
unsigned int auiW[64];
|
||||
int i;
|
||||
for(i=0; i<16; i++,pucIn+=4)
|
||||
Bytes2Word(pucIn, auiW[i]);
|
||||
for(i=16; i<64; i++)
|
||||
auiW[i] = sig1(auiW[i-2]) + auiW[i-7] + sig0(auiW[i-15]) + auiW[i-16];
|
||||
//OR
|
||||
//for(i=0; i<48; i++)
|
||||
// auiW[i+16] = sig1(auiW[i+14]) + auiW[i+9] + sig0(auiW[i+1]) + auiW[i];
|
||||
unsigned int a, b, c, d, e, f, g, h, t;
|
||||
a = m_auiBuf[0];
|
||||
b = m_auiBuf[1];
|
||||
c = m_auiBuf[2];
|
||||
d = m_auiBuf[3];
|
||||
e = m_auiBuf[4];
|
||||
f = m_auiBuf[5];
|
||||
g = m_auiBuf[6];
|
||||
h = m_auiBuf[7];
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K256[0] + auiW[0]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K256[1] + auiW[1]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K256[2] + auiW[2]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K256[3] + auiW[3]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K256[4] + auiW[4]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K256[5] + auiW[5]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K256[6] + auiW[6]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K256[7] + auiW[7]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K256[8] + auiW[8]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K256[9] + auiW[9]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K256[10] + auiW[10]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K256[11] + auiW[11]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K256[12] + auiW[12]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K256[13] + auiW[13]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K256[14] + auiW[14]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K256[15] + auiW[15]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K256[16] + auiW[16]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K256[17] + auiW[17]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K256[18] + auiW[18]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K256[19] + auiW[19]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K256[20] + auiW[20]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K256[21] + auiW[21]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K256[22] + auiW[22]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K256[23] + auiW[23]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K256[24] + auiW[24]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K256[25] + auiW[25]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K256[26] + auiW[26]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K256[27] + auiW[27]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K256[28] + auiW[28]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K256[29] + auiW[29]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K256[30] + auiW[30]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K256[31] + auiW[31]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K256[32] + auiW[32]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K256[33] + auiW[33]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K256[34] + auiW[34]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K256[35] + auiW[35]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K256[36] + auiW[36]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K256[37] + auiW[37]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K256[38] + auiW[38]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K256[39] + auiW[39]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K256[40] + auiW[40]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K256[41] + auiW[41]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K256[42] + auiW[42]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K256[43] + auiW[43]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K256[44] + auiW[44]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K256[45] + auiW[45]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K256[46] + auiW[46]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K256[47] + auiW[47]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K256[48] + auiW[48]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K256[49] + auiW[49]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K256[50] + auiW[50]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K256[51] + auiW[51]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K256[52] + auiW[52]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K256[53] + auiW[53]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K256[54] + auiW[54]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K256[55] + auiW[55]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K256[56] + auiW[56]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K256[57] + auiW[57]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K256[58] + auiW[58]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K256[59] + auiW[59]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K256[60] + auiW[60]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K256[61] + auiW[61]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K256[62] + auiW[62]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K256[63] + auiW[63]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
//OR
|
||||
/*
|
||||
unsigned int a, b, c, d, e, f, g, h, t1, t2;
|
||||
a = m_auiBuf[0];
|
||||
b = m_auiBuf[1];
|
||||
c = m_auiBuf[2];
|
||||
d = m_auiBuf[3];
|
||||
e = m_auiBuf[4];
|
||||
f = m_auiBuf[5];
|
||||
g = m_auiBuf[6];
|
||||
h = m_auiBuf[7];
|
||||
//
|
||||
for(i=0; i<64; i++)
|
||||
{
|
||||
t1 = h + SIG1(e) + CH(e, f, g) + sm_K256[i] + auiW[i];
|
||||
t2 = SIG0(a) + MAJ(a, b, c);
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d+t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
*/
|
||||
m_auiBuf[0] += a;
|
||||
m_auiBuf[1] += b;
|
||||
m_auiBuf[2] += c;
|
||||
m_auiBuf[3] += d;
|
||||
m_auiBuf[4] += e;
|
||||
m_auiBuf[5] += f;
|
||||
m_auiBuf[6] += g;
|
||||
m_auiBuf[7] += h;
|
||||
}
|
||||
break;
|
||||
|
||||
case SHA384:
|
||||
case SHA512:
|
||||
{
|
||||
//Expansion of m_aucIn
|
||||
unsigned char* pucIn = m_aucIn;
|
||||
SUI64 aoui64W[80];
|
||||
int i;
|
||||
for(i=0; i<16; i++,pucIn+=8)
|
||||
Bytes2Word(pucIn, aoui64W[i]);
|
||||
for(i=16; i<80; i++)
|
||||
aoui64W[i] = sig1(aoui64W[i-2]) + aoui64W[i-7] + sig0(aoui64W[i-15]) + aoui64W[i-16];
|
||||
SUI64 a, b, c, d, e, f, g, h, t;
|
||||
a = m_aoui64Buf[0];
|
||||
b = m_aoui64Buf[1];
|
||||
c = m_aoui64Buf[2];
|
||||
d = m_aoui64Buf[3];
|
||||
e = m_aoui64Buf[4];
|
||||
f = m_aoui64Buf[5];
|
||||
g = m_aoui64Buf[6];
|
||||
h = m_aoui64Buf[7];
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K512[0] + aoui64W[0]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K512[1] + aoui64W[1]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K512[2] + aoui64W[2]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K512[3] + aoui64W[3]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K512[4] + aoui64W[4]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K512[5] + aoui64W[5]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K512[6] + aoui64W[6]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K512[7] + aoui64W[7]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K512[8] + aoui64W[8]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K512[9] + aoui64W[9]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K512[10] + aoui64W[10]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K512[11] + aoui64W[11]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K512[12] + aoui64W[12]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K512[13] + aoui64W[13]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K512[14] + aoui64W[14]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K512[15] + aoui64W[15]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K512[16] + aoui64W[16]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K512[17] + aoui64W[17]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K512[18] + aoui64W[18]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K512[19] + aoui64W[19]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K512[20] + aoui64W[20]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K512[21] + aoui64W[21]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K512[22] + aoui64W[22]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K512[23] + aoui64W[23]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K512[24] + aoui64W[24]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K512[25] + aoui64W[25]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K512[26] + aoui64W[26]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K512[27] + aoui64W[27]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K512[28] + aoui64W[28]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K512[29] + aoui64W[29]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K512[30] + aoui64W[30]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K512[31] + aoui64W[31]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K512[32] + aoui64W[32]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K512[33] + aoui64W[33]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K512[34] + aoui64W[34]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K512[35] + aoui64W[35]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K512[36] + aoui64W[36]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K512[37] + aoui64W[37]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K512[38] + aoui64W[38]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K512[39] + aoui64W[39]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K512[40] + aoui64W[40]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K512[41] + aoui64W[41]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K512[42] + aoui64W[42]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K512[43] + aoui64W[43]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K512[44] + aoui64W[44]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K512[45] + aoui64W[45]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K512[46] + aoui64W[46]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K512[47] + aoui64W[47]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K512[48] + aoui64W[48]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K512[49] + aoui64W[49]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K512[50] + aoui64W[50]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K512[51] + aoui64W[51]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K512[52] + aoui64W[52]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K512[53] + aoui64W[53]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K512[54] + aoui64W[54]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K512[55] + aoui64W[55]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K512[56] + aoui64W[56]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K512[57] + aoui64W[57]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K512[58] + aoui64W[58]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K512[59] + aoui64W[59]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K512[60] + aoui64W[60]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K512[61] + aoui64W[61]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K512[62] + aoui64W[62]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K512[63] + aoui64W[63]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K512[64] + aoui64W[64]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K512[65] + aoui64W[65]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K512[66] + aoui64W[66]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K512[67] + aoui64W[67]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K512[68] + aoui64W[68]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K512[69] + aoui64W[69]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K512[70] + aoui64W[70]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K512[71] + aoui64W[71]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
t = h + SIG1(e) + CH(e, f, g) + sm_K512[72] + aoui64W[72]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
|
||||
t = g + SIG1(d) + CH(d, e, f) + sm_K512[73] + aoui64W[73]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
|
||||
t = f + SIG1(c) + CH(c, d, e) + sm_K512[74] + aoui64W[74]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
|
||||
t = e + SIG1(b) + CH(b, c, d) + sm_K512[75] + aoui64W[75]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
|
||||
t = d + SIG1(a) + CH(a, b, c) + sm_K512[76] + aoui64W[76]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
|
||||
t = c + SIG1(h) + CH(h, a, b) + sm_K512[77] + aoui64W[77]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
|
||||
t = b + SIG1(g) + CH(g, h, a) + sm_K512[78] + aoui64W[78]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
|
||||
t = a + SIG1(f) + CH(f, g, h) + sm_K512[79] + aoui64W[79]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
|
||||
//
|
||||
m_aoui64Buf[0] += a;
|
||||
m_aoui64Buf[1] += b;
|
||||
m_aoui64Buf[2] += c;
|
||||
m_aoui64Buf[3] += d;
|
||||
m_aoui64Buf[4] += e;
|
||||
m_aoui64Buf[5] += f;
|
||||
m_aoui64Buf[6] += g;
|
||||
m_aoui64Buf[7] += h;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
379
3rdparty/MultiEmulator/src/SHA.h
vendored
379
3rdparty/MultiEmulator/src/SHA.h
vendored
@ -1,379 +0,0 @@
|
||||
//SHA.h
|
||||
|
||||
#ifndef __SHA_H__
|
||||
#define __SHA_H__
|
||||
|
||||
#include "MessageDigest.h"
|
||||
|
||||
//Typical DISCLAIMER:
|
||||
//The code in this project is Copyright (C) 2003 by George Anescu. You have the right to
|
||||
//use and distribute the code in any way you see fit as long as this paragraph is included
|
||||
//with the distribution. No warranties or claims are made as to the validity of the
|
||||
//information and code contained herein, so use it at your own risk.
|
||||
|
||||
//Structure for representing an Unsigned Integer on 64 bits
|
||||
struct SUI64
|
||||
{
|
||||
//Data
|
||||
unsigned int m_uiLeft;
|
||||
unsigned int m_uiRight;
|
||||
|
||||
//Operators
|
||||
SUI64& operator++()
|
||||
{
|
||||
unsigned int uiTemp = m_uiRight;
|
||||
m_uiRight++;
|
||||
if(m_uiRight < uiTemp)
|
||||
m_uiLeft++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SUI64& operator--()
|
||||
{
|
||||
unsigned int uiTemp = m_uiRight;
|
||||
m_uiRight--;
|
||||
if(m_uiRight > uiTemp)
|
||||
m_uiLeft--;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SUI64& operator+=(SUI64 const& roUI64)
|
||||
{
|
||||
m_uiRight += roUI64.m_uiRight;
|
||||
if(m_uiRight < roUI64.m_uiRight)
|
||||
m_uiLeft++;
|
||||
m_uiLeft += roUI64.m_uiLeft;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SUI64& operator|=(SUI64 const& roUI64)
|
||||
{
|
||||
m_uiRight |= roUI64.m_uiRight;
|
||||
m_uiLeft |= roUI64.m_uiLeft;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SUI64& operator&=(SUI64 const& roUI64)
|
||||
{
|
||||
m_uiRight &= roUI64.m_uiRight;
|
||||
m_uiLeft &= roUI64.m_uiLeft;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SUI64& operator^=(SUI64 const& roUI64)
|
||||
{
|
||||
m_uiRight ^= roUI64.m_uiRight;
|
||||
m_uiLeft ^= roUI64.m_uiLeft;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SUI64& operator<<=(unsigned int uiBits)
|
||||
{
|
||||
if(uiBits < 32)
|
||||
{
|
||||
(m_uiLeft <<= uiBits) |= (m_uiRight >> (32-uiBits));
|
||||
m_uiRight <<= uiBits;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_uiLeft = m_uiRight << (uiBits-32);
|
||||
m_uiRight = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
SUI64& operator>>=(unsigned int uiBits)
|
||||
{
|
||||
if(uiBits < 32)
|
||||
{
|
||||
(m_uiRight >>= uiBits) |= (m_uiLeft << (32-uiBits));
|
||||
m_uiLeft >>= uiBits;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_uiRight = m_uiLeft >> (uiBits-32);
|
||||
m_uiLeft = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator>(SUI64 const& roUI64) const
|
||||
{
|
||||
if(m_uiLeft == roUI64.m_uiLeft)
|
||||
return m_uiRight > roUI64.m_uiRight;
|
||||
else
|
||||
return m_uiLeft > roUI64.m_uiLeft;
|
||||
}
|
||||
|
||||
bool operator<(SUI64 const& roUI64) const
|
||||
{
|
||||
if(m_uiLeft == roUI64.m_uiLeft)
|
||||
return m_uiRight < roUI64.m_uiRight;
|
||||
else
|
||||
return m_uiLeft < roUI64.m_uiLeft;
|
||||
}
|
||||
};
|
||||
|
||||
inline SUI64 operator+(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
|
||||
{
|
||||
SUI64 temp = roUI64_1;
|
||||
temp += roUI64_2;
|
||||
return temp;
|
||||
}
|
||||
|
||||
inline SUI64 operator|(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
|
||||
{
|
||||
SUI64 temp = roUI64_1;
|
||||
temp |= roUI64_2;
|
||||
return temp;
|
||||
}
|
||||
|
||||
inline SUI64 operator&(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
|
||||
{
|
||||
SUI64 temp = roUI64_1;
|
||||
temp &= roUI64_2;
|
||||
return temp;
|
||||
}
|
||||
|
||||
inline SUI64 operator^(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
|
||||
{
|
||||
SUI64 temp = roUI64_1;
|
||||
temp ^= roUI64_2;
|
||||
return temp;
|
||||
}
|
||||
|
||||
inline SUI64 operator<<(SUI64 const& roUI64, unsigned int uiBits)
|
||||
{
|
||||
SUI64 temp = roUI64;
|
||||
temp <<= uiBits;
|
||||
return temp;
|
||||
}
|
||||
|
||||
inline SUI64 operator>>(SUI64 const& roUI64, unsigned int uiBits)
|
||||
{
|
||||
SUI64 temp = roUI64;
|
||||
temp >>= uiBits;
|
||||
return temp;
|
||||
}
|
||||
|
||||
inline bool operator>(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
|
||||
{
|
||||
return roUI64_1.operator>(roUI64_2);
|
||||
}
|
||||
|
||||
inline bool operator<(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
|
||||
{
|
||||
return roUI64_1.operator<(roUI64_2);
|
||||
}
|
||||
|
||||
//SHA Message Digest algorithm
|
||||
//SHA160 TEST VALUES:
|
||||
//1)"abc"
|
||||
//"A9993E364706816ABA3E25717850C26C9CD0D89D"
|
||||
//
|
||||
//2)"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
||||
//"84983E441C3BD26EBAAE4AA1F95129E5E54670F1"
|
||||
//
|
||||
//3)1,000,000 repetitions of "a".
|
||||
//"34AA973CD4C4DAA4F61EEB2BDBAD27316534016F"
|
||||
//
|
||||
//SHA256 TEST VALUES:
|
||||
//1)One-Block Message "abc"
|
||||
//"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
|
||||
//
|
||||
//2)"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
||||
//"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
|
||||
//
|
||||
//3)Multi-Block Message "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
|
||||
//"CF5B16A778AF8380036CE59E7B0492370B249B11E8F07A51AFAC45037AFEE9D1"
|
||||
//
|
||||
//4)Long Message "a" 1,000,000 times
|
||||
//"cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0"
|
||||
//
|
||||
//SHA384 TEST VALUES:
|
||||
//1)One-Block Message "abc"
|
||||
//"cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7"
|
||||
//
|
||||
//2)Multi-Block Message "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
|
||||
//"09330C33F71147E83D192FC782CD1B4753111B173B3B05D22FA08086E3B0F712FCC7C71A557E2DB966C3E9FA91746039"
|
||||
//
|
||||
//3)Long Message "a" 1,000,000 times
|
||||
//"9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985"
|
||||
//
|
||||
//SHA512 TEST VALUES:
|
||||
//1)One-Block Message "abc"
|
||||
//"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a8
|
||||
//36ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"
|
||||
//
|
||||
//2)"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
|
||||
//"8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4
|
||||
//331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909"
|
||||
//
|
||||
//3)""
|
||||
//"CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D13C5D85F2B0
|
||||
//FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E"
|
||||
//
|
||||
//4)Long Message "a" 1,000,000 times
|
||||
//"E718483D0CE769644E2E42C7BC15B4638E1F98B13B2044285632A803AFA973EBDE0FF244877EA60A
|
||||
//4CB0432CE577C31BEB009C5C2C49AA2E4EADB217AD8CC09B"
|
||||
|
||||
class CSHA : public IMessageDigest
|
||||
{
|
||||
public:
|
||||
enum { SHA160=0, SHA256=1, SHA384=2, SHA512=3 };
|
||||
//CONSTRUCTOR
|
||||
CSHA(int iMethod=SHA160);
|
||||
//Update context to reflect the concatenation of another buffer of bytes.
|
||||
void AddData(char const* pcData, int iDataLength);
|
||||
//Final wrapup - pad to 64-byte boundary with the bit pattern
|
||||
//1 0*(64-bit count of bits processed, MSB-first)
|
||||
void FinalDigest(char* pcDigest);
|
||||
//Reset current operation in order to prepare a new one
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
//Transformation Function
|
||||
void Transform();
|
||||
//The Method
|
||||
int m_iMethod;
|
||||
enum { BLOCKSIZE2 = BLOCKSIZE<<1 };
|
||||
//For 32 bits Integers
|
||||
enum { SHA160LENGTH=5, SHA256LENGTH=8 };
|
||||
//Context Variables
|
||||
unsigned int m_auiBuf[SHA256LENGTH]; //Maximum for SHA256
|
||||
unsigned int m_auiBits[2];
|
||||
unsigned char m_aucIn[BLOCKSIZE2]; //128 bytes for SHA384, SHA512
|
||||
//Internal auxiliary static functions
|
||||
static unsigned int CircularShift(unsigned int uiBits, unsigned int uiWord);
|
||||
static unsigned int CH(unsigned int x, unsigned int y, unsigned int z);
|
||||
static unsigned int MAJ(unsigned int x, unsigned int y, unsigned int z);
|
||||
static unsigned int SIG0(unsigned int x);
|
||||
static unsigned int SIG1(unsigned int x);
|
||||
static unsigned int sig0(unsigned int x);
|
||||
static unsigned int sig1(unsigned int x);
|
||||
static void Bytes2Word(unsigned char const* pcBytes, unsigned int& ruiWord);
|
||||
static void Word2Bytes(unsigned int const& ruiWord, unsigned char* pcBytes);
|
||||
static const unsigned int sm_K160[4];
|
||||
static const unsigned int sm_H160[SHA160LENGTH];
|
||||
static const unsigned int sm_K256[64];
|
||||
static const unsigned int sm_H256[SHA256LENGTH];
|
||||
|
||||
//For 64 bits Integers
|
||||
enum { SHA384LENGTH=6, SHA512LENGTH=8 };
|
||||
//Context Variables
|
||||
SUI64 m_aoui64Buf[SHA512LENGTH]; //Maximum for SHA512
|
||||
SUI64 m_aoui64Bits[2];
|
||||
//Internal auxiliary static functions
|
||||
static SUI64 CircularShift(unsigned int uiBits, SUI64 const& roui64Word);
|
||||
static SUI64 CH(SUI64 const& x, SUI64 const& y, SUI64 const& z);
|
||||
static SUI64 MAJ(SUI64 const& x, SUI64 const& y, SUI64 const& z);
|
||||
static SUI64 SIG0(SUI64 const& x);
|
||||
static SUI64 SIG1(SUI64 const& x);
|
||||
static SUI64 sig0(SUI64 const& x);
|
||||
static SUI64 sig1(SUI64 const& x);
|
||||
static void Bytes2Word(unsigned char const* pcBytes, SUI64& ruiWord);
|
||||
static void Word2Bytes(SUI64 const& ruiWord, unsigned char* pcBytes);
|
||||
static const SUI64 sm_H384[SHA512LENGTH]; //Dim is as 512
|
||||
static const SUI64 sm_K512[80];
|
||||
static const SUI64 sm_H512[SHA512LENGTH];
|
||||
};
|
||||
|
||||
inline unsigned int CSHA::CircularShift(unsigned int uiBits, unsigned int uiWord)
|
||||
{
|
||||
return (uiWord << uiBits) | (uiWord >> (32-uiBits));
|
||||
}
|
||||
|
||||
inline unsigned int CSHA::CH(unsigned int x, unsigned int y, unsigned int z)
|
||||
{
|
||||
return ((x&(y^z))^z);
|
||||
}
|
||||
|
||||
inline unsigned int CSHA::MAJ(unsigned int x, unsigned int y, unsigned int z)
|
||||
{
|
||||
return (((x|y)&z)|(x&y));
|
||||
}
|
||||
|
||||
inline unsigned int CSHA::SIG0(unsigned int x)
|
||||
{
|
||||
return ((x >> 2)|(x << 30)) ^ ((x >> 13)|(x << 19)) ^ ((x >> 22)|(x << 10));
|
||||
}
|
||||
|
||||
inline unsigned int CSHA::SIG1(unsigned int x)
|
||||
{
|
||||
return ((x >> 6)|(x << 26)) ^ ((x >> 11)|(x << 21)) ^ ((x >> 25)|(x << 7));
|
||||
}
|
||||
|
||||
inline unsigned int CSHA::sig0(unsigned int x)
|
||||
{
|
||||
return ((x >> 7)|(x << 25)) ^ ((x >> 18)|(x << 14)) ^ (x >> 3);
|
||||
}
|
||||
|
||||
inline unsigned int CSHA::sig1(unsigned int x)
|
||||
{
|
||||
return ((x >> 17)|(x << 15)) ^ ((x >> 19)|(x << 13)) ^ (x >> 10);
|
||||
}
|
||||
|
||||
inline void CSHA::Bytes2Word(unsigned char const* pcBytes, unsigned int& ruiWord)
|
||||
{
|
||||
ruiWord = (unsigned int)*(pcBytes+3) | (unsigned int)(*(pcBytes+2)<<8) |
|
||||
(unsigned int)(*(pcBytes+1)<<16) | (unsigned int)(*pcBytes<<24);
|
||||
}
|
||||
|
||||
inline void CSHA::Word2Bytes(unsigned int const& ruiWord, unsigned char* pcBytes)
|
||||
{
|
||||
pcBytes += 3;
|
||||
*pcBytes = ruiWord & 0xff;
|
||||
*--pcBytes = (ruiWord>>8) & 0xff;
|
||||
*--pcBytes = (ruiWord>>16) & 0xff;
|
||||
*--pcBytes = (ruiWord>>24) & 0xff;
|
||||
}
|
||||
|
||||
inline SUI64 CSHA::CircularShift(unsigned int uiBits, SUI64 const& roui64Word)
|
||||
{
|
||||
return (roui64Word << uiBits) | (roui64Word >> (64-uiBits));
|
||||
}
|
||||
|
||||
inline SUI64 CSHA::CH(SUI64 const& x, SUI64 const& y, SUI64 const& z)
|
||||
{
|
||||
return ((x&(y^z))^z);
|
||||
}
|
||||
|
||||
inline SUI64 CSHA::MAJ(SUI64 const& x, SUI64 const& y, SUI64 const& z)
|
||||
{
|
||||
return (((x|y)&z)|(x&y));
|
||||
}
|
||||
|
||||
inline SUI64 CSHA::SIG0(SUI64 const& x)
|
||||
{
|
||||
return ((x >> 28)|(x << 36)) ^ ((x >> 34)|(x << 30)) ^ ((x >> 39)|(x << 25));
|
||||
}
|
||||
|
||||
inline SUI64 CSHA::SIG1(SUI64 const& x)
|
||||
{
|
||||
return ((x >> 14)|(x << 50)) ^ ((x >> 18)|(x << 46)) ^ ((x >> 41)|(x << 23));
|
||||
}
|
||||
|
||||
inline SUI64 CSHA::sig0(SUI64 const& x)
|
||||
{
|
||||
return ((x >> 1)|(x << 63)) ^ ((x >> 8)|(x << 56)) ^ (x >> 7);
|
||||
}
|
||||
|
||||
inline SUI64 CSHA::sig1(SUI64 const& x)
|
||||
{
|
||||
return ((x >> 19)|(x << 45)) ^ ((x >> 61)|(x << 3)) ^ (x >> 6);
|
||||
}
|
||||
|
||||
inline void CSHA::Bytes2Word(unsigned char const* pcBytes, SUI64& ruiWord)
|
||||
{
|
||||
Bytes2Word(pcBytes+4, ruiWord.m_uiRight);
|
||||
Bytes2Word(pcBytes, ruiWord.m_uiLeft);
|
||||
}
|
||||
|
||||
inline void CSHA::Word2Bytes(SUI64 const& ruiWord, unsigned char* pcBytes)
|
||||
{
|
||||
Word2Bytes(ruiWord.m_uiRight, pcBytes+4);
|
||||
Word2Bytes(ruiWord.m_uiLeft, pcBytes);
|
||||
}
|
||||
|
||||
#endif // __SHA_H__
|
13
3rdparty/MultiEmulator/src/Setti.cpp
vendored
13
3rdparty/MultiEmulator/src/Setti.cpp
vendored
@ -1,13 +0,0 @@
|
||||
#include "multi_emulator.h"
|
||||
|
||||
int GenerateSetti(void *pDest)
|
||||
{
|
||||
auto pTicket = (int *)pDest;
|
||||
|
||||
pTicket[0] = 0xD4CA7F7B;
|
||||
pTicket[1] = 0xC7DB6023;
|
||||
pTicket[2] = 0x6D6A2E1F;
|
||||
pTicket[5] = 0xB4C43105;
|
||||
|
||||
return 768;
|
||||
}
|
18
3rdparty/MultiEmulator/src/SteamEmu.cpp
vendored
18
3rdparty/MultiEmulator/src/SteamEmu.cpp
vendored
@ -1,18 +0,0 @@
|
||||
#include "multi_emulator.h"
|
||||
int GenerateSteamEmu(void *pDest, int nSteamID)
|
||||
{
|
||||
auto pTicket = (int *)pDest;
|
||||
|
||||
pTicket[20] = -1; // +80, dproto/reunion wants this value to be -1, but if this value
|
||||
// does not match -1, then instead of SteamID in [21] cell
|
||||
// client IP address that xored with 0x25730981 number should
|
||||
// be used. But dproto/reunion will just skip ticket validation
|
||||
// in that case.
|
||||
|
||||
pTicket[21] = nSteamID; // +84, SteamId, low part. Actually, this is just system volume serial
|
||||
// number, which comes from GetVolumeInformationA() function. If
|
||||
// function failed (returned 0), then instead of volume serial number
|
||||
// 777 number will be written to the ticket.
|
||||
|
||||
return 768;
|
||||
}
|
12
3rdparty/MultiEmulator/src/StrUtils.cpp
vendored
12
3rdparty/MultiEmulator/src/StrUtils.cpp
vendored
@ -1,12 +0,0 @@
|
||||
#include "StrUtils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void CreateRandomString(char *pszDest, int nLength)
|
||||
{
|
||||
static const char c_szAlphaNum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
for (int i = 0; i < nLength; ++i)
|
||||
pszDest[i] = c_szAlphaNum[rand() % (sizeof(c_szAlphaNum) - 1)];
|
||||
|
||||
pszDest[nLength] = '\0';
|
||||
}
|
3
3rdparty/MultiEmulator/src/StrUtils.h
vendored
3
3rdparty/MultiEmulator/src/StrUtils.h
vendored
@ -1,3 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
void CreateRandomString(char *pszDest, int nLength);
|
24
3rdparty/MultiEmulator/wscript
vendored
24
3rdparty/MultiEmulator/wscript
vendored
@ -1,24 +0,0 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# mittorn, 2018
|
||||
|
||||
from waflib import Logs
|
||||
import os
|
||||
|
||||
top = '.'
|
||||
|
||||
def options(opt):
|
||||
return
|
||||
|
||||
def configure(conf):
|
||||
return
|
||||
|
||||
def build(bld):
|
||||
bld.stlib(
|
||||
source = bld.path.ant_glob(['src/*.cpp']),
|
||||
target = 'MultiEmulator',
|
||||
features = 'cxx',
|
||||
includes = ['include/', 'src/'],
|
||||
export_includes = ['include/'],
|
||||
subsystem = bld.env.MSVC_SUBSYSTEM
|
||||
)
|
Loading…
Reference in New Issue
Block a user