/* This is the core key expansion, which, given a 4-byte value, * does some scrambling */ static void schedule_core(unsigned char *in, unsigned char i) { char a; /* Rotate the input 8 bits to the left */ rotate(in); /* Apply Rijndael's s-box on all 4 bytes */ for(a = 0; a < 4; a++) in[a] = sbox[in[a]]; /* On just the first byte, add 2^i to the byte */ in[0] ^= rcon(i); }
void expand(const std::array<VAR, KSZ>& key, // 4 * Nk octets std::array<VAR, WSZ>& w) const // 16 * (Nr + 1) octets { const std::size_t Nk = key.size() / 4, Nr = w.size() / 16 - 1; for (std::size_t i = 0; i < Nk; ++i) { w[4*i] = key[4*i]; w[4*i + 1] = key[4*i + 1]; w[4*i + 2] = key[4*i + 2]; w[4*i + 3] = key[4*i + 3]; } for (std::size_t i = Nk; i < 4 * (Nr + 1); ++i) { std::array<VAR, 4> temp = { w[4*(i - 1)], w[4*(i - 1) + 1], w[4*(i - 1) + 2], w[4*(i - 1) + 3] }; if (0 == i % Nk) { const VAR tmp = temp[0]; temp[0] = BITWISE::XOR(m_sbox(temp[1]), BITWISE::constant(rcon(i/Nk - 1))); temp[1] = m_sbox(temp[2]); temp[2] = m_sbox(temp[3]); temp[3] = m_sbox(tmp); } else if (Nk > 6 && 4 == i % Nk) { temp[0] = m_sbox(temp[0]); temp[1] = m_sbox(temp[1]); temp[2] = m_sbox(temp[2]); temp[3] = m_sbox(temp[3]); } w[4*i] = BITWISE::XOR(w[4*(i - Nk)], temp[0]); w[4*i + 1] = BITWISE::XOR(w[4*(i - Nk) + 1], temp[1]); w[4*i + 2] = BITWISE::XOR(w[4*(i - Nk) + 2], temp[2]); w[4*i + 3] = BITWISE::XOR(w[4*(i - Nk) + 3], temp[3]); } }
int main() { std::string data; // RCON Example. #ifdef RCON_EXAMPLE RCON rcon(EXAMPLE_IP, EXAMPLE_PORT, EXAMPLE_PASSWORD); rcon.Send(EXAMPLE_COMMAND); data.assign(rcon.Recv()); std::cout << "RCON response: " << data << "\n"; #endif #ifdef QUERY_EXAMPLE // Query example. Query query(EXAMPLE_IP, EXAMPLE_PORT); std::string pingdata; std::stringstream tostring; tostring << ((rand() % 8999) + 1000); data.assign(query.Ping(tostring.str())); std::cout << "Query response: " << data << "\n"; #endif return 1; }
int main(int ac, char** av) { zhttpd::RCON::Rcon rcon(ac, av); return rcon.run(); }