summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/core.c4
-rw-r--r--src/common/des.c14
-rw-r--r--src/common/des.h14
-rw-r--r--src/common/grfio.c8
4 files changed, 29 insertions, 11 deletions
diff --git a/src/common/core.c b/src/common/core.c
index e6b522926..ce92a77e3 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -25,6 +25,7 @@
#include "common/cbasetypes.h"
#include "common/console.h"
+#include "common/des.h"
#include "common/db.h"
#include "common/memmgr.h"
#include "common/mmo.h"
@@ -253,6 +254,7 @@ void core_defaults(void) {
malloc_defaults();
showmsg_defaults();
cmdline_defaults();
+ des_defaults();
#ifndef MINICORE
libconfig_defaults();
sql_defaults();
diff --git a/src/common/des.c b/src/common/des.c
index ce64309f3..c811dd96c 100644
--- a/src/common/des.c
+++ b/src/common/des.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -24,6 +24,9 @@
#include "common/cbasetypes.h"
+struct des_interface des_s;
+struct des_interface *des;
+
/// DES (Data Encryption Standard) algorithm, modified version.
/// @see http://www.eathena.ws/board/index.php?autocom=bugtracker&showbug=5099.
/// @see http://en.wikipedia.org/wiki/Data_Encryption_Standard
@@ -232,5 +235,12 @@ void des_decrypt(unsigned char* data, size_t size)
size_t i;
for( i = 0; i*8 < size; i += 8 )
- des_decrypt_block(p);
+ des->decrypt_block(p);
+}
+
+void des_defaults(void)
+{
+ des = &des_s;
+ des->decrypt = des_decrypt;
+ des->decrypt_block = des_decrypt_block;
}
diff --git a/src/common/des.h b/src/common/des.h
index d62b5cc49..e7460e9fd 100644
--- a/src/common/des.h
+++ b/src/common/des.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -21,14 +21,20 @@
#ifndef COMMON_DES_H
#define COMMON_DES_H
-#include "common/cbasetypes.h"
+#include "common/hercules.h"
/// One 64-bit block.
typedef struct BIT64 { uint8_t b[8]; } BIT64;
+struct des_interface {
+ void (*decrypt_block) (BIT64* block);
+ void (*decrypt) (unsigned char* data, size_t size);
+};
+
#ifdef HERCULES_CORE
-void des_decrypt_block(BIT64* block);
-void des_decrypt(unsigned char* data, size_t size);
+void des_defaults(void);
#endif // HERCULES_CORE
+HPShared struct des_interface *des;
+
#endif // COMMON_DES_H
diff --git a/src/common/grfio.c b/src/common/grfio.c
index c6e47d357..c24f2aee5 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -162,7 +162,7 @@ static void grf_decode_header(unsigned char* buf, size_t len)
// first 20 blocks are all des-encrypted
for( i = 0; i < 20 && i < nblocks; ++i )
- des_decrypt_block(&p[i]);
+ des->decrypt_block(&p[i]);
// the rest is plaintext, done.
}
@@ -176,7 +176,7 @@ static void grf_decode_full(unsigned char* buf, size_t len, int cycle)
// first 20 blocks are all des-encrypted
for( i = 0; i < 20 && i < nblocks; ++i )
- des_decrypt_block(&p[i]);
+ des->decrypt_block(&p[i]);
// after that only one of every 'dcycle' blocks is des-encrypted
dcycle = cycle;
@@ -190,7 +190,7 @@ static void grf_decode_full(unsigned char* buf, size_t len, int cycle)
{
if( i % dcycle == 0 )
{// decrypt block
- des_decrypt_block(&p[i]);
+ des->decrypt_block(&p[i]);
continue;
}
@@ -504,7 +504,7 @@ static char* decode_filename(unsigned char* buf, int len)
int lop;
for(lop=0;lop<len;lop+=8) {
NibbleSwap(&buf[lop],8);
- des_decrypt(&buf[lop],8);
+ des->decrypt(&buf[lop],8);
}
return (char*)buf;
}