rodecomp/Source/Utility/Rijndael.h
ragnarok-clanker a47d20f8be Reconstruct readable C++ and organize cohesive source subsystems
Administrative source import: native x86 compilation passed for 423 authored units. Source placement and submission states are migrated separately; this commit does not imply peer acceptance.

Previous head: 35d2a8cb36
Payload SHA256: 592f016d2730c5593bb653aa054c1e5f76a6df72c8f5a09e66f74876e2e33dee
2026-10-25 07:42:41 +00:00

83 lines
2.2 KiB
C++

#ifndef RAGNAROK_SOURCE_UTILITY_RIJNDAEL_H
#define RAGNAROK_SOURCE_UTILITY_RIJNDAEL_H
#include <cstddef>
#include <cstdint>
class CRijndael {
public:
enum { ECB = 0, CBC = 1, CFB = 2 };
enum { DEFAULT_BLOCK_SIZE = 16 };
enum { MAX_BLOCK_SIZE = 32, MAX_ROUNDS = 14, MAX_KC = 8, MAX_BC = 8 };
CRijndael();
virtual ~CRijndael();
void MakeKey(const char* key, const char* chain, int keyLength = DEFAULT_BLOCK_SIZE, int blockSize = DEFAULT_BLOCK_SIZE);
void EncryptBlock(const char* in, char* result);
void DecryptBlock(const char* in, char* result);
void DefEncryptBlock(const char* in, char* result);
void DefDecryptBlock(const char* in, char* result);
void Xor(unsigned char* destination, const unsigned char* source);
inline int GetKeyLength() const {
return this->m_keylength;
}
inline int GetBlockSize() const {
return this->m_blockSize;
}
inline int GetRounds() const {
return this->m_iROUNDS;
}
inline void ResetChain() {
for (int i = 0; i < this->m_blockSize; ++i) {
this->m_chain[i] = this->m_chain0[i];
}
}
static const char* 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];
/* 0004 */ bool m_bKeyInit;
/* 0008 */ int m_Ke[MAX_ROUNDS + 1][MAX_BC];
/* 01E8 */ int m_Kd[MAX_ROUNDS + 1][MAX_BC];
/* 03C8 */ int m_keylength;
/* 03CC */ int m_blockSize;
/* 03D0 */ int m_iROUNDS;
/* 03D4 */ char m_chain0[MAX_BLOCK_SIZE];
/* 03F4 */ char m_chain[MAX_BLOCK_SIZE];
/* 0414 */ int tk[MAX_KC];
/* 0434 */ int a[MAX_BC];
/* 0454 */ int t[MAX_BC];
};
#if defined(_WIN32) && !defined(_WIN64)
static_assert(sizeof(CRijndael) == 0x474);
#endif
#endif