From 7c1d3869d8cf4341acedbe7c662e8ac1ca935666 Mon Sep 17 00:00:00 2001 From: Egor Ananyin Date: Fri, 22 May 2020 19:46:43 +0300 Subject: Decompile libmath --- arm9/lib/include/MATH.h | 8 ++++++++ arm9/lib/include/MATH_crc.h | 38 ++++++++++++++++++++++++++++++++++++++ arm9/lib/include/MATH_dgt.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ arm9/lib/include/dgt.h | 30 ++++++++++++++++++++++++++++++ arm9/lib/include/math.h | 8 ++++++++ 5 files changed, 129 insertions(+) create mode 100644 arm9/lib/include/MATH.h create mode 100644 arm9/lib/include/MATH_crc.h create mode 100644 arm9/lib/include/MATH_dgt.h create mode 100644 arm9/lib/include/dgt.h create mode 100644 arm9/lib/include/math.h (limited to 'arm9/lib/include') diff --git a/arm9/lib/include/MATH.h b/arm9/lib/include/MATH.h new file mode 100644 index 00000000..037492f5 --- /dev/null +++ b/arm9/lib/include/MATH.h @@ -0,0 +1,8 @@ +#ifndef GUARD_MATH_H +#define GUARD_MATH_H + +#include "types.h" + +u8 MATH_CountPopulation(u32); + +#endif diff --git a/arm9/lib/include/MATH_crc.h b/arm9/lib/include/MATH_crc.h new file mode 100644 index 00000000..800b738b --- /dev/null +++ b/arm9/lib/include/MATH_crc.h @@ -0,0 +1,38 @@ +#ifndef GUARD_MATH_CRC_H +#define GUARD_MATH_CRC_H + +#include "types.h" + +typedef u8 MATHCRC8Context; +typedef u16 MATHCRC16Context; +typedef u32 MATHCRC32Context; + +struct MATHCRC8Table { + u8 table[256]; +}; + +struct MATHCRC16Table { + u16 table[256]; +}; + +struct MATHCRC32Table { + u32 table[256]; +}; + +u32 MATH_CalcCRC32(const struct MATHCRC32Table *table, const void *data, u32 dataLength); +void MATHi_CRC32UpdateRev(const struct MATHCRC32Table *table, MATHCRC32Context *context, const void *input, u32 length); +u16 MATH_CalcCRC16CCITT(const struct MATHCRC16Table *table, const void *data, u32 dataLength); +void MATHi_CRC16Update(const struct MATHCRC16Table *table, MATHCRC16Context *context, const void *input, u32 length); +u16 MATH_CalcCRC16(const struct MATHCRC16Table *table, const void *data, u32 dataLength); +void MATHi_CRC16UpdateRev(const struct MATHCRC16Table *table, MATHCRC16Context *context, const void *input, u32 length); +u8 MATH_CalcCRC8(const struct MATHCRC8Table *table, const void *data, u32 dataLength); +void MATHi_CRC8Update(const struct MATHCRC8Table *table, MATHCRC8Context *context, const void *input, u32 length); +void MATHi_CRC32InitTableRev(struct MATHCRC32Table *table, u32 poly); +void MATHi_CRC16UpdateRev(const struct MATHCRC16Table *table, MATHCRC16Context *context, const void *input, u32 length); +void MATHi_CRC16Update(const struct MATHCRC16Table *table, MATHCRC16Context *context, const void *input, u32 length); +void MATHi_CRC16InitTableRev(struct MATHCRC16Table *table, u16 poly); +void MATHi_CRC16InitTable(struct MATHCRC16Table *table, u16 poly); +void MATHi_CRC8Update(const struct MATHCRC8Table *table, MATHCRC8Context *context, const void *input, u32 length); +void MATHi_CRC8InitTable(struct MATHCRC8Table *table, u8 poly); + +#endif diff --git a/arm9/lib/include/MATH_dgt.h b/arm9/lib/include/MATH_dgt.h new file mode 100644 index 00000000..9eb3d2ef --- /dev/null +++ b/arm9/lib/include/MATH_dgt.h @@ -0,0 +1,45 @@ +#ifndef GUARD_MATH_DGT_H +#define GUARD_MATH_DGT_H + +#include "dgt.h" +#include "types.h" + +typedef struct DGTHash1Context MATHMD5Context; +typedef struct 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); + +#endif diff --git a/arm9/lib/include/dgt.h b/arm9/lib/include/dgt.h new file mode 100644 index 00000000..5e63f3f7 --- /dev/null +++ b/arm9/lib/include/dgt.h @@ -0,0 +1,30 @@ +#ifndef GUARD_DGT_H +#define GUARD_DGT_H + +#include "types.h" + +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]; + }; +}; + +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; +}; + +#endif diff --git a/arm9/lib/include/math.h b/arm9/lib/include/math.h new file mode 100644 index 00000000..80d7cc26 --- /dev/null +++ b/arm9/lib/include/math.h @@ -0,0 +1,8 @@ +#ifndef GUARD_LIBMATH_H +#define GUARD_LIBMATH_H + +#include "MATH.h" +#include "MATH_crc.h" +#include "MATH_dgt.h" + +#endif -- cgit v1.2.3 From 936ea8a0134ed8095f9496ebe1571866509530d7 Mon Sep 17 00:00:00 2001 From: Egor Ananyin Date: Sat, 23 May 2020 09:22:31 +0300 Subject: Rename header files to avoid confusion --- arm9/lib/include/MATH.h | 8 -------- arm9/lib/include/MATH_pop.h | 8 ++++++++ arm9/lib/include/dgt.h | 7 +++++++ arm9/lib/include/math.h | 7 ++++--- 4 files changed, 19 insertions(+), 11 deletions(-) delete mode 100644 arm9/lib/include/MATH.h create mode 100644 arm9/lib/include/MATH_pop.h (limited to 'arm9/lib/include') diff --git a/arm9/lib/include/MATH.h b/arm9/lib/include/MATH.h deleted file mode 100644 index 037492f5..00000000 --- a/arm9/lib/include/MATH.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef GUARD_MATH_H -#define GUARD_MATH_H - -#include "types.h" - -u8 MATH_CountPopulation(u32); - -#endif diff --git a/arm9/lib/include/MATH_pop.h b/arm9/lib/include/MATH_pop.h new file mode 100644 index 00000000..89dab0c0 --- /dev/null +++ b/arm9/lib/include/MATH_pop.h @@ -0,0 +1,8 @@ +#ifndef GUARD_MATH_POP_H +#define GUARD_MATH_POP_H + +#include "types.h" + +u8 MATH_CountPopulation(u32); + +#endif diff --git a/arm9/lib/include/dgt.h b/arm9/lib/include/dgt.h index 5e63f3f7..a764e85a 100644 --- a/arm9/lib/include/dgt.h +++ b/arm9/lib/include/dgt.h @@ -27,4 +27,11 @@ struct DGTHash2Context { int Corrupted; }; +void DGT_Hash1Reset(struct DGTHash1Context *context); +void DGT_Hash1SetSource(struct DGTHash1Context *context, u8 *input, u32 length); +void DGT_Hash1GetDigest_R(u8 *digest, struct DGTHash1Context *context); +void DGT_Hash2Reset(struct DGTHash2Context *context); +void DGT_Hash2SetSource(struct DGTHash2Context *context, u8 *input, u32 length); +void DGT_Hash2GetDigest(struct DGTHash2Context *context, u8 *digest); + #endif diff --git a/arm9/lib/include/math.h b/arm9/lib/include/math.h index 80d7cc26..085aa24f 100644 --- a/arm9/lib/include/math.h +++ b/arm9/lib/include/math.h @@ -1,7 +1,8 @@ -#ifndef GUARD_LIBMATH_H -#define GUARD_LIBMATH_H +#ifndef GUARD_MATH_H +#define GUARD_MATH_H -#include "MATH.h" +#include "dgt.h" +#include "MATH_pop.h" #include "MATH_crc.h" #include "MATH_dgt.h" -- cgit v1.2.3