Compare commits

...

4 Commits

Author SHA1 Message Date
Devin AI
74e27b1c92 docs: nwc attempts
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-30 23:04:55 +00:00
Devin AI
c4e828f030 nwc24 MsgCommit: LoopBackEnable[2], explicit-NUL literal
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-30 23:04:55 +00:00
Devin AI
0093feb646 aes: split ENCRYPT/DECRYPT key-xor; hmac: reorder function decl
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-30 23:04:55 +00:00
Devin AI
5def4ba8ec flip neterrorcode + sha1 to Matching
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-30 23:04:55 +00:00
5 changed files with 31 additions and 19 deletions

View File

@@ -1044,9 +1044,9 @@ config.libs = [
Object(Matching, "net/nettime.c"),
Object(Matching, "net/crc.c"),
Object(NonMatching, "net/md5.c"),
Object(NonMatching, "net/sha1.c"),
Object(Matching, "net/sha1.c"),
Object(NonMatching, "net/hmac.c"),
Object(NonMatching, "net/neterrorcode.c"),
Object(Matching, "net/neterrorcode.c"),
Object(Matching, "net/NETVersion.c"),
Object(NonMatching, "net/aes.c"),
Object(Matching, "net/wireless_macaddr.c"),

View File

@@ -180,11 +180,11 @@ void AESiEncryptBlock(AESContext* context, u32* output, const u32* input) {
const u32* key = context->keys + 4;
u32 a=input[0]^context->keys[0], b=input[1]^context->keys[1], c=input[2]^context->keys[2], d=input[3]^context->keys[3];
while (--rounds != 0) {
u32 nextA=ENCRYPT(a,b,c,d)^key[0];
u32 nextB=ENCRYPT(b,c,d,a)^key[1];
u32 nextC=ENCRYPT(c,d,a,b)^key[2];
u32 nextD=ENCRYPT(d,a,b,c)^key[3];
a=nextA; b=nextB; c=nextC; d=nextD;
u32 nextA=ENCRYPT(a,b,c,d);
u32 nextB=ENCRYPT(b,c,d,a);
u32 nextC=ENCRYPT(c,d,a,b);
u32 nextD=ENCRYPT(d,a,b,c);
a=nextA^key[0]; b=nextB^key[1]; c=nextC^key[2]; d=nextD^key[3];
key += 4;
}
output[0] = SUBSTITUTE(AESiSubShiftTable,a,b,c,d)^key[0];
@@ -203,15 +203,16 @@ void AESiDecryptBlock(AESContext* context, u32* output, const u32* input) {
u32 round;
for (round=1; round<context->rounds; ++round) {
u32 word;
u32* keys=context->keys + round*4;
for (word=0; word<4; ++word) {
u32 value=context->keys[round*4+word];
u32 value=keys[word];
u32 twice=DOUBLE_BYTES(value);
u32 four=DOUBLE_BYTES(twice);
u32 eight=DOUBLE_BYTES(four)^value;
u32 mixed=eight ^ (four ^ ROTATE(eight,8));
mixed ^= twice ^ ROTATE(mixed,8);
mixed ^= value ^ ROTATE(mixed,8);
context->keys[round*4+word]=mixed;
keys[word]=mixed;
}
}
context->needsTransform=0;
@@ -219,11 +220,11 @@ void AESiDecryptBlock(AESContext* context, u32* output, const u32* input) {
a=input[0]^key[0]; b=input[1]^key[1]; c=input[2]^key[2]; d=input[3]^key[3];
key-=4;
while (--rounds != 0) {
u32 nextA=DECRYPT(a,d,c,b)^key[0];
u32 nextB=DECRYPT(b,a,d,c)^key[1];
u32 nextC=DECRYPT(c,b,a,d)^key[2];
u32 nextD=DECRYPT(d,c,b,a)^key[3];
a=nextA; b=nextB; c=nextC; d=nextD;
u32 nextA=DECRYPT(a,d,c,b);
u32 nextB=DECRYPT(b,a,d,c);
u32 nextC=DECRYPT(c,b,a,d);
u32 nextD=DECRYPT(d,c,b,a);
a=nextA^key[0]; b=nextB^key[1]; c=nextC^key[2]; d=nextD^key[3];
key-=4;
}
output[0]=SUBSTITUTE_XOR(AESiInvSubShiftTable,a,d,c,b)^key[0];

View File

@@ -20,11 +20,11 @@ typedef struct HMACContext {
} HMACContext;
void NETHMACInit(HMACContext* context, const DigestInterface* interface, const void* key, u32 length) {
const char* function = "NETHMACInit";
u8 innerKey[64];
u32 i;
u32 keyLength;
void* work = context->digestContext;
const char* function = "NETHMACInit";
context->interface = *interface;
if (context->interface.contextSize > 96 || context->interface.blockSize > 64) {
OSReport("%s(%d):[warning in %s]", "hmac.c", 100, function);

View File

@@ -4,7 +4,7 @@
#include <revolution/nwc24.h>
static char MultiPartDivider[64];
BOOL LoopBackEnable = TRUE;
BOOL LoopBackEnable[2] = {TRUE, FALSE};
static NWC24File* m_pFile;
static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType type);
@@ -177,7 +177,7 @@ NWC24Err NWC24CommitMsg(NWC24MsgObj* object) {
return NWC24_ERR_LIB_NOT_OPENED;
if (!(msg->type & 0x100) || (msg->type & 0x200))
return NWC24_ERR_PROTECTED;
if (LoopBackEnable && (msg->type & 1)) {
if (LoopBackEnable[0] && (msg->type & 1)) {
NWC24GetMyUserId(&myId);
if (msg->numTo == 1 && msg->toIds[0] == myId)
loopback = TRUE;
@@ -327,7 +327,7 @@ static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType ty
buffer = NWC24WorkP->stringWork;
Mail_memset(buffer, 0, 1024);
Mail_sprintf(buffer, "\r\n--%s", MultiPartDivider);
Mail_strcat(buffer, "\r\n");
Mail_strcat(buffer, "\r\n\0");
CHECK_WRITE(WriteString(msg, buffer));
}
CHECK_WRITE(WriteContentTypeField(msg));
@@ -346,7 +346,7 @@ static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType ty
buffer = NWC24WorkP->stringWork;
Mail_memset(buffer, 0, 1024);
Mail_sprintf(buffer, "\r\n--%s", MultiPartDivider);
Mail_strcat(buffer, "\r\n");
Mail_strcat(buffer, "\r\n\0");
CHECK_WRITE(WriteString(msg, buffer));
CHECK_WRITE(WriteMIMEAttachHeader(msg, index));
attached[index].ptr = (const void*)msg->length;

View File

@@ -0,0 +1,11 @@
## NWC24MsgCommit data decode (2026-09-28)
- Orig's 8B {1,0} .sdata object = `BOOL LoopBackEnable[2] = {TRUE,FALSE}` + `[0]` use-site (SDA reloc same as scalar).
- Orig's second "\r\n" literal @.sdata+0x24 (literal-use position between "\r\n--%s" and "--\r\n") = explicit-NUL literal `"\r\n\0"` — emits a distinct 4B literal MWCC won't dedup with the plain "\r\n". Named `static char crlf[]` can't reproduce it: named objects emit before pooled literals (lands at 0x8). Compound literals unsupported by this MWCC build. After this, .sdata/.data/.sbss/.bss all byte-identical modulo extraction end-pads.
## MWCC literal dedup / load-CSE notes
- SelectMBox reload tie (NWC24MsgRead, 4 fns, -4B each): orig emits `lwz r0,4(priv)` for the `&0x200` test then RE-LOADS `lwz r3,4(priv)` inside inlined SelectMBox. MWCC always CSEs the two `->type` loads to one register; tried `data[1]` lvalue, public-param+inside-cast, cast-callsite, inside-cast combos — all fold. Same class as pf_stub `message->operation` re-read.
- CheckMsgBoxSpace (223/223): identical insn stream, 45 scheduling diffs on the div-by-10 mulhwu chain + reg-home cascade (orig dateFlags->r23/buffer->r24 vs swapped).
- NWC24CommitMsgInternal/WriteMIMEAttachHeader: ndiff-0, residual fuzzy from one r23<->r24 home swap at ~0x770 (cascade from earlier live range).
- NWC24MsgSubject fns: reg-name/arg-staging diffs only; ReadMsgSubjectPublic missing `mr r8,r26` staging; iSetMsgSubjectBase64 +12 same-stream.
- ConvertDaysToDate: 57 regname diffs + one extra tail block (`*month++` + b) vs orig's fall-through return.