JubeatPlus 3.9.11
Loading...
Searching...
No Matches
bfcodeccontext.h
Go to the documentation of this file.
1
15
16#pragma once
17
18#include <cstdint>
19
24public:
33
41 ~BFCodecContext() = default;
42
47 void clear();
48
55 void setKey(const uint8_t *pbKey, int nKeyLength);
56
63 void encipherBlock(uint64_t *pqwLeft, uint64_t *pqwRight) const;
64
71 void decipherBlock(uint64_t *pqwLeft, uint64_t *pqwRight) const;
72
73private:
74 static constexpr int kPEntries = 18; // +0x00, 0x90 bytes
75 static constexpr int kSBoxEntries = 256; // each S-box, 0x800 bytes
76
77 // Each word is a zero-extended 32-bit value in a 64-bit slot, matching the binary's layout.
78 uint64_t m_aqwP[kPEntries] = {}; // +0x0000
79 uint64_t m_aqwS1[kSBoxEntries] = {}; // +0x0090
80 uint64_t m_aqwS2[kSBoxEntries] = {}; // +0x0890
81 uint64_t m_aqwS3[kSBoxEntries] = {}; // +0x1090
82 uint64_t m_aqwS4[kSBoxEntries] = {}; // +0x1890
83
84 // The shipped round function: two S-box sums XORed together, unlike standard Blowfish's
85 // add-xor-add. Shared by the cipher and the key expansion in setKey.
86 uint64_t roundFunction(uint64_t block) const;
87
88 // One forward 16-round pass, updating (left, right) in place. Shared by encipherBlock and the
89 // key expansion in setKey, which chains each output pair back in as the next input.
90 void encipherHalves(uint64_t &left, uint64_t &right) const;
91};
void encipherBlock(uint64_t *pqwLeft, uint64_t *pqwRight) const
Encrypts one 64-bit block in place, as two 32-bit halves.
Definition bfcodeccontext.cpp:260
BFCodecContext()
Constructs a zeroed key schedule.
void decipherBlock(uint64_t *pqwLeft, uint64_t *pqwRight) const
Decrypts one 64-bit block in place, as two 32-bit halves.
Definition bfcodeccontext.cpp:270
~BFCodecContext()=default
Destroys the schedule.
void clear()
Returns the whole schedule to its zero state, so it must be re-keyed before reuse.
Definition bfcodeccontext.cpp:184
void setKey(const uint8_t *pbKey, int nKeyLength)
Expands a key into the schedule.
Definition bfcodeccontext.cpp:204