Files
mtgodot-poc/extension/tests/classic/classic_cipher.h
T
shenleiandClaude Opus 5.5 f970f95800 cleanup: drop Godot-era build trees, m2dev net/pack layers and stale docs
- Untrack build-debug/ and build-asan/ (CMake trees committed by mistake in
  c9389431) and ignore them.
- Remove extension/src/net and extension/src/pack (m2dev protocol and XChaCha
  pack format, superseded by the ported 40250 code), their 18 unregistered tests
  and the net/pack tools, the MT_BUILD_NET_TOOLS probe, and the libsodium and zstd
  submodules they alone used.
- The fake login server's classic cipher, sequence table and wire layouts move to
  extension/tests/classic/ (still used by port.login_flow, port.packet and the
  native client's offline mode).
- Archive Godot/m2dev-era plans under docs/archive/; THIRD-PARTY.md updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 18:17:25 +09:00

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