From 8fc38e7ae7b92cd3f34c253abb3e65f39d7835b2 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Mon, 6 Jul 2026 11:53:14 -0700 Subject: [PATCH] move more files to src --- asm/include/main_02003DB8.inc | 4 +- asm/include/main_0207F894.inc | 6 +- asm/include/overlay_00.inc | 14 +- asm/include/overlay_02.inc | 4 +- asm/main_02003DB8.s | 4 +- asm/overlay_00.s | 38 +-- asm/overlay_02.s | 4 +- common.mk | 5 +- lib/NitroSDK/asm/dgt.s | 30 +-- lib/NitroSDK/asm/include/main_0207F894.inc | 6 +- lib/NitroSDK/asm/math_crc.s | 60 ++--- lib/NitroSDK/asm/math_dgt.s | 25 -- lib/NitroSDK/src/{math_math.c => math/math.c} | 0 lib/NitroSDK/src/math/math_crc.c | 250 ++++++++++++++++++ lib/NitroSDK/src/math/math_dgt.c | 19 ++ lib/NitroSDK/src/{ => rtc}/rtc_internal.c | 0 lib/include/nitro/dgt/common.h | 19 ++ lib/include/nitro/dgt/dgt.h | 77 ++++++ lib/include/nitro/math.h | 2 + lib/include/nitro/math/dgt.h | 79 ++++++ main.lsf | 6 +- 21 files changed, 537 insertions(+), 115 deletions(-) delete mode 100644 lib/NitroSDK/asm/math_dgt.s rename lib/NitroSDK/src/{math_math.c => math/math.c} (100%) create mode 100644 lib/NitroSDK/src/math/math_crc.c create mode 100644 lib/NitroSDK/src/math/math_dgt.c rename lib/NitroSDK/src/{ => rtc}/rtc_internal.c (100%) create mode 100644 lib/include/nitro/dgt/common.h create mode 100644 lib/include/nitro/dgt/dgt.h create mode 100644 lib/include/nitro/math/dgt.h diff --git a/asm/include/main_02003DB8.inc b/asm/include/main_02003DB8.inc index a9961f7b..fe912b18 100644 --- a/asm/include/main_02003DB8.inc +++ b/asm/include/main_02003DB8.inc @@ -72,8 +72,8 @@ .public FS_StartOverlay .public LOADED_OVERLAY_GROUP_0 .public FS_LoadOverlayImage -.public Math_CalcCrc32 -.public Mathi_Crc32InitTable +.public MATH_CalcCRC32 +.public MATHi_CRC32InitTable .public MemAlloc .public MemFree .public MemLocateSet diff --git a/asm/include/main_0207F894.inc b/asm/include/main_0207F894.inc index 5f88b5df..d596a379 100644 --- a/asm/include/main_0207F894.inc +++ b/asm/include/main_0207F894.inc @@ -82,9 +82,9 @@ .public DC_StoreRange .public DC_WaitWriteBufferEmpty .public Dgt_Hash2CalcHmac -.public Dgt_Hash2GetHash -.public Dgt_Hash2Init -.public Dgt_Hash2Update +.public DGT_Hash2GetDigest +.public DGT_Hash2Reset +.public DGT_Hash2SetSource .public EnableIrqFlag .public fflush .public FS_CloseFile diff --git a/asm/include/overlay_00.inc b/asm/include/overlay_00.inc index 2b353414..c51748a8 100644 --- a/asm/include/overlay_00.inc +++ b/asm/include/overlay_00.inc @@ -74,15 +74,15 @@ .public InitMenu .public InitWfcSettingsOverlay .public LoadOverlay -.public Math_CalcCrc16 -.public Math_CalcCrc32 -.public Math_CalcCrc8 +.public MATH_CalcCRC16 +.public MATH_CalcCRC32 +.public MATH_CalcCRC8 .public Math_CalcSha1 .public Math_CountPopulation -.public Mathi_Crc16InitTable -.public Mathi_Crc16Update -.public Mathi_Crc32InitTable -.public Mathi_Crc8InitTable +.public MATHi_CRC16InitTable +.public MATHi_CRC16Update +.public MATHi_CRC32InitTable +.public MATHi_CRC8InitTable .public MD5_Digest .public MD5_Init .public MD5_Update diff --git a/asm/include/overlay_02.inc b/asm/include/overlay_02.inc index 5da0792f..6295268b 100644 --- a/asm/include/overlay_02.inc +++ b/asm/include/overlay_02.inc @@ -112,8 +112,8 @@ .public GXS_SetGraphicsMode .public GXx_SetMasterBrightness_ .public InitWfc -.public Math_CalcCrc16 -.public Mathi_Crc16InitTable +.public MATH_CalcCRC16 +.public MATHi_CRC16InitTable .public MB_CommGetChildUser .public MB_CommIsBootable .public MB_CommResponseRequest diff --git a/asm/main_02003DB8.s b/asm/main_02003DB8.s index 79b61118..af2e7fc9 100644 --- a/asm/main_02003DB8.s +++ b/asm/main_02003DB8.s @@ -1300,11 +1300,11 @@ sub_02004F80: ; 0x02004F80 bl MemAlloc ldr r1, _02004FC8 ; =0xEDB88320 mov r5, r0 - bl Mathi_Crc32InitTable + bl MATHi_CRC32InitTable mov r0, r5 mov r1, r6 mov r2, r4 - bl Math_CalcCrc32 + bl MATH_CalcCRC32 mov r4, r0 mov r0, r5 bl MemFree diff --git a/asm/overlay_00.s b/asm/overlay_00.s index c8f9ba2f..f48ec248 100644 --- a/asm/overlay_00.s +++ b/asm/overlay_00.s @@ -36235,14 +36235,14 @@ _022DA63C: add r0, r0, #0x1a00 add r1, r1, #0x1800 add r2, r4, r7 - bl Mathi_Crc16Update + bl MATHi_CRC16Update ldr r0, _022DA86C ; =ov00_02326CA4 add r1, r4, r7 ldr r0, [r0] mov r2, #0x6e add r0, r0, #0x96 add r0, r0, #0x1a00 - bl Math_CalcCrc16 + bl MATH_CalcCRC16 ldr r1, _022DA86C ; =ov00_02326CA4 mov r2, #0x70 ldr r4, [r1] @@ -36364,7 +36364,7 @@ Wds_Initialize: ; 0x022DA884 ldr r0, [r2] add r0, r0, #0x96 add r0, r0, #0x1a00 - bl Mathi_Crc16InitTable + bl MATHi_CRC16InitTable ldr r0, _022DA914 ; =ov00_02326CA4 mov r1, r6 ldr r0, [r0] @@ -37254,11 +37254,11 @@ Dwc_Acc_CreateFriendKey: ; 0x022DB358 _022DB37C: add r0, sp, #0x70 mov r1, #7 - bl Mathi_Crc8InitTable + bl MATHi_CRC8InitTable add r0, sp, #0x70 add r1, sp, #0 mov r2, #8 - bl Math_CalcCrc8 + bl MATH_CalcCRC8 and r0, r0, #0x7f b _022DB3D0 _022DB3A0: @@ -37452,11 +37452,11 @@ Dwci_Acc_CreateUserData: ; 0x022DB5B8 bl Dwci_Acc_SetFlag_DataType ldr r1, _022DB630 ; =0xEDB88320 add r0, sp, #0 - bl Mathi_Crc32InitTable + bl MATHi_CRC32InitTable add r0, sp, #0 mov r1, r5 mov r2, #0x3c - bl Math_CalcCrc32 + bl MATH_CalcCRC32 str r0, [r5, #0x3c] ldr r0, [r5, #0x20] orr r0, r0, #1 @@ -37608,11 +37608,11 @@ Dwc_CheckUserData: ; 0x022DB7BC ldr r1, _022DB7FC ; =0xEDB88320 mov r4, r0 add r0, sp, #0 - bl Mathi_Crc32InitTable + bl MATHi_CRC32InitTable add r0, sp, #0 mov r1, r4 mov r2, #0x3c - bl Math_CalcCrc32 + bl MATH_CalcCRC32 ldr r1, [r4, #0x3c] cmp r0, r1 moveq r0, #1 @@ -37682,11 +37682,11 @@ Dwci_Acc_SetLoginIdToUserData: ; 0x022DB898 ldr r1, _022DB8EC ; =0xEDB88320 add r0, sp, #0 str ip, [r4, #0x1c] - bl Mathi_Crc32InitTable + bl MATHi_CRC32InitTable add r0, sp, #0 mov r1, r4 mov r2, #0x3c - bl Math_CalcCrc32 + bl MATH_CalcCRC32 str r0, [r4, #0x3c] ldr r0, [r4, #0x20] orr r0, r0, #1 @@ -37733,11 +37733,11 @@ Dwci_Acc_ClearDirty: ; 0x022DB920 bic r2, r1, #1 ldr r1, _022DB960 ; =0xEDB88320 str r2, [r4, #0x20] - bl Mathi_Crc32InitTable + bl MATHi_CRC32InitTable add r0, sp, #0 mov r1, r4 mov r2, #0x3c - bl Math_CalcCrc32 + bl MATH_CalcCRC32 str r0, [r4, #0x3c] add sp, sp, #0x400 ldmia sp!, {r4, pc} @@ -58594,7 +58594,7 @@ Dwci_BM_SetWiFiInfo: ; 0x022ED540 bl Dwci_BackuplConvWifiInfo ldr r1, _022ED614 ; =0x0000A001 add r0, sl, #0x200 - bl Mathi_Crc16InitTable + bl MATHi_CRC16InitTable mov r5, #0x100 ldr r6, _022ED618 ; =ov00_023276E0 mov r8, #0 @@ -58619,7 +58619,7 @@ _022ED59C: mov r1, sl mov r2, #0xfe add r0, sl, #0x200 - bl Math_CalcCrc16 + bl MATH_CalcCRC16 strh r0, [sl, #0xfe] _022ED5C0: mov r0, sb @@ -58743,7 +58743,7 @@ _022ED738: mov r1, r7 mov r2, r4 add r0, r8, #0x500 - bl Math_CalcCrc16 + bl MATH_CalcCRC16 add r1, r8, r5, lsl #8 strh r0, [r1, #0xfe] _022ED750: @@ -59426,7 +59426,7 @@ Dwc_BM_Init: ; 0x022EE018 ldmeqia sp!, {r4, r5, r6, r7, r8, sb, sl, pc} ldr r1, _022EE310 ; =0x0000A001 add r0, r8, #0x500 - bl Mathi_Crc16InitTable + bl MATHi_CRC16InitTable mov r0, r8 bl Dwci_BackuplRead cmp r0, #0 @@ -59447,7 +59447,7 @@ _022EE094: mov r1, r6 mov r2, r4 add r0, r8, #0x500 - bl Math_CalcCrc16 + bl MATH_CalcCRC16 add r1, r8, r5, lsl #8 ldrh r1, [r1, #0xfe] cmp r0, r1 @@ -59465,7 +59465,7 @@ _022EE0C4: add r0, r8, #0x500 add r1, r8, #0x300 mov r2, #0xfe - bl Math_CalcCrc16 + bl MATH_CalcCRC16 add r1, r8, #0x300 ldrh r1, [r1, #0xfe] cmp r0, r1 diff --git a/asm/overlay_02.s b/asm/overlay_02.s index 4618f31e..ba68b010 100644 --- a/asm/overlay_02.s +++ b/asm/overlay_02.s @@ -42705,7 +42705,7 @@ Dwci_SettignlInit: ; 0x023474C0 str r0, [r1] ldr r1, _02347500 ; =0x0000A001 add r0, r2, #0x400 - bl Mathi_Crc16InitTable + bl MATHi_CRC16InitTable ldr r0, _023474FC ; =ov02_0235AB48 ldr r0, [r0] bl Dwci_BackuplRead @@ -43525,7 +43525,7 @@ _02347F08: add r0, r1, #0xf8 add r0, r0, #0x400 add r1, r1, r7 - bl Math_CalcCrc16 + bl MATH_CalcCRC16 ldr r1, [r8] add r1, r1, r6, lsl #8 strh r0, [r1, #0xfe] diff --git a/common.mk b/common.mk index 919b3851..566343b8 100644 --- a/common.mk +++ b/common.mk @@ -88,7 +88,7 @@ PRECOMPILE_OBJ_DIR := $(dir $(PRECOMPILE_OBJ)) PRECOMPILE_DEPFILE := $(BUILD_DIR)/precompile/global.d # Directories -NITROSDK_SRC_SUBDIRS := os mi snd fs gx fx +NITROSDK_SRC_SUBDIRS := os mi snd fs gx fx rtc math LIB_SUBDIRS := DSE NitroSDK MSL_C SRC_SUBDIR := src @@ -132,6 +132,7 @@ XMAP := $(NEF).xMAP EXCCFLAGS := -Cpp_exceptions off MWCFLAGS = $(DEFINES) -enum min -lang c99 $(EXCCFLAGS) -gccext,on -proc $(PROC) -msgstyle gcc -gccinc -i ./include -i ./include/library -i $(WORK_DIR)/files -I$(WORK_DIR)/lib/include -interworking -inline on,noauto -char signed -W all -W pedantic -W noimpl_signedunsigned -W noimplicitconv -W nounusedarg -W nomissingreturn -W error +MWCFLAGS_LIB = $(DEFINES) -enum int -lang c99 $(EXCCFLAGS) -gccext,on -proc $(PROC) -msgstyle gcc -gccinc -i ./include -i ./include/library -i $(WORK_DIR)/files -I$(WORK_DIR)/lib/include -interworking -inline on,noauto -char signed -W all -W pedantic -W noimpl_signedunsigned -W noimplicitconv -W nounusedarg -W nomissingreturn -W error -stdinc MWASFLAGS = $(DEFINES) -proc $(PROC_S) -gccinc -i . -i ./include -i $(WORK_DIR)/asm/include -i $(WORK_DIR)/files -i $(WORK_DIR)/lib/asm/include -i $(WORK_DIR)/lib/syscall/asm/include -I$(WORK_DIR)/lib/include -DSDK_ASM MWLDFLAGS := -proc $(PROC) -nopic -nopid -interworking -map closure,unused -symtab sort -m _start -msgstyle gcc @@ -146,7 +147,7 @@ SRC_INCLUDE_FLAGS := -i ./include -i ./include/library -i $(WORK_DIR)/files $(LI SDK_INCLUDE_FLAGS := $(LIBRARY_INCLUDE_FLAGS) MW_COMPILE_SRC = $(WINE) $(MWCC) $(OPTFLAGS) $(MWCFLAGS) $(SRC_INCLUDE_FLAGS) -i $(PRECOMPILE_OBJ_DIR) -prefix $(PRECOMPILE_OBJ_BASENAME) -MW_COMPILE_LIB = $(WINE) $(MWCC) $(OPTFLAGS_SDK) $(MWCFLAGS) $(SRC_INCLUDE_FLAGS) -i $(PRECOMPILE_OBJ_DIR) -prefix $(PRECOMPILE_OBJ_BASENAME) +MW_COMPILE_LIB = $(WINE) $(MWCC) $(OPTFLAGS_SDK) $(MWCFLAGS_LIB) $(SRC_INCLUDE_FLAGS) -i $(PRECOMPILE_OBJ_DIR) -prefix $(PRECOMPILE_OBJ_BASENAME) MW_COMPILE_SRC_PRECOMPILE = $(WINE) $(MWCC) $(MWCFLAGS) $(SRC_INCLUDE_FLAGS) MW_ASSEMBLE = $(WINE) $(MWAS) $(MWASFLAGS) diff --git a/lib/NitroSDK/asm/dgt.s b/lib/NitroSDK/asm/dgt.s index 76002179..7611a743 100644 --- a/lib/NitroSDK/asm/dgt.s +++ b/lib/NitroSDK/asm/dgt.s @@ -3,8 +3,8 @@ .text - arm_func_start Dgt_Hash2Init -Dgt_Hash2Init: ; 0x02080670 + arm_func_start DGT_Hash2Reset +DGT_Hash2Reset: ; 0x02080670 ldr r1, _020806AC ; =0x67452301 ldr r2, _020806B0 ; =0xEFCDAB89 str r1, [r0] @@ -26,10 +26,10 @@ _020806B0: .word 0xEFCDAB89 _020806B4: .word 0x98BADCFE _020806B8: .word 0x10325476 _020806BC: .word 0xC3D2E1F0 - arm_func_end Dgt_Hash2Init + arm_func_end DGT_Hash2Reset - arm_func_start Dgt_Hash2Update -Dgt_Hash2Update: ; 0x020806C0 + arm_func_start DGT_Hash2SetSource +DGT_Hash2SetSource: ; 0x020806C0 stmdb sp!, {r3, r4, r5, r6, r7, r8, sb, sl, fp, lr} mov sl, r0 movs r8, r2 @@ -121,10 +121,10 @@ _020807F0: ldmia sp!, {r3, r4, r5, r6, r7, r8, sb, sl, fp, pc} .align 2, 0 _02080810: .word _020B2D88 - arm_func_end Dgt_Hash2Update + arm_func_end DGT_Hash2SetSource - arm_func_start Dgt_Hash2GetHash -Dgt_Hash2GetHash: ; 0x02080814 + arm_func_start DGT_Hash2GetDigest +DGT_Hash2GetDigest: ; 0x02080814 stmdb sp!, {r0, r1, r2, r3} stmdb sp!, {r4, r5, r6, lr} ldr r0, [sp, #0x10] @@ -260,7 +260,7 @@ _020808D4: bx lr .align 2, 0 _02080A0C: .word _020B2D88 - arm_func_end Dgt_Hash2GetHash + arm_func_end DGT_Hash2GetDigest arm_func_start Dgt_Hash2CalcHmac Dgt_Hash2CalcHmac: ; 0x02080A10 @@ -280,11 +280,11 @@ Dgt_Hash2CalcHmac: ; 0x02080A10 add lr, sp, #0x38 add ip, sp, #0x24 str lr, [sp, #0x10] - ldr lr, _02080A98 ; =Dgt_Hash2Init + ldr lr, _02080A98 ; =DGT_Hash2Reset str ip, [sp, #0x14] - ldr ip, _02080A9C ; =Dgt_Hash2Update + ldr ip, _02080A9C ; =DGT_Hash2SetSource str lr, [sp, #0x18] - ldr lr, _02080AA0 ; =Dgt_Hash2GetHash + ldr lr, _02080AA0 ; =DGT_Hash2GetDigest str ip, [sp, #0x1c] ldr ip, [sp, #0xb8] str lr, [sp, #0x20] @@ -299,9 +299,9 @@ Dgt_Hash2CalcHmac: ; 0x02080A10 ldmia sp!, {r4, r5, r6, r7, r8, pc} .align 2, 0 _02080A94: .word _020AEC5C -_02080A98: .word Dgt_Hash2Init -_02080A9C: .word Dgt_Hash2Update -_02080AA0: .word Dgt_Hash2GetHash +_02080A98: .word DGT_Hash2Reset +_02080A9C: .word DGT_Hash2SetSource +_02080AA0: .word DGT_Hash2GetDigest arm_func_end Dgt_Hash2CalcHmac arm_func_start Dgti_CalcHmac diff --git a/lib/NitroSDK/asm/include/main_0207F894.inc b/lib/NitroSDK/asm/include/main_0207F894.inc index 8ee00b15..8f3db743 100644 --- a/lib/NitroSDK/asm/include/main_0207F894.inc +++ b/lib/NitroSDK/asm/include/main_0207F894.inc @@ -75,9 +75,9 @@ .public DC_InvalidateRange .public DC_StoreRange .public DC_WaitWriteBufferEmpty -.public Dgt_Hash2GetHash -.public Dgt_Hash2Init -.public Dgt_Hash2Update +.public DGT_Hash2GetDigest +.public DGT_Hash2Reset +.public DGT_Hash2SetSource .public EnableIrqFlag .public fflush .public FS_CloseFile diff --git a/lib/NitroSDK/asm/math_crc.s b/lib/NitroSDK/asm/math_crc.s index 74b3b218..159bfa05 100644 --- a/lib/NitroSDK/asm/math_crc.s +++ b/lib/NitroSDK/asm/math_crc.s @@ -3,8 +3,8 @@ .text - arm_func_start Mathi_Crc8InitTable -Mathi_Crc8InitTable: ; 0x02084FB8 + arm_func_start MATHi_CRC8InitTable +MATHi_CRC8InitTable: ; 0x02084FB8 stmdb sp!, {r3, lr} mov ip, #0 mov r2, ip @@ -23,10 +23,10 @@ _02084FCC: cmp ip, #0x100 blo _02084FC4 ldmia sp!, {r3, pc} - arm_func_end Mathi_Crc8InitTable + arm_func_end MATHi_CRC8InitTable - arm_func_start Mathi_Crc8Update -Mathi_Crc8Update: ; 0x02084FF8 + arm_func_start MATHi_CRC8Update +MATHi_CRC8Update: ; 0x02084FF8 stmdb sp!, {r4, lr} cmp r3, #0 ldrb lr, [r1] @@ -43,10 +43,10 @@ _0208500C: _02085028: strb lr, [r1] ldmia sp!, {r4, pc} - arm_func_end Mathi_Crc8Update + arm_func_end MATHi_CRC8Update - arm_func_start Mathi_Crc16InitTable -Mathi_Crc16InitTable: ; 0x02085030 + arm_func_start MATHi_CRC16InitTable +MATHi_CRC16InitTable: ; 0x02085030 stmdb sp!, {r3, lr} mov lr, #0 mov r3, lr @@ -66,10 +66,10 @@ _02085044: cmp lr, #0x100 blo _0208503C ldmia sp!, {r3, pc} - arm_func_end Mathi_Crc16InitTable + arm_func_end MATHi_CRC16InitTable - arm_func_start Mathi_Crc16Update -Mathi_Crc16Update: ; 0x02085074 + arm_func_start MATHi_CRC16Update +MATHi_CRC16Update: ; 0x02085074 stmdb sp!, {r4, lr} cmp r3, #0 ldrh lr, [r1] @@ -88,10 +88,10 @@ _02085088: _020850AC: strh lr, [r1] ldmia sp!, {r4, pc} - arm_func_end Mathi_Crc16Update + arm_func_end MATHi_CRC16Update - arm_func_start Mathi_Crc32InitTable -Mathi_Crc32InitTable: ; 0x020850B4 + arm_func_start MATHi_CRC32InitTable +MATHi_CRC32InitTable: ; 0x020850B4 stmdb sp!, {r3, lr} mov ip, #0 mov r2, ip @@ -110,10 +110,10 @@ _020850C8: cmp ip, #0x100 blo _020850C0 ldmia sp!, {r3, pc} - arm_func_end Mathi_Crc32InitTable + arm_func_end MATHi_CRC32InitTable - arm_func_start Mathi_Crc32Update -Mathi_Crc32Update: ; 0x020850F4 + arm_func_start MATHi_CRC32Update +MATHi_CRC32Update: ; 0x020850F4 stmdb sp!, {r4, lr} cmp r3, #0 ldr lr, [r1] @@ -131,10 +131,10 @@ _02085108: _02085128: str lr, [r1] ldmia sp!, {r4, pc} - arm_func_end Mathi_Crc32Update + arm_func_end MATHi_CRC32Update - arm_func_start Math_CalcCrc8 -Math_CalcCrc8: ; 0x02085130 + arm_func_start MATH_CalcCRC8 +MATH_CalcCRC8: ; 0x02085130 stmdb sp!, {r3, lr} mov lr, r1 mov ip, #0 @@ -142,13 +142,13 @@ Math_CalcCrc8: ; 0x02085130 add r1, sp, #0 mov r2, lr strb ip, [sp] - bl Mathi_Crc8Update + bl MATHi_CRC8Update ldrb r0, [sp] ldmia sp!, {r3, pc} - arm_func_end Math_CalcCrc8 + arm_func_end MATH_CalcCRC8 - arm_func_start Math_CalcCrc16 -Math_CalcCrc16: ; 0x02085158 + arm_func_start MATH_CalcCRC16 +MATH_CalcCRC16: ; 0x02085158 stmdb sp!, {r3, lr} mov lr, r1 mov ip, #0 @@ -156,13 +156,13 @@ Math_CalcCrc16: ; 0x02085158 add r1, sp, #0 mov r2, lr strh ip, [sp] - bl Mathi_Crc16Update + bl MATHi_CRC16Update ldrh r0, [sp] ldmia sp!, {r3, pc} - arm_func_end Math_CalcCrc16 + arm_func_end MATH_CalcCRC16 - arm_func_start Math_CalcCrc32 -Math_CalcCrc32: ; 0x02085180 + arm_func_start MATH_CalcCRC32 +MATH_CalcCRC32: ; 0x02085180 stmdb sp!, {r3, lr} mov lr, r1 mvn ip, #0 @@ -170,11 +170,11 @@ Math_CalcCrc32: ; 0x02085180 add r1, sp, #0 mov r2, lr str ip, [sp] - bl Mathi_Crc32Update + bl MATHi_CRC32Update ldr r0, [sp] mvn r0, r0 ldmia sp!, {r3, pc} - arm_func_end Math_CalcCrc32 + arm_func_end MATH_CalcCRC32 arm_func_start sub_020851AC sub_020851AC: ; 0x020851AC diff --git a/lib/NitroSDK/asm/math_dgt.s b/lib/NitroSDK/asm/math_dgt.s deleted file mode 100644 index 380733c8..00000000 --- a/lib/NitroSDK/asm/math_dgt.s +++ /dev/null @@ -1,25 +0,0 @@ - .include "asm/macros.inc" - .include "main_0207F894.inc" - - .text - - arm_func_start Math_CalcSha1 -Math_CalcSha1: ; 0x02084F78 - stmdb sp!, {r4, r5, r6, lr} - sub sp, sp, #0x68 - mov r6, r0 - add r0, sp, #0 - mov r5, r1 - mov r4, r2 - bl Dgt_Hash2Init - add r0, sp, #0 - mov r1, r5 - mov r2, r4 - bl Dgt_Hash2Update - add r0, sp, #0 - mov r1, r6 - bl Dgt_Hash2GetHash - add sp, sp, #0x68 - ldmia sp!, {r4, r5, r6, pc} - arm_func_end Math_CalcSha1 - diff --git a/lib/NitroSDK/src/math_math.c b/lib/NitroSDK/src/math/math.c similarity index 100% rename from lib/NitroSDK/src/math_math.c rename to lib/NitroSDK/src/math/math.c diff --git a/lib/NitroSDK/src/math/math_crc.c b/lib/NitroSDK/src/math/math_crc.c new file mode 100644 index 00000000..d96f20e0 --- /dev/null +++ b/lib/NitroSDK/src/math/math_crc.c @@ -0,0 +1,250 @@ +#include + +void MATHi_CRC8InitTable (MATHCRC8Table *table, u8 poly) +{ + u32 r; + u32 i, j; + u8 *t = table->table; + + for (i = 0; i < 256; i++) { + r = i; + for (j = 0; j < 8; j++) { + if (r & 0x80) { + r = (r << 1) ^ poly; + } else { + r <<= 1; + } + } + t[i] = (u8)r; + } +} + +// void MATHi_CRC8InitTableRev (MATHCRC8Table *table, u8 poly) +// { +// u32 r; +// u32 i, j; +// u8 *t = table->table; +// +// for (i = 0; i < 256; i++) { +// r = i; +// for (j = 0; j < 8; j++) { +// if (r & 1) { +// r = (r >> 1) ^ poly; +// } else { +// r >>= 1; +// } +// } +// t[i] = (u8)r; +// } +// } + +void MATHi_CRC8Update (const MATHCRC8Table *table, MATHCRC8Context *context, const void *input, u32 length) +{ + u32 r; + u32 i; + const u8 *t = table->table; + u8 *data = (u8 *)input; + + r = (u32) * context; + + for (i = 0; i < length; i++) { + r = t[(r ^ *data) & 0xff]; + data++; + } + + *context = (MATHCRC8Context) r; +} + +void MATHi_CRC16InitTable (MATHCRC16Table *table, u16 poly) +{ + u32 r; + u32 i, j; + u16 *t = table->table; + + for (i = 0; i < 256; i++) { + r = i << 8; + for (j = 0; j < 8; j++) { + if (r & 0x8000) { + r = (r << 1) ^ poly; + } else { + r <<= 1; + } + } + t[i] = (u16)r; + } +} + +// void MATHi_CRC16InitTableRev (MATHCRC16Table *table, u16 poly) +// { +// u32 r; +// u32 i, j; +// u16 *t = table->table; +// +// for (i = 0; i < 256; i++) { +// r = i; +// for (j = 0; j < 8; j++) { +// if (r & 1) { +// r = (r >> 1) ^ poly; +// } else { +// r >>= 1; +// } +// } +// t[i] = (u16)r; +// } +// } + +void MATHi_CRC16Update (const MATHCRC16Table *table, MATHCRC16Context *context, const void *input, u32 length) +{ + u32 r; + u32 i; + const u16 *t = table->table; + u8 *data = (u8 *)input; + + r = (u32) * context; + + for (i = 0; i < length; i++) { + r = (r << 8) ^ t[((r >> 8) ^ *data) & 0xff]; + data++; + } + + *context = (MATHCRC16Context) r; +} + +// void MATHi_CRC16UpdateRev (const MATHCRC16Table *table, MATHCRC16Context *context, const void *input, u32 length) +// { +// u32 r; +// u32 i; +// const u16 *t = table->table; +// u8 *data = (u8 *)input; +// +// r = (u32) * context; +// +// for (i = 0; i < length; i++) { +// r = (r >> 8) ^ t[(r ^ *data) & 0xff]; +// data++; +// } +// +// *context = (MATHCRC16Context) r; +// } + +void MATHi_CRC32InitTable (MATHCRC32Table *table, u32 poly) +{ + u32 r; + u32 i, j; + u32 *t = table->table; + + for (i = 0; i < 256; i++) { + r = i << 24; + for (j = 0; j < 8; j++) { + if (r & 0x80000000U) { + r = (r << 1) ^ poly; + } else { + r <<= 1; + } + } + t[i] = r; + } +} + +// void MATHi_CRC32InitTableRev (MATHCRC32Table *table, u32 poly) +// { +// u32 r; +// u32 i, j; +// u32 *t = table->table; +// +// for (i = 0; i < 256; i++) { +// r = i; +// for (j = 0; j < 8; j++) { +// if (r & 1) { +// r = (r >> 1) ^ poly; +// } else { +// r >>= 1; +// } +// } +// t[i] = r; +// } +// } + +void MATHi_CRC32Update (const MATHCRC32Table *table, MATHCRC32Context *context, const void *input, u32 length) +{ + u32 r; + u32 i; + const u32 *t = table->table; + u8 *data = (u8 *)input; + + r = (u32) * context; + + for (i = 0; i < length; i++) { + r = (r << 8) ^ t[((r >> 24) ^ *data) & 0xff]; + data++; + } + + *context = (MATHCRC32Context) r; +} + +// void MATHi_CRC32UpdateRev (const MATHCRC32Table *table, MATHCRC32Context *context, const void *input, u32 length) +// { +// u32 r; +// u32 i; +// const u32 *t = table->table; +// u8 *data = (u8 *)input; +// +// r = (u32) * context; +// +// for (i = 0; i < length; i++) { +// r = (r >> 8) ^ t[(r ^ *data) & 0xff]; +// data++; +// } +// +// *context = (MATHCRC32Context) r; +// } + +u8 MATH_CalcCRC8 (const MATHCRC8Table *table, const void *data, u32 dataLength) +{ + MATHCRC8Context context; + + MATH_CRC8Init(&context); + MATH_CRC8Update(table, &context, data, dataLength); + + return MATH_CRC8GetHash(&context); +} + +u16 MATH_CalcCRC16 (const MATHCRC16Table *table, const void *data, u32 dataLength) +{ + MATHCRC16Context context; + + MATH_CRC16Init(&context); + MATH_CRC16Update(table, &context, data, dataLength); + + return MATH_CRC16GetHash(&context); +} + +// u16 MATH_CalcCRC16CCITT (const MATHCRC16Table *table, const void *data, u32 dataLength) +// { +// MATHCRC16Context context; +// +// MATH_CRC16CCITTInit(&context); +// MATH_CRC16CCITTUpdate(table, &context, data, dataLength); +// +// return MATH_CRC16CCITTGetHash(&context); +// } + +u32 MATH_CalcCRC32 (const MATHCRC32Table *table, const void *data, u32 dataLength) +{ + MATHCRC32Context context; + + MATH_CRC32Init(&context); + MATH_CRC32Update(table, &context, data, dataLength); + + return MATH_CRC32GetHash(&context); +} + +// u32 MATH_CalcCRC32POSIX (const MATHCRC32Table *table, const void *data, u32 dataLength) +// { +// MATHCRC32Context context; +// +// MATH_CRC32POSIXInit(&context); +// MATH_CRC32POSIXUpdate(table, &context, data, dataLength); +// +// return MATH_CRC32POSIXGetHash(&context); +// } diff --git a/lib/NitroSDK/src/math/math_dgt.c b/lib/NitroSDK/src/math/math_dgt.c new file mode 100644 index 00000000..e4361e56 --- /dev/null +++ b/lib/NitroSDK/src/math/math_dgt.c @@ -0,0 +1,19 @@ +#include + +// void MATH_CalcMD5 (void *digest, const void *data, u32 dataLength) +// { +// MATHMD5Context context; +// +// MATH_MD5Init(&context); +// MATH_MD5Update(&context, data, dataLength); +// MATH_MD5GetHash(&context, digest); +// } + +void Math_CalcSha1 (void *digest, const void *data, u32 dataLength) +{ + MATHSHA1Context context; + + MATH_SHA1Init(&context); + MATH_SHA1Update(&context, data, dataLength); + MATH_SHA1GetHash(&context, digest); +} diff --git a/lib/NitroSDK/src/rtc_internal.c b/lib/NitroSDK/src/rtc/rtc_internal.c similarity index 100% rename from lib/NitroSDK/src/rtc_internal.c rename to lib/NitroSDK/src/rtc/rtc_internal.c diff --git a/lib/include/nitro/dgt/common.h b/lib/include/nitro/dgt/common.h new file mode 100644 index 00000000..547ce04b --- /dev/null +++ b/lib/include/nitro/dgt/common.h @@ -0,0 +1,19 @@ +#ifndef NITRO_DGT_COMMON_H_ +#define NITRO_DGT_COMMON_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define DGT_HASH1_DIGEST_SIZE (128 / 8) +#define DGT_HASH2_DIGEST_SIZE (160 / 8) + +#define DGT_HASH_DIGEST_SIZE_MAX DGT_HASH2_DIGEST_SIZE + +#define DGT_HASH_BLOCK_SIZE (512 / 8) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/include/nitro/dgt/dgt.h b/lib/include/nitro/dgt/dgt.h new file mode 100644 index 00000000..a067a518 --- /dev/null +++ b/lib/include/nitro/dgt/dgt.h @@ -0,0 +1,77 @@ +#ifndef NITRO_DGT_DGT_H_ +#define NITRO_DGT_DGT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct DGTHash1Context { + union { + struct { + unsigned long a, b, c, d; + }; + unsigned long state[4]; + }; + unsigned long long length; + union { + unsigned long buffer32[16]; + unsigned char buffer8[64]; + }; +} DGTHash1Context; + +#if defined(SDK_DGT_HASH2_CODE_SAFE) || defined(SDK_WIN32) || defined(SDK_FROM_TOOL) + typedef struct DGTHash2Context { + unsigned long Intermediate_Hash[5]; + unsigned long Length_Low; + unsigned long Length_High; + int Message_Block_Index; + unsigned char Message_Block[64]; + int Computed; + int Corrupted; + } DGTHash2Context; +#else + typedef struct DGTHash2Context { + unsigned long h0, h1, h2, h3, h4; + unsigned long Nl, Nh; + int num; + unsigned long data[64 / 4]; + int dummy[2]; + } DGTHash2Context; +#endif + +#ifdef SDK_DGT_HASH1_CODE_SAFE + void DGT_Hash1Reset(DGTHash1Context *); + void DGT_Hash1SetSource(DGTHash1Context *, unsigned char *, unsigned long); + void DGT_Hash1GetDigest_R(unsigned char digest[16], DGTHash1Context *); +#else + void DGT_Hash1Reset(DGTHash1Context *); + void DGT_Hash1SetSource(DGTHash1Context *, const void *, unsigned long); + void DGT_Hash1GetDigest_R(void * digest, DGTHash1Context *); +#endif + +#if defined(SDK_DGT_HASH2_CODE_SAFE) || defined(SDK_WIN32) || defined(SDK_FROM_TOOL) + void DGT_Hash2Reset(DGTHash2Context *); + void DGT_Hash2SetSource(DGTHash2Context *, unsigned char *, unsigned long); + void DGT_Hash2GetDigest(DGTHash2Context *, unsigned char digest[20]); +#else + void DGT_Hash2Reset(DGTHash2Context *); + void DGT_Hash2SetSource(DGTHash2Context *, const unsigned char *, unsigned long); + void DGT_Hash2GetDigest(DGTHash2Context *, unsigned char * digest); +#endif + +void DGT_Hash1CalcHmac(void * digest, void * bin_ptr, int bin_len, void * key_ptr, int key_len); +void DGT_Hash2CalcHmac(void * digest, void * bin_ptr, int bin_len, void * key_ptr, int key_len); + +int DGT_Hash1CalcHmacForRms(void * digest, void * romh_ptr, int romh_len, void * mbin_ptr, int mbin_len, void * sbin_ptr, int sbin_len, void * key_ptr, int key_len); +int DGT_Hash2CalcHmacForRms(void * digest, void * romh_ptr, int romh_len, void * mbin_ptr, int mbin_len, void * sbin_ptr, int sbin_len, void * key_ptr, int key_len); +int DGT_Hash1TestHmacForRms(void * digest, void * romh_ptr, int romh_len, void * mbin_ptr, int mbin_len, void * sbin_ptr, int sbin_len, void * key_ptr, int key_len); +int DGT_Hash2TestHmacForRms(void * digest, void * romh_ptr, int romh_len, void * mbin_ptr, int mbin_len, void * sbin_ptr, int sbin_len, void * key_ptr, int key_len); +int DGT_SetOverlayTableMode(int flag); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/include/nitro/math.h b/lib/include/nitro/math.h index bfc300a8..64a8bce9 100644 --- a/lib/include/nitro/math.h +++ b/lib/include/nitro/math.h @@ -3,5 +3,7 @@ u8 Math_CountPopulation (u32 x); +#include + #endif //NITRO_MATH_H_ diff --git a/lib/include/nitro/math/dgt.h b/lib/include/nitro/math/dgt.h new file mode 100644 index 00000000..70dcc450 --- /dev/null +++ b/lib/include/nitro/math/dgt.h @@ -0,0 +1,79 @@ +#ifndef NITRO_MATH_DGT_H_ +#define NITRO_MATH_DGT_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MATH_MD5_DIGEST_SIZE DGT_HASH1_DIGEST_SIZE +#define MATH_SHA1_DIGEST_SIZE DGT_HASH2_DIGEST_SIZE + +#define MATH_MD5_BLOCK_SIZE DGT_HASH_BLOCK_SIZE +#define MATH_SHA1_BLOCK_SIZE DGT_HASH_BLOCK_SIZE + +typedef DGTHash1Context MATHMD5Context; +typedef DGTHash2Context MATHSHA1Context; + +static inline void MATH_MD5Init (MATHMD5Context * context) +{ + DGT_Hash1Reset(context); +} + +static inline void MATH_MD5Update (MATHMD5Context * context, const void * input, u32 length) +{ + DGT_Hash1SetSource(context, (u8 *)input, length); +} + +static inline void MATH_MD5GetHash (MATHMD5Context * context, void * digest) +{ + DGT_Hash1GetDigest_R((u8 *)digest, context); +} + +static inline void MATH_MD5GetDigest (MATHMD5Context * context, void * digest) +{ + MATH_MD5GetHash(context, digest); +} + +static inline void MATH_SHA1Init (MATHSHA1Context * context) +{ + DGT_Hash2Reset(context); +} + +static inline void MATH_SHA1Update (MATHSHA1Context * context, const void * input, u32 length) +{ + DGT_Hash2SetSource(context, (u8 *)input, length); +} + +static inline void MATH_SHA1GetHash (MATHSHA1Context * context, void * digest) +{ + DGT_Hash2GetDigest(context, (u8 *)digest); +} + +static inline void MATH_SHA1GetDigest (MATHSHA1Context * context, void * digest) +{ + MATH_SHA1GetHash(context, digest); +} + +void MATH_CalcMD5(void * digest, const void * data, u32 dataLength); +void Math_CalcSha1(void * digest, const void * data, u32 dataLength); + +static inline void MATH_CalcHMACMD5 (void * digest, const void * data, u32 dataLength, const void * key, u32 keyLength) +{ + DGT_Hash1CalcHmac(digest, (void *)data, (int)dataLength, (void *)key, (int)keyLength); +} + +static inline void MATH_CalcHMACSHA1 (void * digest, const void * data, u32 dataLength, const void * key, u32 keyLength) +{ + DGT_Hash2CalcHmac(digest, (void *)data, (int)dataLength, (void *)key, (int)keyLength); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/main.lsf b/main.lsf index aa5b322f..707d2b58 100644 --- a/main.lsf +++ b/main.lsf @@ -308,7 +308,7 @@ Static main Object lib/NitroSDK/asm/spi_tp.o Object lib/NitroSDK/asm/spi_pm.o Object lib/NitroSDK/asm/rtc_external.o - Object lib/NitroSDK/src/rtc_internal.o + Object lib/NitroSDK/src/rtc/rtc_internal.o Object lib/NitroSDK/asm/rtc_convert.o Object lib/NitroSDK/asm/card_common.o Object lib/NitroSDK/asm/card_spi.o @@ -319,8 +319,8 @@ Static main Object lib/NitroSDK/asm/ctrdg.o Object lib/NitroSDK/asm/ctrdg_proc.o Object lib/NitroSDK/asm/ctrdg_task.o - Object lib/NitroSDK/src/math_math.o - Object lib/NitroSDK/asm/math_dgt.o + Object lib/NitroSDK/src/math/math.o + Object lib/NitroSDK/src/math/math_dgt.o Object lib/NitroSDK/asm/math_crc.o Object lib/NitroSDK/asm/std_string.o Object lib/NitroSDK/src/os/os_printf_1.o