Files
mtgodot-poc/extension/src/net/classic/classic_cipher.h
T

53 lines
1.7 KiB
C++

#pragma once
// ClassicCipher — 40250 _IMPROVED_PACKET_ENCRYPTION_ (docs/CLIENT-40250-PORT.md §3).
// Ported near-verbatim from ClientVS22/source/EterBase/cipher.{h,cpp}
// (Themida / stdafx / logging stripped). Needs Crypto++ 8.4.0 (mt3p::cryptopp).
//
// Prepare(buf,&len) -> generate this end's DH2 public blob (spub||epub),
// returns the agreed-value length (0 = failure).
// Activate(polarity, agreed_len, peer_blob, peer_len)
// -> DH2 Agree() -> derive 2 hint-selected block ciphers in
// CTR mode, wire encoder_/decoder_ per polarity.
// **client polarity = true**, server = false.
// Encrypt/Decrypt(buf,len) in place, no padding (CTR stream).
// activated() flips true only after set_activated(true) (on GC_KEY_AGREEMENT_COMPLETED).
#include <cassert>
#include <cstddef>
namespace CryptoPP {
class SymmetricCipher;
}
namespace mtnet::classic {
class KeyAgreement;
class ClassicCipher {
public:
ClassicCipher();
~ClassicCipher();
void clean_up();
size_t prepare(void *buffer, size_t *length);
bool activate(bool polarity, size_t agreed_length, const void *buffer, size_t length);
void encrypt(void *buffer, size_t length);
void decrypt(void *buffer, size_t length);
bool activated() const { return activated_; }
void set_activated(bool value) { activated_ = value; }
bool key_ready() const { return encoder_ != nullptr && decoder_ != nullptr; }
private:
bool set_up(bool polarity);
bool activated_ = false;
CryptoPP::SymmetricCipher *encoder_ = nullptr;
CryptoPP::SymmetricCipher *decoder_ = nullptr;
KeyAgreement *key_agreement_ = nullptr;
};
} // namespace mtnet::classic