diff --git a/Makefile.common b/Makefile.common index ba808836..809e6f19 100644 --- a/Makefile.common +++ b/Makefile.common @@ -41,13 +41,6 @@ endif INCFLAGS := -I$(CORE_DIR) -I$(MEDNAFEN_DIR) -I$(MEDNAFEN_DIR)/include -I$(MEDNAFEN_DIR)/intl -I$(MEDNAFEN_DIR)/hw_sound -I$(MEDNAFEN_DIR)/hw_cpu -I$(MEDNAFEN_DIR)/hw_misc -I$(LIBRETRO_DIR)/include -I$(DEPS_DIR)/zlib -SOURCES_C += $(LIBKIRK_DIR)/aes.c \ - $(LIBKIRK_DIR)/amctrl.c \ - $(LIBKIRK_DIR)/bn.c \ - $(LIBKIRK_DIR)/des.c \ - $(LIBKIRK_DIR)/ec.c \ - $(LIBKIRK_DIR)/kirk_engine.c \ - $(LIBKIRK_DIR)/sha1.c SOURCES_C += $(DEPS_DIR)/zlib/adler32.c \ $(DEPS_DIR)/zlib/compress.c \ @@ -199,7 +192,15 @@ SOURCES_C += \ SOURCES_CXX += $(CORE_DIR)/rsx/rsx_intf.cpp ifneq ($(STATIC_LINKING), 1) -SOURCES_C += $(LIBRETRO_DIR)/streams/file_stream.c +SOURCES_C += $(LIBRETRO_DIR)/streams/file_stream.c \ + $(LIBRETRO_DIR)/string/stdstring.c +SOURCES_C += $(LIBKIRK_DIR)/aes.c \ + $(LIBKIRK_DIR)/amctrl.c \ + $(LIBKIRK_DIR)/bn.c \ + $(LIBKIRK_DIR)/des.c \ + $(LIBKIRK_DIR)/ec.c \ + $(LIBKIRK_DIR)/kirk_engine.c \ + $(LIBKIRK_DIR)/sha1.c ifeq ($(NEED_THREADING), 1) SOURCES_C += $(LIBRETRO_DIR)/rthreads/rthreads.c @@ -209,4 +210,3 @@ endif endif SOURCES_C += $(LIBRETRO_DIR)/file/retro_stat.c -SOURCES_C += $(LIBRETRO_DIR)/string/stdstring.c diff --git a/beetle_psx_griffin.cpp b/beetle_psx_griffin.cpp index a500163a..b25fd723 100644 --- a/beetle_psx_griffin.cpp +++ b/beetle_psx_griffin.cpp @@ -31,6 +31,7 @@ #include "mednafen/cdrom/CDAccess.cpp" #include "mednafen/cdrom/CDAccess_Image.cpp" #include "mednafen/cdrom/CDAccess_CCD.cpp" +#include "mednafen/cdrom/CDAccess_PBP.cpp" #include "mednafen/cdrom/SimpleFIFO.cpp" #include "mednafen/cdrom/audioreader.cpp" #include "mednafen/cdrom/cdromif.cpp" diff --git a/beetle_psx_griffin_c.c b/beetle_psx_griffin_c.c index 17c3e30f..aca491d2 100644 --- a/beetle_psx_griffin_c.c +++ b/beetle_psx_griffin_c.c @@ -34,3 +34,11 @@ #include "mednafen/cdrom/recover-raw.c" #include "mednafen/cdrom/galois.c" #endif + +#include "deps/libkirk/aes.c" +#include "deps/libkirk/amctrl.c" +#include "deps/libkirk/bn.c" +#include "deps/libkirk/des.c" +#include "deps/libkirk/ec.c" +#include "deps/libkirk/kirk_engine.c" +#include "deps/libkirk/sha1.c" diff --git a/deps/libkirk/key_vault.h b/deps/libkirk/key_vault.h index edafd66a..ddc86ce2 100644 --- a/deps/libkirk/key_vault.h +++ b/deps/libkirk/key_vault.h @@ -55,8 +55,8 @@ static u8 kirk16_key[0x10] = {0x47, 0x5E, 0x09, 0xF4, 0xA2, 0x37, 0xDA, 0x9B, 0 /* ECC Curves for Kirk 1 and Kirk 0x11 */ // Common Curve paramters p and a -static u8 ec_p[0x14] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; -static u8 ec_a[0x14] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC}; // mon +static u8 keyvault_ec_p[0x14] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +static u8 keyvault_ec_a[0x14] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC}; // mon // Kirk 0xC,0xD,0x10,0x11,(likely 0x12)- Unique curve parameters for b, N, and base point G for Kirk 0xC,0xD,0x10,0x11,(likely 0x12) service // Since public key is variable, it is not specified here diff --git a/deps/libkirk/kirk_engine.c b/deps/libkirk/kirk_engine.c index 4c2c3232..586f70dd 100644 --- a/deps/libkirk/kirk_engine.c +++ b/deps/libkirk/kirk_engine.c @@ -332,7 +332,7 @@ int kirk_CMD1(u8* outbuff, u8* inbuff, int size) KIRK_CMD1_ECDSA_HEADER* eheader = (KIRK_CMD1_ECDSA_HEADER*) inbuff; u8 kirk1_pub[40]; u8 header_hash[20];u8 data_hash[20]; - ecdsa_set_curve(ec_p,ec_a,ec_b1,ec_N1,Gx1,Gy1); + ecdsa_set_curve(keyvault_ec_p,keyvault_ec_a,ec_b1,ec_N1,Gx1,Gy1); memcpy(kirk1_pub,Px1,20); memcpy(kirk1_pub+20,Py1,20); ecdsa_set_pub(kirk1_pub); @@ -470,7 +470,7 @@ int kirk_CMD12(u8 * outbuff, int outsize) KIRK_CMD12_BUFFER * keypair = (KIRK_CMD12_BUFFER *) outbuff; if (outsize != 0x3C) return KIRK_INVALID_SIZE; - ecdsa_set_curve(ec_p,ec_a,ec_b2,ec_N2,Gx2,Gy2); + ecdsa_set_curve(keyvault_ec_p,keyvault_ec_a,ec_b2,ec_N2,Gx2,Gy2); k[0] = 0; kirk_CMD14(k+1,0x14); @@ -489,7 +489,7 @@ int kirk_CMD13(u8 * outbuff, int outsize,u8 * inbuff, int insize) if (outsize != 0x28) return KIRK_INVALID_SIZE; if (insize != 0x3C) return KIRK_INVALID_SIZE; - ecdsa_set_curve(ec_p,ec_a,ec_b2,ec_N2,Gx2,Gy2); + ecdsa_set_curve(keyvault_ec_p,keyvault_ec_a,ec_b2,ec_N2,Gx2,Gy2); ecdsa_set_pub((u8*)pointmult->public_key.x); memcpy(k+1,pointmult->multiplier,0x14); ec_pub_mult(k, outbuff); @@ -560,7 +560,7 @@ int kirk_CMD16(u8 * outbuff, int outsize, u8 * inbuff, int insize) // Clear out the padding for safety memset(&dec_private[0x14], 0, 0xC); - ecdsa_set_curve(ec_p,ec_a,ec_b2,ec_N2,Gx2,Gy2); + ecdsa_set_curve(keyvault_ec_p,keyvault_ec_a,ec_b2,ec_N2,Gx2,Gy2); ecdsa_set_priv(dec_private); ecdsa_sign(signbuf->message_hash,sig->r, sig->s); @@ -573,7 +573,7 @@ int kirk_CMD17(u8 * inbuff, int insize) if (insize != 0x64) return KIRK_INVALID_SIZE; - ecdsa_set_curve(ec_p,ec_a,ec_b2,ec_N2,Gx2,Gy2); + ecdsa_set_curve(keyvault_ec_p,keyvault_ec_a,ec_b2,ec_N2,Gx2,Gy2); ecdsa_set_pub(sig->public_key.x); if (ecdsa_verify(sig->message_hash,sig->signature.r,sig->signature.s)) { @@ -600,4 +600,4 @@ int sceUtilsBufferCopyWithRange(u8* outbuff, int outsize, u8* inbuff, int insize case KIRK_CMD_ECDSA_VERIFY: return kirk_CMD17(inbuff, insize); break; } return -1; -} \ No newline at end of file +} diff --git a/libretro-common/rthreads/rthreads.c b/libretro-common/rthreads/rthreads.c index 7d6767cd..db5f3e71 100644 --- a/libretro-common/rthreads/rthreads.c +++ b/libretro-common/rthreads/rthreads.c @@ -467,3 +467,7 @@ bool scond_wait_timeout(scond_t *cond, slock_t *lock, int64_t timeout_us) return (ret == 0); #endif } + +#ifdef __unix__ +#undef _POSIX_C_SOURCE +#endif diff --git a/mednafen/cdrom/l-ec.c b/mednafen/cdrom/l-ec.c index 05f85769..59701a3e 100644 --- a/mednafen/cdrom/l-ec.c +++ b/mednafen/cdrom/l-ec.c @@ -26,7 +26,7 @@ #include #include -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#include /*** *** Mapping between cd frame and parity vectors