feat: port GIP protocol and auth stack
Port the GIP protocol and authentication layers from medusalix/xone into the C++ stack: - crypto: SHA-256/HMAC (CommonCrypto), RSA PKCS#1 (Security.framework), and a self-contained P-256 ECDH validated against OpenSSL vectors - auth: v1 (RSA) and v2 (ECDH) handshake state machine - gip: header/varint/chunk handling and packet dispatch, with the kernel device model replaced by transport + client_listener interfaces Adds test_crypto, test_auth, and test_gip suites. Co-Authored-By: deepseek (deepseek/deepseek-v4-pro-0813): ported crypto, auth, and GIP
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
// ==============================================================================
|
||||
// Minimal printf-style logger
|
||||
// ==============================================================================
|
||||
// Replaces the kernel's dev_dbg/dev_err from medusalix/xone. Writes to
|
||||
// stderr; the Swift app layer can redirect or swallow it later.
|
||||
// ==============================================================================
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
|
||||
namespace xone {
|
||||
|
||||
enum class log_level {
|
||||
debug = 0,
|
||||
info,
|
||||
warn,
|
||||
error,
|
||||
};
|
||||
|
||||
inline auto log_msg(log_level level, char const* fmt, ...) -> void
|
||||
{
|
||||
char const* tag = "?";
|
||||
switch (level) {
|
||||
case log_level::debug:
|
||||
tag = "debug";
|
||||
break;
|
||||
case log_level::info:
|
||||
tag = "info";
|
||||
break;
|
||||
case log_level::warn:
|
||||
tag = "warn";
|
||||
break;
|
||||
case log_level::error:
|
||||
tag = "error";
|
||||
break;
|
||||
}
|
||||
|
||||
std::fprintf(stderr, "[%s] ", tag);
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
std::vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
std::fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
} // namespace xone
|
||||
@@ -10,6 +10,11 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Mark a struct as packed (no padding), matching the wire formats of the
|
||||
// MT76 chip and the GIP protocol. clang-specific, like the rest of this
|
||||
// macOS-only project.
|
||||
#define XONE_PACKED __attribute__((packed))
|
||||
|
||||
namespace xone {
|
||||
|
||||
// 128-bit GUID used by the GIP protocol (port of the kernel guid_t).
|
||||
@@ -46,4 +51,18 @@ inline auto store_le32(void *p, std::uint32_t v) -> void
|
||||
b[3] = static_cast<std::uint8_t>((v >> 24) & 0xFF);
|
||||
}
|
||||
|
||||
// Big-endian 16-bit load/store (used by the auth handshake headers).
|
||||
inline auto load_be16(void const *p) -> std::uint16_t
|
||||
{
|
||||
auto const *b = static_cast<std::uint8_t const *>(p);
|
||||
return static_cast<std::uint16_t>((b[0] << 8) | b[1]);
|
||||
}
|
||||
|
||||
inline auto store_be16(void *p, std::uint16_t v) -> void
|
||||
{
|
||||
auto *b = static_cast<std::uint8_t *>(p);
|
||||
b[0] = static_cast<std::uint8_t>((v >> 8) & 0xFF);
|
||||
b[1] = static_cast<std::uint8_t>(v & 0xFF);
|
||||
}
|
||||
|
||||
} // namespace xone
|
||||
|
||||
Reference in New Issue
Block a user