mirror of
https://github.com/SWG-Source/src.git
synced 2026-01-15 23:05:01 -05:00
Checkpoint - committing to investigate a different approach.
This commit is contained in:
@@ -89,7 +89,7 @@ namespace LoginServerNamespace {
|
||||
};
|
||||
|
||||
// Very simple function to determine if a "threshold" has been crossed
|
||||
bool hasCrossedThreshold(int thresholdValue, int oldValue, int newValue) {
|
||||
bool hasCrossedThreshold(int32_t thresholdValue, int32_t oldValue, int32_t newValue) {
|
||||
bool result = false;
|
||||
|
||||
if ((oldValue < thresholdValue) && (newValue >= thresholdValue)) {
|
||||
@@ -106,8 +106,8 @@ namespace LoginServerNamespace {
|
||||
// for testing purpose when not using session authentication, store
|
||||
// the account feature Ids here, which will get cleared (obviously)
|
||||
// when the LoginServer is restarted
|
||||
std::map <uint32, std::map<uint32, int>> s_nonSessionTestingAccountSwgFeatureIds;
|
||||
std::map <uint32, std::map<uint32, int>> s_nonSessionTestingAccountSwgTcgFeatureIds;
|
||||
std::map <uint32, std::map<uint32, int32_t>> s_nonSessionTestingAccountSwgFeatureIds;
|
||||
std::map <uint32, std::map<uint32, int32_t>> s_nonSessionTestingAccountSwgTcgFeatureIds;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -191,12 +191,12 @@ LoginServer::~LoginServer() {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int LoginServer::addClient(ClientConnection &client) {
|
||||
int32_t LoginServer::addClient(ClientConnection &client) {
|
||||
DEBUG_FATAL(client.getIsValidated(), ("Tried to add an already validated client?!"));
|
||||
//Perhaps add a debug only check to make sure a client connection isn't in twice...I'm not sure how that could happen.
|
||||
|
||||
static int nextClientId = 0;
|
||||
int tmp = ++nextClientId;
|
||||
static int32_t nextClientId = 0;
|
||||
int32_t tmp = ++nextClientId;
|
||||
m_clientMap[tmp] = &client;
|
||||
return tmp;
|
||||
}
|
||||
@@ -213,9 +213,9 @@ ClientConnection *LoginServer::getValidatedClient(const StationId &clientId) {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ClientConnection *LoginServer::getUnvalidatedClient(int clientId) {
|
||||
ClientConnection *LoginServer::getUnvalidatedClient(int32_t clientId) {
|
||||
WARNING_STRICT_FATAL(clientId == 0, ("Tried to get an unvalidated client with client id == 0"));
|
||||
std::map<int, ClientConnection *>::iterator i = m_clientMap.find(clientId);
|
||||
std::map<int32_t, ClientConnection *>::iterator i = m_clientMap.find(clientId);
|
||||
if (i == m_clientMap.end()) {
|
||||
return 0;
|
||||
}
|
||||
@@ -224,8 +224,8 @@ ClientConnection *LoginServer::getUnvalidatedClient(int clientId) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void LoginServer::removeClient(int clientId) {
|
||||
std::map<int, ClientConnection *>::iterator i = m_clientMap.find(clientId);
|
||||
void LoginServer::removeClient(int32_t clientId) {
|
||||
std::map<int32_t, ClientConnection *>::iterator i = m_clientMap.find(clientId);
|
||||
if (i != m_clientMap.end()) {
|
||||
if (i->second->getIsValidated()) {
|
||||
IGNORE_RETURN(m_validatedClientMap.erase(i->second->getStationId()));
|
||||
@@ -306,8 +306,8 @@ KeyShare::Token LoginServer::makeToken(const unsigned char *const data, const ui
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void LoginServer::pushAllKeys(CentralServerConnection *targetGameServer) const {
|
||||
for (int i = static_cast<int>(keyServer->getKeyCount()) - 1; i >= 0; i--) {
|
||||
LoginKeyPush pk(keyServer->getKey(static_cast<unsigned int>(i)));
|
||||
for (int32_t i = static_cast<int32_t>(keyServer->getKeyCount()) - 1; i >= 0; i--) {
|
||||
LoginKeyPush pk(keyServer->getKey(static_cast<uint32_t>(i)));
|
||||
targetGameServer->send(pk, true);
|
||||
}
|
||||
}
|
||||
@@ -530,18 +530,18 @@ void LoginServer::receiveMessage(const MessageDispatch::Emitter &source, const M
|
||||
// for testing purpose when not using session authentication, store
|
||||
// the account feature Ids locally in memory, which will get cleared
|
||||
// (obviously) when the LoginServer is restarted
|
||||
std::map <uint32, std::map<uint32, int>> *nonSessionTestingAccountFeatureIds = nullptr;
|
||||
std::map <uint32, std::map<uint32, int32_t>> *nonSessionTestingAccountFeatureIds = nullptr;
|
||||
if (msg.getGameCode() == PlatformGameCode::SWG) {
|
||||
nonSessionTestingAccountFeatureIds = &s_nonSessionTestingAccountSwgFeatureIds;
|
||||
} else if (msg.getGameCode() == PlatformGameCode::SWGTCG) {
|
||||
nonSessionTestingAccountFeatureIds = &s_nonSessionTestingAccountSwgTcgFeatureIds;
|
||||
}
|
||||
|
||||
int currentFeatureIdCount = 0;
|
||||
int updatedFeatureIdCount = 0;
|
||||
int32_t currentFeatureIdCount = 0;
|
||||
int32_t updatedFeatureIdCount = 0;
|
||||
if (nonSessionTestingAccountFeatureIds) {
|
||||
std::map<uint32, int> &accountFeatureIds = (*nonSessionTestingAccountFeatureIds)[msg.getTargetStationId()];
|
||||
std::map<uint32, int>::const_iterator accountFeatureId = accountFeatureIds.find(msg.getFeatureId());
|
||||
std::map<uint32, int32_t> &accountFeatureIds = (*nonSessionTestingAccountFeatureIds)[msg.getTargetStationId()];
|
||||
std::map<uint32, int32_t>::const_iterator accountFeatureId = accountFeatureIds.find(msg.getFeatureId());
|
||||
if (accountFeatureId != accountFeatureIds.end()) {
|
||||
currentFeatureIdCount = accountFeatureId->second;
|
||||
}
|
||||
@@ -587,18 +587,18 @@ void LoginServer::receiveMessage(const MessageDispatch::Emitter &source, const M
|
||||
// for testing purpose when not using session authentication, store
|
||||
// the account feature Ids locally in memory, which will get cleared
|
||||
// (obviously) when the LoginServer is restarted
|
||||
std::map <uint32, std::map<uint32, int>> *nonSessionTestingAccountFeatureIds = nullptr;
|
||||
std::map <uint32, std::map<uint32, int32_t>> *nonSessionTestingAccountFeatureIds = nullptr;
|
||||
if (msg.getGameCode() == PlatformGameCode::SWG) {
|
||||
nonSessionTestingAccountFeatureIds = &s_nonSessionTestingAccountSwgFeatureIds;
|
||||
} else if (msg.getGameCode() == PlatformGameCode::SWGTCG) {
|
||||
nonSessionTestingAccountFeatureIds = &s_nonSessionTestingAccountSwgTcgFeatureIds;
|
||||
}
|
||||
|
||||
static std::map<uint32, int> const empty;
|
||||
std::map<uint32, int> const *accountFeatureIds = ∅
|
||||
static std::map<uint32, int32_t> const empty;
|
||||
std::map<uint32, int32_t> const *accountFeatureIds = ∅
|
||||
|
||||
if (nonSessionTestingAccountFeatureIds) {
|
||||
std::map < uint32, std::map < uint32, int > > ::const_iterator
|
||||
std::map < uint32, std::map < uint32, int32_t > > ::const_iterator
|
||||
iterFind = nonSessionTestingAccountFeatureIds->find(msg.getTargetStationId());
|
||||
if (iterFind != nonSessionTestingAccountFeatureIds->end()) {
|
||||
accountFeatureIds = &(iterFind->second);
|
||||
@@ -823,9 +823,9 @@ void LoginServer::receiveMessage(const MessageDispatch::Emitter &source, const M
|
||||
// for testing purpose when not using session authentication, store
|
||||
// the account feature Ids locally in memory, which will get cleared
|
||||
// (obviously) when the LoginServer is restarted
|
||||
std::map<uint32, int> &accountFeatureIds = s_nonSessionTestingAccountSwgFeatureIds[msg->getStationId()];
|
||||
std::map<uint32, int>::const_iterator accountFeatureId = accountFeatureIds.find(requiredAccountFeatureId);
|
||||
int currentFeatureIdCount = 0;
|
||||
std::map<uint32, int32_t> &accountFeatureIds = s_nonSessionTestingAccountSwgFeatureIds[msg->getStationId()];
|
||||
std::map<uint32, int32_t>::const_iterator accountFeatureId = accountFeatureIds.find(requiredAccountFeatureId);
|
||||
int32_t currentFeatureIdCount = 0;
|
||||
if (accountFeatureId != accountFeatureIds.end()) {
|
||||
currentFeatureIdCount = accountFeatureId->second;
|
||||
}
|
||||
@@ -841,7 +841,7 @@ void LoginServer::receiveMessage(const MessageDispatch::Emitter &source, const M
|
||||
sendToCluster(conn->getClusterId(), rsp);
|
||||
} else {
|
||||
// account has required feature id so claim is success, so update feature id for claim
|
||||
int const updatedFeatureIdCount = (consumeAccountFeatureId ? std::max(0,
|
||||
int32_t const updatedFeatureIdCount = (consumeAccountFeatureId ? std::max(0,
|
||||
currentFeatureIdCount -
|
||||
1)
|
||||
: currentFeatureIdCount);
|
||||
@@ -932,7 +932,7 @@ void LoginServer::receiveMessage(const MessageDispatch::Emitter &source, const M
|
||||
* @see DatabaseConnection::getAccountValidationData
|
||||
*/
|
||||
void
|
||||
LoginServer::validateAccount(const StationId &stationId, uint32 clusterId, uint32 subscriptionBits, bool canCreateRegular, bool canCreateJedi, bool canSkipTutorial, unsigned int track, std::vector <std::pair<NetworkId, std::string>> const &consumedRewardEvents, std::vector <std::pair<NetworkId, std::string>> const &claimedRewardItems) {
|
||||
LoginServer::validateAccount(const StationId &stationId, uint32 clusterId, uint32 subscriptionBits, bool canCreateRegular, bool canCreateJedi, bool canSkipTutorial, uint32 track, std::vector <std::pair<NetworkId, std::string>> const &consumedRewardEvents, std::vector <std::pair<NetworkId, std::string>> const &claimedRewardItems) {
|
||||
bool canLogin = false;
|
||||
|
||||
ClusterListEntry *cle = findClusterById(clusterId);
|
||||
@@ -1038,7 +1038,7 @@ void LoginServer::run(void) {
|
||||
unsigned long totalTime = 0;
|
||||
|
||||
// load authentication data and bind the monitor to the port
|
||||
const int port = ConfigLoginServer::getMetricsListenerPort();
|
||||
const int32_t port = ConfigLoginServer::getMetricsListenerPort();
|
||||
CMonitorAPI *mon = nullptr;
|
||||
|
||||
if (port) {
|
||||
@@ -1090,8 +1090,8 @@ void LoginServer::run(void) {
|
||||
NetworkHandler::clearBytesThisFrame();
|
||||
|
||||
if (port) {
|
||||
mon->set(WORLD_COUNT_CHANNEL, static_cast<int>(getInstance().m_clientMap.size()));
|
||||
int count = 0;
|
||||
mon->set(WORLD_COUNT_CHANNEL, static_cast<int32_t>(getInstance().m_clientMap.size()));
|
||||
int32_t count = 0;
|
||||
ClusterListType::const_iterator i;
|
||||
for (i = getInstance().m_clusterList.begin(); i != getInstance().m_clusterList.end(); ++i) {
|
||||
if ((*i)->m_connected) {
|
||||
@@ -1119,7 +1119,7 @@ void LoginServer::run(void) {
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void
|
||||
LoginServer::sendAvatarList(const StationId &stationId, int stationIdNumberJediSlot, const AvatarList &avatars, TransferCharacterData *const transferData) {
|
||||
LoginServer::sendAvatarList(const StationId &stationId, int32_t stationIdNumberJediSlot, const AvatarList &avatars, TransferCharacterData *const transferData) {
|
||||
std::vector <EnumerateCharacterId::Chardata> chardata;
|
||||
chardata.reserve(avatars.size());
|
||||
|
||||
@@ -1176,7 +1176,7 @@ LoginServer::sendAvatarList(const StationId &stationId, int stationIdNumberJediS
|
||||
|
||||
// this message ***MUST*** be sent first, as the client expects to
|
||||
// receive this information before receiving the avatar list information
|
||||
GenericValueTypeMessage<int> const msgStationIdHasJediSlot("StationIdHasJediSlot", stationIdNumberJediSlot);
|
||||
GenericValueTypeMessage<int32_t> const msgStationIdHasJediSlot("StationIdHasJediSlot", stationIdNumberJediSlot);
|
||||
conn->send(msgStationIdHasJediSlot, true);
|
||||
|
||||
conn->send(msg, true);
|
||||
@@ -1397,7 +1397,7 @@ void LoginServer::sendClusterStatus(ClientConnection &conn) const {
|
||||
// connection server will force disconnect non-secure connections if they are required by configuration.
|
||||
const bool clientIsPrivate = conn.getAdminLevel() > 0;
|
||||
|
||||
const unsigned int subscriptionBits = conn.getSubscriptionBits();
|
||||
const uint32_t subscriptionBits = conn.getSubscriptionBits();
|
||||
const bool isFreeTrialAccount = (((subscriptionBits & ClientSubscriptionFeature::FreeTrial) != 0) &&
|
||||
((subscriptionBits & ClientSubscriptionFeature::Base) == 0));
|
||||
|
||||
@@ -1540,7 +1540,7 @@ LoginServer::ClusterListEntry::ClusterListEntry()
|
||||
* If we don't know about the cluster already, add it to the list.
|
||||
*/
|
||||
void
|
||||
LoginServer::updateClusterData(uint32 clusterId, const std::string &clusterName, const std::string &address, const uint16 port, bool secret, bool locked, bool notRecommended, int maxCharactersPerAccount, int onlinePlayerLimit, int onlineFreeTrialLimit, bool freeTrialCanCreateChar, int onlineTutorialLimit) {
|
||||
LoginServer::updateClusterData(uint32 clusterId, const std::string &clusterName, const std::string &address, const uint16 port, bool secret, bool locked, bool notRecommended, int32_t maxCharactersPerAccount, int32_t onlinePlayerLimit, int32_t onlineFreeTrialLimit, bool freeTrialCanCreateChar, int32_t onlineTutorialLimit) {
|
||||
ClusterListEntry *cle = findClusterById(clusterId);
|
||||
|
||||
if (ConfigLoginServer::getDevelopmentMode()) {
|
||||
@@ -1781,7 +1781,7 @@ void LoginServer::getClusterIds(std::vector <uint32> result) {
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void
|
||||
LoginServer::setClusterInfoByName(const std::string &name, const std::string &branch, int changelist, const std::string &networkVersion) {
|
||||
LoginServer::setClusterInfoByName(const std::string &name, const std::string &branch, int32_t changelist, const std::string &networkVersion) {
|
||||
ClusterListEntry *entry = findClusterByName(name);
|
||||
|
||||
if (entry) {
|
||||
|
||||
@@ -38,10 +38,10 @@ class LoginServer : public Singleton<LoginServer>, public MessageDispatch::Recei
|
||||
public:
|
||||
|
||||
~LoginServer ();
|
||||
int addClient (ClientConnection & client);
|
||||
int32_t addClient (ClientConnection & client);
|
||||
ClientConnection* getValidatedClient (const StationId& suid);
|
||||
ClientConnection* getUnvalidatedClient (int clientId);
|
||||
void removeClient (int clientId);
|
||||
ClientConnection* getUnvalidatedClient (int32_t clientId);
|
||||
void removeClient (int32_t clientId);
|
||||
|
||||
const std::unordered_map<std::string, const CentralServerConnection *> & getCentralServerMap_hide() const;
|
||||
|
||||
@@ -57,11 +57,11 @@ public:
|
||||
static void run (void);
|
||||
void onValidateClient (StationId id, const std::string & username, ClientConnection*,bool, const char*, uint32 gameBits, uint32 subscriptionBits);
|
||||
|
||||
void sendAvatarList (const StationId& stationId, int stationIdNumberJediSlot, const AvatarList &avatars, TransferCharacterData * const);
|
||||
void sendAvatarList (const StationId& stationId, int32_t stationIdNumberJediSlot, const AvatarList &avatars, TransferCharacterData * const);
|
||||
|
||||
void updateClusterData (uint32 clusterId, const std::string &clusterName, const std::string &address, const uint16 port, bool secret, bool locked, bool notRecommended, int maxCharactersPerAccount, int onlinePlayerLimit, int onlineFreeTrialLimit, bool freeTrialCanCreateChar, int onlineTutorialLimit);
|
||||
void updateClusterData (uint32 clusterId, const std::string &clusterName, const std::string &address, const uint16 port, bool secret, bool locked, bool notRecommended, int32_t maxCharactersPerAccount, int32_t onlinePlayerLimit, int32_t onlineFreeTrialLimit, bool freeTrialCanCreateChar, int32_t onlineTutorialLimit);
|
||||
void onClusterRegistered (uint32 clusterId, const std::string &clusterName);
|
||||
void validateAccount (const StationId& stationId, uint32 clusterId, uint32 subscriptionBits, bool canCreateRegular, bool canCreateJedi, bool canSkipTutorial, unsigned int track, std::vector<std::pair<NetworkId, std::string> > const & consumedRewardEvents, std::vector<std::pair<NetworkId, std::string> > const & claimedRewardItems);
|
||||
void validateAccount (const StationId& stationId, uint32 clusterId, uint32 subscriptionBits, bool canCreateRegular, bool canCreateJedi, bool canSkipTutorial, uint32 track, std::vector<std::pair<NetworkId, std::string> > const & consumedRewardEvents, std::vector<std::pair<NetworkId, std::string> > const & claimedRewardItems);
|
||||
void validateAccountForTransfer(const TransferRequestMoveValidation & request, uint32 clusterId, uint32 sourceCharacterTemplateId, bool canCreateRegular, bool canCreateJedi);
|
||||
void sendToCluster (uint32 clusterId, const GameNetworkMessage &message);
|
||||
void sendToAllClusters (GameNetworkMessage const & message, Connection const * excludeCentralConnection = nullptr, uint32 excludeClusterId = 0, char const * excludeClusterName = nullptr);
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
void performAccountTransfer (const AvatarList &avatars, TransferAccountData * transferAccountData);
|
||||
void setDone (const bool isDone);
|
||||
|
||||
void setClusterInfoByName( const std::string &name, const std::string &branch, int changelist, const std::string &networkVersion );
|
||||
void setClusterInfoByName( const std::string &name, const std::string &branch, int32_t changelist, const std::string &networkVersion );
|
||||
void sendExtendedClusterInfo( ClientConnection &client ) const;
|
||||
|
||||
void getAllClusterNamesAndIDs( std::map< std::string, uint32 > &results ) const;
|
||||
@@ -82,9 +82,9 @@ public:
|
||||
std::string clientServiceAddress;
|
||||
uint16 clientServicePortPrivate;
|
||||
uint16 clientServicePortPublic;
|
||||
int id;
|
||||
int32_t id;
|
||||
uint16 pingPort;
|
||||
int numClients;
|
||||
int32_t numClients;
|
||||
|
||||
bool operator==(const ConnectionServerEntry &rhs) const;
|
||||
};
|
||||
@@ -107,16 +107,16 @@ private:
|
||||
std::string m_clusterName;
|
||||
CentralServerConnection * m_centralServerConnection;
|
||||
std::vector<ConnectionServerEntry> m_connectionServers;
|
||||
int m_numPlayers;
|
||||
int m_numFreeTrialPlayers;
|
||||
int m_numTutorialPlayers;
|
||||
int m_maxCharacters;
|
||||
int m_maxCharactersPerAccount;
|
||||
int m_onlinePlayerLimit;
|
||||
int m_onlineFreeTrialLimit;
|
||||
int m_onlineTutorialLimit;
|
||||
int32_t m_numPlayers;
|
||||
int32_t m_numFreeTrialPlayers;
|
||||
int32_t m_numTutorialPlayers;
|
||||
int32_t m_maxCharacters;
|
||||
int32_t m_maxCharactersPerAccount;
|
||||
int32_t m_onlinePlayerLimit;
|
||||
int32_t m_onlineFreeTrialLimit;
|
||||
int32_t m_onlineTutorialLimit;
|
||||
bool m_freeTrialCanCreateChar;
|
||||
int m_timeZone;
|
||||
int32_t m_timeZone;
|
||||
bool m_connected;
|
||||
std::string m_address;
|
||||
uint16 m_port;
|
||||
@@ -127,7 +127,7 @@ private:
|
||||
bool m_notRecommendedDatabase;
|
||||
bool m_notRecommendedCentral;
|
||||
std::string m_branch;
|
||||
int m_changelist;
|
||||
int32_t m_changelist;
|
||||
std::string m_networkVersion;
|
||||
|
||||
ClusterListEntry ();
|
||||
@@ -136,7 +136,7 @@ private:
|
||||
};
|
||||
|
||||
typedef std::vector<ClusterListEntry*> ClusterListType;
|
||||
typedef std::map<int, ClientConnection *> ActiveClientsType;
|
||||
typedef std::map<int32_t, ClientConnection *> ActiveClientsType;
|
||||
|
||||
private:
|
||||
void installSessionValidation();
|
||||
|
||||
@@ -28,20 +28,20 @@ protected:
|
||||
virtual void Init() =0;
|
||||
virtual void HashBlock(const T *input) =0;
|
||||
|
||||
unsigned int blockSize;
|
||||
uint32_t blockSize;
|
||||
word32 countLo, countHi; // 64-bit bit count
|
||||
SecBlock<T> data; // Data buffer
|
||||
SecBlock<T> digest; // Message digest
|
||||
};
|
||||
|
||||
template <class T>
|
||||
IteratedHashBase<T>::IteratedHashBase(unsigned int blockSize, unsigned int digestSize)
|
||||
IteratedHashBase<T>::IteratedHashBase(uint32_t blockSize, uint32_t digestSize)
|
||||
: blockSize(blockSize), countLo(0), countHi(0)
|
||||
, data(blockSize/sizeof(T)), digest(digestSize/sizeof(T))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T> void IteratedHashBase<T>::Update(const byte *input, unsigned int len)
|
||||
template <class T> void IteratedHashBase<T>::Update(const byte *input, uint32_t len)
|
||||
{
|
||||
HashWordType tmp = countLo;
|
||||
if ((countLo = tmp + ((word32)len << 3)) < tmp)
|
||||
@@ -54,7 +54,7 @@ template <class T> void IteratedHashBase<T>::Update(const byte *input, unsigned
|
||||
}
|
||||
|
||||
assert((blockSize & (blockSize-1)) == 0); // blockSize is a power of 2
|
||||
unsigned int num = (unsigned int)(tmp >> 3) & (blockSize-1);
|
||||
uint32_t num = (uint32_t)(tmp >> 3) & (blockSize-1);
|
||||
|
||||
if (num != 0)
|
||||
{
|
||||
@@ -80,7 +80,7 @@ template <class T> void IteratedHashBase<T>::Update(const byte *input, unsigned
|
||||
{
|
||||
if (IsAligned<T>(input))
|
||||
{
|
||||
unsigned int leftOver = HashMultipleBlocks((T *)input, len);
|
||||
uint32_t leftOver = HashMultipleBlocks((T *)input, len);
|
||||
input += (len - leftOver);
|
||||
len = leftOver;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ template <class T> void IteratedHashBase<T>::Update(const byte *input, unsigned
|
||||
memcpy(data, input, len);
|
||||
}
|
||||
|
||||
template <class T> unsigned int IteratedHashBase<T>::HashMultipleBlocks(const T *input, unsigned int length)
|
||||
template <class T> uint32_t IteratedHashBase<T>::HashMultipleBlocks(const T *input, uint32_t length)
|
||||
{
|
||||
do
|
||||
{
|
||||
@@ -109,9 +109,9 @@ template <class T> unsigned int IteratedHashBase<T>::HashMultipleBlocks(const T
|
||||
return length;
|
||||
}
|
||||
|
||||
template <class T> void IteratedHashBase<T>::PadLastBlock(unsigned int lastBlockSize, byte padFirst)
|
||||
template <class T> void IteratedHashBase<T>::PadLastBlock(uint32_t lastBlockSize, byte padFirst)
|
||||
{
|
||||
unsigned int num = (unsigned int)(countLo >> 3) & (blockSize-1);
|
||||
uint32_t num = (uint32_t)(countLo >> 3) & (blockSize-1);
|
||||
assert(num < blockSize);
|
||||
((byte *)data.ptr)[num++]=padFirst;
|
||||
if (num <= lastBlockSize)
|
||||
@@ -135,16 +135,16 @@ template <class T> void IteratedHashBase<T>::Init() {}
|
||||
template <class T> void IteratedHashBase<T>::HashBlock(const T *input) {}
|
||||
|
||||
//! .
|
||||
template <class T, bool H, unsigned int S>
|
||||
template <class T, bool H, uint32_t S>
|
||||
class IteratedHash : public IteratedHashBase<T>
|
||||
{
|
||||
public:
|
||||
typedef T HashWordType;
|
||||
enum {HIGHFIRST = H, BLOCKSIZE = S};
|
||||
|
||||
IteratedHash(unsigned int digestSize) : IteratedHashBase<T>(BLOCKSIZE, digestSize) {}
|
||||
IteratedHash(uint32_t digestSize) : IteratedHashBase<T>(BLOCKSIZE, digestSize) {}
|
||||
|
||||
inline static void CorrectEndianess(HashWordType *out, const HashWordType *in, unsigned int byteCount)
|
||||
inline static void CorrectEndianess(HashWordType *out, const HashWordType *in, uint32_t byteCount)
|
||||
{
|
||||
if (!CheckEndianess(HIGHFIRST))
|
||||
byteReverse(out, in, byteCount);
|
||||
@@ -174,7 +174,7 @@ protected:
|
||||
vTransform(input);
|
||||
else
|
||||
{
|
||||
byteReverse(this->data.ptr, input, (unsigned int)BLOCKSIZE);
|
||||
byteReverse(this->data.ptr, input, (uint32_t)BLOCKSIZE);
|
||||
vTransform(this->data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ NAMESPACE_BEGIN(CryptoPP)
|
||||
// this one may be faster on a Pentium
|
||||
// #define GETBYTE(x, y) (((byte *)&(x))[y])
|
||||
|
||||
unsigned int Parity(unsigned long);
|
||||
unsigned int BytePrecision(unsigned long);
|
||||
unsigned int BitPrecision(unsigned long);
|
||||
uint32_t Parity(unsigned long);
|
||||
uint32_t BytePrecision(unsigned long);
|
||||
uint32_t BitPrecision(unsigned long);
|
||||
unsigned long Crop(unsigned long, uint32_t size);
|
||||
|
||||
inline uint32_t bitsToBytes(uint32_t bitCount)
|
||||
@@ -474,7 +474,7 @@ class FixedKeyLength
|
||||
public:
|
||||
enum {KEYLENGTH=N, MIN_KEYLENGTH=N, MAX_KEYLENGTH=N, DEFAULT_KEYLENGTH=N};
|
||||
/// returns the key length
|
||||
static unsigned int KeyLength(uint32_t) {return KEYLENGTH;}
|
||||
static uint32_t KeyLength(uint32_t) {return KEYLENGTH;}
|
||||
};
|
||||
|
||||
/// support query of variable key length, template parameters are default, min, max, multiple (default multiple 1)
|
||||
@@ -570,7 +570,7 @@ template <class T> struct SecBlock
|
||||
T* End()
|
||||
{return ptr+size;}
|
||||
|
||||
unsigned int Size() const {return size;}
|
||||
uint32_t Size() const {return size;}
|
||||
|
||||
void Assign(const T *t, uint32_t len)
|
||||
{
|
||||
|
||||
@@ -10,9 +10,9 @@ NAMESPACE_BEGIN(CryptoPP)
|
||||
// over GF(256)
|
||||
static inline unsigned int Mod(unsigned int c)
|
||||
{
|
||||
static const unsigned int modulus = 0x14d;
|
||||
unsigned int c2 = (c<<1) ^ ((c & 0x80) ? modulus : 0);
|
||||
unsigned int c1 = c2 ^ (c>>1) ^ ((c & 1) ? (modulus>>1) : 0);
|
||||
static const uint32_t modulus = 0x14d;
|
||||
uint32_t c2 = (c<<1) ^ ((c & 0x80) ? modulus : 0);
|
||||
uint32_t c1 = c2 ^ (c>>1) ^ ((c & 1) ? (modulus>>1) : 0);
|
||||
return c | (c1 << 8) | (c2 << 16) | (c1 << 24);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ static inline unsigned int Mod(unsigned int c)
|
||||
// this is equivalent to multiplying by the RS matrix
|
||||
static word32 ReedSolomon(word32 high, word32 low)
|
||||
{
|
||||
for (unsigned int i=0; i<8; i++)
|
||||
for (uint32_t i=0; i<8; i++)
|
||||
{
|
||||
high = Mod(high>>24) ^ (high<<8) ^ (low>>24);
|
||||
low <<= 8;
|
||||
@@ -28,7 +28,7 @@ static word32 ReedSolomon(word32 high, word32 low)
|
||||
return high;
|
||||
}
|
||||
|
||||
inline word32 Twofish::h0(word32 x, const word32 *key, unsigned int kLen)
|
||||
inline word32 Twofish::h0(word32 x, const word32 *key, uint32_t kLen)
|
||||
{
|
||||
x = x | (x<<8) | (x<<16) | (x<<24);
|
||||
switch(kLen)
|
||||
@@ -42,22 +42,22 @@ inline word32 Twofish::h0(word32 x, const word32 *key, unsigned int kLen)
|
||||
return x;
|
||||
}
|
||||
|
||||
inline word32 Twofish::h(word32 x, const word32 *key, unsigned int kLen)
|
||||
inline word32 Twofish::h(word32 x, const word32 *key, uint32_t kLen)
|
||||
{
|
||||
x = h0(x, key, kLen);
|
||||
return mds[0][GETBYTE(x,0)] ^ mds[1][GETBYTE(x,1)] ^ mds[2][GETBYTE(x,2)] ^ mds[3][GETBYTE(x,3)];
|
||||
}
|
||||
|
||||
Twofish::Twofish(const byte *userKey, unsigned int keylength)
|
||||
Twofish::Twofish(const byte *userKey, uint32_t keylength)
|
||||
: m_k(40), m_s(4)
|
||||
{
|
||||
assert(keylength == KeyLength(keylength));
|
||||
|
||||
unsigned int len = (keylength <= 16 ? 2 : (keylength <= 24 ? 3 : 4));
|
||||
uint32_t len = (keylength <= 16 ? 2 : (keylength <= 24 ? 3 : 4));
|
||||
SecBlock<word32> key(len*2);
|
||||
GetUserKeyLittleEndian(key.ptr, len*2, userKey, keylength);
|
||||
|
||||
unsigned int i;
|
||||
uint32_t i;
|
||||
for (i=0; i<40; i+=2)
|
||||
{
|
||||
word32 a = h(i, key, len);
|
||||
|
||||
@@ -13,9 +13,9 @@ NAMESPACE_BEGIN(CryptoPP)
|
||||
class Twofish : public FixedBlockSize<16>, public VariableKeyLength<16, 0, 32>
|
||||
{
|
||||
protected:
|
||||
Twofish(const byte *userKey, unsigned int keylength);
|
||||
static word32 h0(word32 x, const word32 *key, unsigned int kLen);
|
||||
static word32 h(word32 x, const word32 *key, unsigned int kLen);
|
||||
Twofish(const byte *userKey, uint32_t keylength);
|
||||
static word32 h0(word32 x, const word32 *key, uint32_t kLen);
|
||||
static word32 h(word32 x, const word32 *key, uint32_t kLen);
|
||||
|
||||
static const byte q[2][256];
|
||||
static const word32 mds[4][256];
|
||||
@@ -28,7 +28,7 @@ protected:
|
||||
class TwofishEncryption : public Twofish
|
||||
{
|
||||
public:
|
||||
TwofishEncryption(const byte *userKey, unsigned int keylength=DEFAULT_KEYLENGTH)
|
||||
TwofishEncryption(const byte *userKey, uint32_t keylength=DEFAULT_KEYLENGTH)
|
||||
: Twofish(userKey, keylength) {}
|
||||
|
||||
void ProcessBlock(const byte *inBlock, byte * outBlock) const;
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
class TwofishDecryption : public Twofish
|
||||
{
|
||||
public:
|
||||
TwofishDecryption(const byte *userKey, unsigned int keylength=DEFAULT_KEYLENGTH)
|
||||
TwofishDecryption(const byte *userKey, uint32_t keylength=DEFAULT_KEYLENGTH)
|
||||
: Twofish(userKey, keylength) {}
|
||||
|
||||
void ProcessBlock(const byte *inBlock, byte * outBlock) const;
|
||||
|
||||
Reference in New Issue
Block a user