Compare commits

...

1 Commits

Author SHA1 Message Date
coah
939902f0be fix(aoss): restore WLAN arguments and complete key bounds 2026-10-02 23:15:58 -05:00
3 changed files with 62 additions and 12 deletions

View File

@@ -167,6 +167,11 @@ typedef struct AOSSKeySchedule {
u32 length;
} AOSSKeySchedule;
typedef struct AOSSKeyMaterial {
u8 nonce[2];
u8 address[8];
} AOSSKeyMaterial;
typedef struct AOSSReceiveBuffer {
s32 socket;
u32 length;
@@ -257,8 +262,7 @@ static AOSSRuntimeState s_runtime;
static AOSSConfigData s_configData;
static u8 s_networkBuffer[0x280];
static struct {
u8 keyNonce[2];
u8 keyAddress[8];
AOSSKeyMaterial key;
u8 payload[0x5e];
} s_packetState;
static u32 s_crcTable[0x100];
@@ -284,7 +288,9 @@ extern int AOSSi_WLANGetBSSList(void** list);
extern int AOSSi_Status(int status);
extern int AOSSi_SetNCDIPAddr(u32 ipAddress, u32 netmask, u32 gateway, u32 dns1, u32 dns2);
extern int AOSSi_Sleep(u32 duration);
extern int AOSSi_WLANConnect(void);
struct AOSSConnection;
struct AOSSConnectionStatus;
extern int AOSSi_WLANConnect(struct AOSSConnection* connection, struct AOSSConnectionStatus* status);
extern int SOPoll(AOSSPollDescriptor* descriptors, int count, s32 timeoutHigh, s32 timeoutLow);
extern int SORecvFrom(int socket, void* buffer, int length, int flags, void* address);
extern int SOSendTo(int socket, const void* buffer, int length, int flags, const void* address);
@@ -1900,10 +1906,9 @@ int AOSSDecryptMessage(AOSSDecryptionMessage* message) {
s_errorCode = 2;
result = -1;
} else {
memcpy(s_packetState.keyNonce, &encrypted->keyNonce, sizeof(encrypted->keyNonce));
memcpy(s_packetState.keyAddress, s_accessPointName, sizeof(s_accessPointName));
AOSSInitKeySchedule(&schedule, s_packetState.keyNonce,
sizeof(s_packetState.keyNonce) + sizeof(s_packetState.keyAddress), dataLength);
memcpy(s_packetState.key.nonce, &encrypted->keyNonce, sizeof(encrypted->keyNonce));
memcpy(s_packetState.key.address, s_accessPointName, sizeof(s_accessPointName));
AOSSInitKeySchedule(&schedule, (const u8*)&s_packetState.key, sizeof(s_packetState.key), dataLength);
outputCursor = decryptedData;
inputCursor = encrypted->data;
@@ -2375,10 +2380,9 @@ int AOSSSendHelloRequest(void* packet, void* request, int socket) {
if (construction.schedule.bytes != 0) {
nonce = (u16)rand();
memcpy(&payload->encrypted.key.nonce, &nonce, 2);
memcpy(s_packetState.keyNonce, payload->encrypted.key.nonceBytes, 2);
memcpy(s_packetState.keyAddress, s_accessPointName, 8);
AOSSInitKeySchedule(&construction.schedule, s_packetState.keyNonce,
sizeof(s_packetState.keyNonce) + sizeof(s_packetState.keyAddress), 8);
memcpy(s_packetState.key.nonce, payload->encrypted.key.nonceBytes, 2);
memcpy(s_packetState.key.address, s_accessPointName, 8);
AOSSInitKeySchedule(&construction.schedule, (const u8*)&s_packetState.key, sizeof(s_packetState.key), 8);
for (index = 0; index < 8; index++) {
state = construction.schedule.bytes;
firstIndex = (construction.schedule.i + 1) % construction.schedule.length & 0xff;
@@ -2562,7 +2566,7 @@ int AOSSConnectAndAwaitHost(void* settings, void* config) {
s32 connectionAttempts = 0;
u32 ticksPerMillisecond;
if (AOSSi_WLANConnect() != 0) {
if (AOSSi_WLANConnect(settings, config) != 0) {
return -1;
}

View File

@@ -0,0 +1,20 @@
# AOSS WLAN connection argument contract
Base 9c7d87ab, 43U. This correction is separate from the key-material representation work.
AOSSConnectAndAwaitHost receives settings and config pointers but previously called AOSSi_WLANConnect through a false no-argument declaration. The actual callee takes a connection record and status output. In the original caller, incoming r3/r4 are forwarded untouched to the first call; the callee preserves r3/r4 and consumes both. The compiler happened to retain the same register contents despite the missing source arguments, hiding this defect behind exact generated code.
The local declaration now uses forward-declared struct AOSSConnection and struct AOSSConnectionStatus, matching the existing tags in AOSSLink.c. The wrapper explicitly passes settings and config. No shared header or AOSSLink.c edit. All three original outer callsites supply r3 = sp+0xb8 (settings) and r4 = s_accessPointConfig, matching the source caller expressions. No arguments are reordered or synthesized.
Validation:
- Configured/built 43U using the approved wibo wrapper and WIBO_SJIS_MISSING_IMPORTS=1
- AOSSConnectAndAwaitHost remains 60/60 instructions, ctxdiff zero
- Every code/data/relocation section, section header, and symbol record is byte-identical to baseline; only five compiler-generated anonymous local symbol spellings change in .strtab
- Full-project objdiff report unchanged: AOSS unit 97.71665% fuzzy, 16/21 exact, 6436 exact code bytes and 3928/3928 data bytes; no matching gain claimed
- Pool identical, 1/1 strings; literal audit checks 12 arguments across 19 functions, no candidates/errors; AOSS_Init_old and AOSSSendHelloRequest are skipped for their existing unequal sizes
- ASan/UBSan extracted-production wrapper harness passes 30,600 cases, asserting actual typed callee pointer identities, driver/startup failures, host readiness, cancellation, all retry boundaries and the original timeout behavior (cleanup and status clear, then return zero). No network calls occur; platform functions are controlled stubs
- LeakSanitizer disabled for ptrace restriction; address/undefined instrumentation enabled
- Full 43U build and ok gate pass; DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d
- git diff --check passes
Private reproducible evidence: /tmp/aoss-key-call-contracts, with original caller/callee disassembly retained privately under /tmp/aoss-decrypt-audit.

View File

@@ -0,0 +1,26 @@
# AOSS contiguous key-material representation
Base candidate: 00b02c27 (the separate WLAN argument-contract correction). Original branch base: 9c7d87ab. 43U only.
## Evidence and focused change
The original decryptor copies two raw nonce bytes and eight access-point bytes into consecutive positions of s_packetState, then passes that base and length 10 to AOSSInitKeySchedule. The original hello sender builds the same key. The key-schedule helper actually indexes all ten bytes; its instruction stream and resolved calls match the source exactly.
Previously the caller passed keyNonce[2] with length sizeof(keyNonce)+sizeof(keyAddress), relying on indexing beyond the first array member. AOSSKeyMaterial now represents the complete key as named nonce[2] and address[8] members. s_packetState embeds this key object, followed by its unchanged payload[0x5e]. Each schedule call uses a const u8 byte view of the complete key object with sizeof(key), so the byte span belongs to the object being viewed.
Only the two nonce copies, two address copies, and two key-schedule calls in AOSSDecryptMessage/AOSSSendHelloRequest are updated. No other packet representation, algorithm, checksum, byte order, allocation, validation, state transition, header or protocol change. No added storage, alignment, padding or assembly.
## Layout and gates
- Key size 10, nonce offset 0, address offset 2, packet payload offset 10, packet-state size 104, natural byte alignment unchanged
- Entire compiled AOSS.o is byte-identical to 00b02c27, including all payloads, symbol spellings and relocations
- Full-project objdiff unchanged from branch baseline: unit 97.71665% fuzzy, 16/21 exact, 6436 exact code bytes, 3928/3928 data bytes; no matching gain claimed
- DecryptMessage remains 97.74143%, 321/321 instructions and the same 87 allocation/operand differences
- Pool identical, 1/1; literal-reference audit still checks 12 arguments in 19 functions without candidates/errors, with the same two unequal-size skips (AOSS_Init_old and AOSSSendHelloRequest)
- ASan/UBSan extracted-production harness passes 68,423 cases: all 65,536 nonce byte combinations with varied addresses against an independent schedule model; every valid payload length 0..0x5c0; checksum/allocation/manufacturer/control error paths; 1,024 hello sender encryption round trips. It asserts key layout/content, unchanged trailing payload, output copy/checksum order and allocation cleanup. The production decryptor, sender, key scheduling, CRC table and name check execute; manufacturer scrambling and transport are controlled stubs, with no network activity
- The separate 30,600-case WLAN pointer/host-wait validator is rerun and passes
- LeakSanitizer disabled for ptrace restriction; address and undefined-behavior instrumentation enabled
- Full 43U build and ok gate pass; DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d
- git diff --check passes
Private reproducible validators, reports and build logs: /tmp/aoss-key-call-contracts. Original disassembly remains private in /tmp/aoss-decrypt-audit.