From c7ad1473782bf65c3c042039589fe0b05361319d Mon Sep 17 00:00:00 2001 From: yosiokat Date: Mon, 12 May 2008 11:16:27 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=9A=E3=82=A2=E3=83=AC=E3=83=B3=E3=82=BF?= =?UTF-8?q?=E3=83=AB=E3=82=B3=E3=83=B3=E3=83=88=E3=83=AD=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E9=96=A2=E9=80=A3=E3=81=AE=E4=B8=8B=E8=A8=98API=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=80=82=20=E3=80=80=E5=95=8F=E3=81=84?= =?UTF-8?q?=E5=90=88=E3=82=8F=E3=81=9B=E3=82=B3=E3=83=BC=E3=83=89=E7=AE=97?= =?UTF-8?q?=E5=87=BA=EF=BC=9A=20SYSM=5FCalcPCTLInquiryCode=20=E3=80=80?= =?UTF-8?q?=E3=83=9E=E3=82=B9=E3=82=BF=E3=83=BC=E3=82=AD=E3=83=BC=E7=AE=97?= =?UTF-8?q?=E5=87=BA=20=20=20=20=20=20=EF=BC=9A=20SYSM=5FCalcPCTLMasterKey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1317 b08762b0-b915-fc4b-9d8c-17b2551a87ff --- build/libraries_sysmenu/sysmenu/ARM9/Makefile | 1 + .../sysmenu/common/src/masterkey.c | 110 ++++++++++++++++++ .../sysmenu/sysmenu_lib/common/sysmenu_api.h | 4 + 3 files changed, 115 insertions(+) create mode 100644 build/libraries_sysmenu/sysmenu/common/src/masterkey.c diff --git a/build/libraries_sysmenu/sysmenu/ARM9/Makefile b/build/libraries_sysmenu/sysmenu/ARM9/Makefile index bfa633cb..df505ac3 100644 --- a/build/libraries_sysmenu/sysmenu/ARM9/Makefile +++ b/build/libraries_sysmenu/sysmenu/ARM9/Makefile @@ -39,6 +39,7 @@ SRCS = sysmenu_lib.c \ ../common/src/pxi.c \ ../common/src/mountInfo.c \ ../common/src/decodeAES.c \ + ../common/src/masterkey.c \ $(REVISION_SRC) diff --git a/build/libraries_sysmenu/sysmenu/common/src/masterkey.c b/build/libraries_sysmenu/sysmenu/common/src/masterkey.c new file mode 100644 index 00000000..c30fb93b --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/common/src/masterkey.c @@ -0,0 +1,110 @@ +/*---------------------------------------------------------------------------* + Project: Sample Test + File: test.c + + Copyright 2005 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + *---------------------------------------------------------------------------*/ + +#include +#include + +#define CODE_LENGTH 8 + +static u32 Crc32Table[0x100]; + +// Forward references +u32 CalcMasterkey(const u8 *src); + +static void Crc32Init(void) +{ + u32 i, j; + u32 poly = 0xedb88320; + u32 crc; + + for (i = 0; i < 0x100; i++) { + crc = i; + for (j = 8; j > 0; j--) { + if (crc & 1) { + crc = (crc >> 1) ^ poly; + } else { + crc >>= 1; + } + } + Crc32Table[i] = crc; + } +} + +static u32 CalcCrc32(const u8 *src, u32 len) +{ + u32 crc = 0xffffffff; + + while (len) { + crc = ((crc >> 8) & 0xffffffff) ^ Crc32Table[(crc ^ *src) & 0xff]; + src++; + len--; + } + return crc; +} + +u32 CalcMasterkey(const u8 *src) +{ + static u8 initFlag = 0; + u32 key; + + if (initFlag == 0) { + Crc32Init(); + initFlag = 1; + } + + key = ((CalcCrc32(src, CODE_LENGTH) ^ 0xaaaa) + 5313) % 100000; + + return key; +} + +//====================================================================== +// +// マスターキー算出 +// +//====================================================================== +u32 SYSM_CalcPCTLMasterKey( void ) +{ + u32 masterKey; + u32 inquiryCode = SYSM_CalcPCTLInquiryCode(); + u8 arg[ 9 ]; + RTCDate date; + RTC_Init(); + RTC_GetDate( &date ); + STD_TSPrintf( (char *)arg, "%02d%02d%04d", date.month, date.day, inquiryCode % 10000 ); + masterKey = CalcMasterkey( arg ); + OS_TPrintf( "MasterKey : %05d\n", masterKey ); + return masterKey; +} + + +//====================================================================== +// +// ペアレンタルコントロール問い合わせ番号算出 +// +//====================================================================== +u32 SYSM_CalcPCTLInquiryCode( void ) +{ + int i; + u64 num = 0; + u8 *p = (u8 *)# + u8 macAddr[ 6 ]; + u32 inquiryCode; + OS_GetMacAddress( macAddr ); + for( i = 5; i >= 0; i-- ) { + *p++ = macAddr[ i ]; + } + inquiryCode = (u32)( num % 100000000UL ); + OS_TPrintf( "InquiryCode : %08d\n", inquiryCode ); + return inquiryCode; +} + diff --git a/include/sysmenu/sysmenu_lib/common/sysmenu_api.h b/include/sysmenu/sysmenu_lib/common/sysmenu_api.h index 8886c38d..b7be6e5f 100644 --- a/include/sysmenu/sysmenu_lib/common/sysmenu_api.h +++ b/include/sysmenu/sysmenu_lib/common/sysmenu_api.h @@ -129,6 +129,10 @@ extern BOOL SYSM_IsLeapYear100( u32 year ); // // スリープモード extern void SYSM_GoSleepMode( void ); // スリープモードへの遷移 +// ペアレンタルコントロール問い合わせ +u32 SYSM_CalcPCTLInquiryCode( void ); // 問い合わせコード(10進8桁)算出 +u32 SYSM_CalcPCTLMasterKey( void ); // マスターキー  (10進5桁)算出 + #endif // 状態チェック