mirror of
https://github.com/pret/pokeplatinum.git
synced 2026-08-20 16:35:19 -05:00
decompile rc4 init functions (#999)
Some checks failed
build / build (push) Has been cancelled
Some checks failed
build / build (push) Has been cancelled
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
.include "macros/function.inc"
|
||||
|
||||
|
||||
|
||||
.text
|
||||
|
||||
|
||||
arm_func_start CRYPTO_RC4FastInit
|
||||
CRYPTO_RC4FastInit: ; 0x020A490C
|
||||
stmfd sp!, {r4, r5, r6, lr}
|
||||
mov r3, #0
|
||||
str r3, [r0, #0]
|
||||
cmp r2, #0x10
|
||||
str r3, [r0, #4]
|
||||
movhi r2, #0x10
|
||||
add r0, r0, #8
|
||||
_020A4928:
|
||||
str r3, [r0, r3, lsl #2]
|
||||
add r3, r3, #1
|
||||
cmp r3, #0x100
|
||||
blt _020A4928
|
||||
mov r5, #0
|
||||
mov r6, r5
|
||||
mov lr, r5
|
||||
mov ip, r5
|
||||
_020A4948:
|
||||
ldrb r3, [r1, r6]
|
||||
ldr r4, [r0, lr, lsl #2]
|
||||
add r6, r6, #1
|
||||
add r3, r4, r3
|
||||
add r3, r5, r3
|
||||
and r5, r3, #0xff
|
||||
ldr r3, [r0, r5, lsl #2]
|
||||
cmp r6, r2
|
||||
str r3, [r0, lr, lsl #2]
|
||||
add lr, lr, #1
|
||||
moveq r6, ip
|
||||
str r4, [r0, r5, lsl #2]
|
||||
cmp lr, #0x100
|
||||
blt _020A4948
|
||||
mov r2, #0
|
||||
_020A4984:
|
||||
ldr r1, [r0, r2, lsl #2]
|
||||
mov r1, r1, lsl #0x18
|
||||
str r1, [r0, r2, lsl #2]
|
||||
add r2, r2, #1
|
||||
cmp r2, #0x100
|
||||
blt _020A4984
|
||||
ldmia sp!, {r4, r5, r6, lr}
|
||||
bx lr
|
||||
arm_func_end CRYPTO_RC4FastInit
|
||||
|
||||
arm_func_start CRYPTO_RC4Init
|
||||
CRYPTO_RC4Init: ; 0x020A49A4
|
||||
stmfd sp!, {r4, r5, r6, r7, lr}
|
||||
sub sp, sp, #4
|
||||
mov r3, #0
|
||||
strb r3, [r0]
|
||||
cmp r2, #0x10
|
||||
strb r3, [r0, #1]
|
||||
movhi r2, #0x10
|
||||
add r0, r0, #4
|
||||
_020A49C4:
|
||||
strb r3, [r0, r3]
|
||||
add r3, r3, #1
|
||||
cmp r3, #0x100
|
||||
blt _020A49C4
|
||||
mov r6, #0
|
||||
mov r7, r6
|
||||
mov r4, r6
|
||||
mov r3, r6
|
||||
and ip, r2, #0xff
|
||||
_020A49E8:
|
||||
ldrb r5, [r0, r4]
|
||||
ldrb lr, [r1, r7]
|
||||
add r2, r7, #1
|
||||
and r7, r2, #0xff
|
||||
add r2, r5, lr
|
||||
add r2, r6, r2
|
||||
and r6, r2, #0xff
|
||||
ldrb r2, [r0, r6]
|
||||
add lr, r0, r4
|
||||
add r4, r4, #1
|
||||
strb r2, [lr]
|
||||
cmp r7, ip
|
||||
moveq r7, r3
|
||||
cmp r4, #0x100
|
||||
strb r5, [r0, r6]
|
||||
blt _020A49E8
|
||||
add sp, sp, #4
|
||||
ldmia sp!, {r4, r5, r6, r7, lr}
|
||||
bx lr
|
||||
arm_func_end CRYPTO_RC4Init
|
||||
@@ -7,20 +7,22 @@ extern "C" {
|
||||
|
||||
#include <nitro/types.h>
|
||||
|
||||
typedef struct CRYPTORC4Context_t {
|
||||
#define RC4_S_SIZE 256
|
||||
|
||||
typedef struct CRYPTORC4Context {
|
||||
u8 i, j;
|
||||
u8 padd[2];
|
||||
u8 s[256];
|
||||
u8 s[RC4_S_SIZE];
|
||||
} CRYPTORC4Context;
|
||||
|
||||
typedef struct CRYPTORC4FastContext_t {
|
||||
typedef struct CRYPTORC4FastContext {
|
||||
u32 i, j;
|
||||
u32 s[256];
|
||||
u32 s[RC4_S_SIZE];
|
||||
} CRYPTORC4FastContext;
|
||||
|
||||
void CRYPTO_RC4Init(CRYPTORC4Context *, const void *, u32);
|
||||
void CRYPTO_RC4Init(CRYPTORC4Context *ctx, const void *key, u32 keyLength);
|
||||
void CRYPTO_RC4Encrypt(CRYPTORC4Context *, const void *, u32, void *);
|
||||
void CRYPTO_RC4FastInit(CRYPTORC4FastContext *, const void *, u32);
|
||||
void CRYPTO_RC4FastInit(CRYPTORC4FastContext *ctx, const void *key, u32 keyLength);
|
||||
void CRYPTO_RC4FastEncrypt(CRYPTORC4FastContext *, const void *, u32, void *);
|
||||
|
||||
static inline void CRYPTO_RC4Decrypt(CRYPTORC4Context *param0, const void *param1, u32 param2, void *param3)
|
||||
|
||||
@@ -13,7 +13,7 @@ libcrypto_c_args = [
|
||||
libcrypto_public_includes = include_directories('include')
|
||||
|
||||
libcrypto_static_srcs = files(
|
||||
'asm/rc4.s',
|
||||
'src/rc4.c',
|
||||
'asm/rc4-arm4cw.s'
|
||||
)
|
||||
|
||||
@@ -25,8 +25,11 @@ libcrypto_ov97_srcs = files(
|
||||
|
||||
libcrypto_static = static_library('crypto_static',
|
||||
sources: libcrypto_static_srcs,
|
||||
c_args: libcrypto_c_args,
|
||||
nasm_args: asm_args,
|
||||
pic: false
|
||||
pic: false,
|
||||
include_directories: libcrypto_public_includes,
|
||||
dependencies: nitrosdk_dep
|
||||
)
|
||||
|
||||
libcrypto_ov97 = static_library('crypto_ov97',
|
||||
|
||||
69
lib/crypto/src/rc4.c
Normal file
69
lib/crypto/src/rc4.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "crypto/rc4.h"
|
||||
|
||||
#include <nitro/types.h>
|
||||
|
||||
void CRYPTO_RC4Init(CRYPTORC4Context *ctx, const void *key, u32 keyLength)
|
||||
{
|
||||
u8 *s;
|
||||
u8 id1, id2;
|
||||
int i;
|
||||
|
||||
if (keyLength > 16) {
|
||||
keyLength = 16;
|
||||
}
|
||||
|
||||
ctx->i = 0;
|
||||
ctx->j = 0;
|
||||
|
||||
s = ctx->s;
|
||||
|
||||
for (i = 0; i < RC4_S_SIZE; i++) {
|
||||
s[i] = i;
|
||||
}
|
||||
|
||||
id1 = id2 = 0;
|
||||
for (i = 0; i < RC4_S_SIZE; i++) {
|
||||
u8 tmp = s[i];
|
||||
id2 = (((u8 *)key)[id1] + tmp + id2);
|
||||
if (++id1 == (u8)keyLength) {
|
||||
id1 = 0;
|
||||
}
|
||||
s[i] = s[id2];
|
||||
s[id2] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void CRYPTO_RC4FastInit(CRYPTORC4FastContext *ctx, const void *key, u32 keyLength)
|
||||
{
|
||||
u32 *s;
|
||||
u32 id1, id2;
|
||||
int i;
|
||||
|
||||
if (keyLength > 16) {
|
||||
keyLength = 16;
|
||||
}
|
||||
|
||||
ctx->i = 0;
|
||||
ctx->j = 0;
|
||||
|
||||
s = ctx->s;
|
||||
|
||||
for (i = 0; i < RC4_S_SIZE; i++) {
|
||||
s[i] = i;
|
||||
}
|
||||
|
||||
id1 = id2 = 0;
|
||||
for (i = 0; i < RC4_S_SIZE; i++) {
|
||||
u32 tmp = s[i];
|
||||
id2 = (((u8 *)key)[id1] + tmp + id2) % RC4_S_SIZE;
|
||||
if (++id1 == keyLength) {
|
||||
id1 = 0;
|
||||
}
|
||||
s[i] = s[id2];
|
||||
s[id2] = tmp;
|
||||
}
|
||||
|
||||
for (i = 0; i < RC4_S_SIZE; i++) {
|
||||
s[i] <<= 24;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user