lacteApp
C++17 service for Lacte hardware
Loading...
Searching...
No Matches
Des.hpp File Reference

Minimal single-block DES ENCRYPTION (no decryption, no chaining mode) - the entire cryptographic primitive RFB's classic "VNC Authentication" security type needs: the server sends a 16-byte random challenge, the client DES-encrypts it (in two independent 8-byte ECB blocks) using the connection password as the key, and the server does the same locally to check the client's answer - see RfbServer.hpp's own file doc comment for the full handshake. More...

#include <algorithm>
#include <array>
#include <cstdint>
#include <string>
Include dependency graph for Des.hpp:

Go to the source code of this file.

Namespaces

namespace  lacte
namespace  lacte::vnc
namespace  lacte::vnc::des
namespace  lacte::vnc::des::detail

Functions

auto lacte::vnc::des::detail::permute (const std::uint64_t src, const int src_bits, const int *table, const int table_len) -> std::uint64_t
 Permutes src (an src_bits-wide value, bit 1 = MSB) through table (each entry a 1-indexed bit position into src), producing a table_len-bit result (also MSB-first).
auto lacte::vnc::des::detail::rotate_left_28 (const std::uint32_t value, const int amount) -> std::uint32_t
auto lacte::vnc::des::detail::compute_round_keys (const std::uint64_t key64, std::array< std::uint64_t, 16 > &round_keys) -> void
 PC1(key) -> C0/D0, then 16 left-rotations (per K_SHIFTS) each followed by PC2 -> one 48-bit round key.
auto lacte::vnc::des::detail::feistel (const std::uint32_t r, const std::uint64_t round_key48) -> std::uint32_t
 The Feistel round function f(R, K): E(R) xor K, split into eight 6-bit groups, each substituted through its own S-box, recombined and permuted through P.
auto lacte::vnc::des::encrypt_block (const std::uint64_t plaintext, const std::uint64_t key64) -> std::uint64_t
 Encrypts one 64-bit block with one 64-bit DES key (parity bits included but unchecked - PC1 drops them exactly as the algorithm always does).
auto lacte::vnc::des::bytes_to_u64 (const std::array< std::uint8_t, 8 > &bytes) -> std::uint64_t
auto lacte::vnc::des::u64_to_bytes (const std::uint64_t value) -> std::array< std::uint8_t, 8 >
auto lacte::vnc::des::detail::reverse_bits (std::uint8_t b) -> std::uint8_t
auto lacte::vnc::des::vnc_encrypt_challenge (const std::array< std::uint8_t, 16 > &challenge, const std::string &password) -> std::array< std::uint8_t, 16 >
 RFB's classic "VNC Authentication" (security type 2) challenge response: the connection password becomes an 8-byte DES key (truncated to 8 bytes / zero-padded if shorter - a real, well-known VNC password length limit, not a bug), with each key BYTE's bits reversed before use.

Variables

constexpr int lacte::vnc::des::detail::K_IP [64]
constexpr int lacte::vnc::des::detail::K_FP [64]
constexpr int lacte::vnc::des::detail::K_E [48]
constexpr int lacte::vnc::des::detail::K_P [32]
constexpr int lacte::vnc::des::detail::K_PC1 [56]
constexpr int lacte::vnc::des::detail::K_PC2 [48]
constexpr int lacte::vnc::des::detail::K_SHIFTS [16]
constexpr int lacte::vnc::des::detail::K_SBOX [8][4][16]

Detailed Description

Minimal single-block DES ENCRYPTION (no decryption, no chaining mode) - the entire cryptographic primitive RFB's classic "VNC Authentication" security type needs: the server sends a 16-byte random challenge, the client DES-encrypts it (in two independent 8-byte ECB blocks) using the connection password as the key, and the server does the same locally to check the client's answer - see RfbServer.hpp's own file doc comment for the full handshake.

Hand-rolled rather than pulled from a crypto library - this project doesn't otherwise depend on OpenSSL/libsodium/etc, and VNC Authentication is DES applied exactly once per 8-byte block with a fixed, well-known bit-reversal quirk on the key (see vnc_encrypt_challenge()'s own doc comment) - not a general-purpose cipher this code needs to be reusable for. The core encrypt_block() is verified against the classic FIPS PUB 46 worked example (see des_test.cpp) independently of the VNC- specific key derivation, so a bug in one is distinguishable from a bug in the other.

All permutation tables below are the standard, publicly-published DES tables (identical across essentially every DES implementation ever written, free of any per-project variation) - bit numbering follows the original FIPS convention: bit 1 is the MOST significant bit of a value, not the least.

Definition in file Des.hpp.