diff --git a/build/buildtools/commondefs.firm b/build/buildtools/commondefs.firm index eb4624c8..b9fe6a7b 100644 --- a/build/buildtools/commondefs.firm +++ b/build/buildtools/commondefs.firm @@ -85,7 +85,6 @@ FIRM_LIBS_BASE ?= \ libpxi \ libfs \ libfatfs \ - libaes \ libmi \ else # ($(CODEGEN_PROC),ARM7) diff --git a/build/libraries/aes/ARM7/Makefile b/build/libraries/aes/ARM7/Makefile index e407dbee..810b504f 100644 --- a/build/libraries/aes/ARM7/Makefile +++ b/build/libraries/aes/ARM7/Makefile @@ -28,11 +28,10 @@ TWL_CODEGEN_ALL ?= TRUE # Codegen for sub processer TWL_PROC = ARM7 -SRCDIR = . ../common +SRCDIR = . SRCS = \ aes_init.c \ - aes_util.c \ TARGET_LIB = libaes_sp$(FIRM_LIBSUFFIX).a diff --git a/build/libraries/aes/ARM7/aes_init.c b/build/libraries/aes/ARM7/aes_init.c index a75cc71e..94f9cba5 100644 --- a/build/libraries/aes/ARM7/aes_init.c +++ b/build/libraries/aes/ARM7/aes_init.c @@ -18,8 +18,6 @@ #include #include -#include - /*---------------------------------------------------------------------------* Name: AESi_InitKeysForApp @@ -32,7 +30,7 @@ *---------------------------------------------------------------------------*/ void AESi_InitKeysForApp( u8 game_code[4] ) { - AESi_WaitKey(); + AES_WaitKey(); reg_AES_AES_ID_A2 = AES_IDS_ID0_C(game_code); reg_AES_AES_ID_A3 = AES_IDS_ID0_D(game_code); @@ -52,7 +50,7 @@ void AESi_InitKeysForApp( u8 game_code[4] ) *---------------------------------------------------------------------------*/ void AESi_InitKeysForHard( u8 fuse[8] ) { - AESi_WaitKey(); + AES_WaitKey(); reg_AES_AES_ID_B2 = *(u32*)&fuse[4]; reg_AES_AES_ID_B3 = *(u32*)&fuse[0]; @@ -71,7 +69,7 @@ void AESi_InitKeysForHard( u8 fuse[8] ) *---------------------------------------------------------------------------*/ void AESi_ResetAesKey( void ) { - AESi_WaitKey(); + AES_WaitKey(); // set dummy without seed[3] reg_AES_AES_SEED_A0 = 1; @@ -119,13 +117,13 @@ void AESi_RecvSeed( BOOL developer_encrypt ) AESKey seed; // PXI_RecvDataByFifo( PXI_FIFO_TAG_DATA, &seed, AES_BLOCK_SIZE ); PXI_RecvStream( &seed, AES_BLOCK_SIZE ); - AESi_WaitKey(); + AES_WaitKey(); if ( developer_encrypt ) { - AESi_SetKeyA(&seed); // Direct + AES_SetKeyA(&seed); // Direct } else { - AESi_SetKeySeedA((AESKeySeed*)&seed); // APP + AES_SetKeySeedA((AESKeySeed*)&seed); // APP } } diff --git a/build/libraries/aes/ARM9/Makefile b/build/libraries/aes/ARM9/Makefile deleted file mode 100644 index 822f216d..00000000 --- a/build/libraries/aes/ARM9/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -#! make -f -#---------------------------------------------------------------------------- -# Project: TwlFirm - libraries - aes -# File: Makefile -# -# Copyright 2007 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. -# -# $Date:: $ -# $Rev$ -# $Author$ -#---------------------------------------------------------------------------- - -SUBDIRS = -SUBMAKES = - - -#---------------------------------------------------------------------------- - -# build ARM & THUMB libraries -TWL_CODEGEN_ALL ?= TRUE - -SRCDIR = . ../common - -SRCS = \ - aes_util.c \ - -TARGET_LIB = libaes$(FIRM_LIBSUFFIX).a - -#---------------------------------------------------------------------------- - -include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs - -INSTALL_TARGETS = $(TARGETS) -INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) - - -#---------------------------------------------------------------------------- - -do-build: $(TARGETS) - -include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules - -#===== End of Makefile ===== diff --git a/build/libraries/aes/Makefile b/build/libraries/aes/Makefile index bf4c4446..a9cca493 100644 --- a/build/libraries/aes/Makefile +++ b/build/libraries/aes/Makefile @@ -21,7 +21,7 @@ include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs #---------------------------------------------------------------------------- -SUBDIRS = ARM9 ARM7 +SUBDIRS = ARM7 #---------------------------------------------------------------------------- diff --git a/build/libraries/aes/common/aes_util.c b/build/libraries/aes/common/aes_util.c deleted file mode 100644 index 47e82986..00000000 --- a/build/libraries/aes/common/aes_util.c +++ /dev/null @@ -1,46 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlIPL - libraries - aes - File: aes_util.c - - Copyright 2007 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. - - $Date:: $ - $Rev$ - $Author$ - *---------------------------------------------------------------------------*/ - -#include - -/*---------------------------------------------------------------------------* - Name: AESi_AddCounter - - Description: calculate updated counter - - Arguments: pCounter pointer to the counter at offset 0 - nums offset in blocks (AES_BLOCK_SIZE) - - Returns: None - *---------------------------------------------------------------------------*/ -void AESi_AddCounter(AESCounter* pCounter, u32 nums) -{ - u32 data = 0; - int i; - for (i = 0; i < 16; i++) - { - data += pCounter->bytes[i] + (nums & 0xFF); - pCounter->bytes[i] = (u8)(data & 0xFF); - data >>= 8; - nums >>= 8; - if ( !data && !nums ) - { - break; - } - } -} - diff --git a/build/libraries/fatfs/ARM7/src/fatfs_firm.c b/build/libraries/fatfs/ARM7/src/fatfs_firm.c index 90da15e6..22b85a72 100644 --- a/build/libraries/fatfs/ARM7/src/fatfs_firm.c +++ b/build/libraries/fatfs/ARM7/src/fatfs_firm.c @@ -354,14 +354,14 @@ static u16 ReadAES(u32 block, void *dest, u16 count) /* AESのセットアップ&出力DMA設定 */ - AESi_Reset(); - AESi_Reset(); - AESi_DmaRecv( DMA_RECV, dest, (u32)(count * SECTOR_SIZE), NULL, NULL ); - AESi_SetCounter( &aesCounter ); - AESi_Run( AES_MODE_CTR, 0, (u32)(count * SECTOR_SIZE / AES_BLOCK_SIZE), NULL, NULL ); + AES_Reset(); + AES_Reset(); + AES_DmaRecv( DMA_RECV, dest, (u32)(count * SECTOR_SIZE), NULL, NULL ); + AES_SetCounter( &aesCounter ); + AES_Run( AES_MODE_CTR, 0, (u32)(count * (SECTOR_SIZE/AES_BLOCK_SIZE)), NULL, NULL ); // update for next read - AESi_AddCounter( &aesCounter, (u32)(count * SECTOR_SIZE / AES_BLOCK_SIZE) ); + AES_AddToCounter( &aesCounter, (u32)(count * (SECTOR_SIZE/AES_BLOCK_SIZE)) ); while ( count * SECTOR_SIZE > offset ) @@ -396,7 +396,7 @@ err: currentSector = 0xFFFFFFFF; #endif StopToRead(); - AESi_Reset(); + AES_Reset(); return SDCARD_ErrStatus; } diff --git a/build/libraries/fatfs/ARM7/src/fatfs_loader.c b/build/libraries/fatfs/ARM7/src/fatfs_loader.c index 9cebe4a3..c43b417d 100644 --- a/build/libraries/fatfs/ARM7/src/fatfs_loader.c +++ b/build/libraries/fatfs/ARM7/src/fatfs_loader.c @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -401,7 +400,7 @@ static AESCounter* FATFSi_GetCounter( u32 offset ) static AESCounter counter; MI_CpuCopy8( rh->s.main_static_digest, &counter, 16 ); - AESi_AddCounter( &counter, offset - rh->s.aes_target_rom_offset ); + AES_AddToCounter( &counter, (offset - rh->s.aes_target_rom_offset) / AES_BLOCK_SIZE ); return &counter; } @@ -442,8 +441,8 @@ static u32 FATFSi_SetupAES( u32 offset, u32 size ) { size = aes_end - offset; } - AESi_WaitKey(); - AESi_LoadKey( AES_KEY_SLOT_A ); + AES_WaitKey(); + AES_LoadKey( AES_KEY_SLOT_A ); FATFS_EnableAES( FATFSi_GetCounter( offset ) ); } else diff --git a/build/libraries/fs/ARM7/src/fs_firm.c b/build/libraries/fs/ARM7/src/fs_firm.c index 73d2613c..9947e8e4 100644 --- a/build/libraries/fs/ARM7/src/fs_firm.c +++ b/build/libraries/fs/ARM7/src/fs_firm.c @@ -18,7 +18,6 @@ #include #include #include -#include //#define WORKAROUND_NAND_2KB_BUG @@ -121,12 +120,12 @@ int FS_OpenSrl( void ) #define DMA_RECV 3 static void CopyWithAes( const void* src, void* dest, u32 size ) { - AESi_Reset(); - AESi_Reset(); - AESi_DmaSend( DMA_SEND, src, size, NULL, NULL ); - AESi_DmaRecv( DMA_RECV, dest, size, NULL, NULL ); - AESi_SetCounter( &aesCounter ); - AESi_Run( AES_MODE_CTR, 0, size / AES_BLOCK_SIZE, NULL, NULL ); + AES_Reset(); + AES_Reset(); + AES_DmaSend( DMA_SEND, src, size, NULL, NULL ); + AES_DmaRecv( DMA_RECV, dest, size, NULL, NULL ); + AES_SetCounter( &aesCounter ); + AES_Run( AES_MODE_CTR, 0, size / AES_BLOCK_SIZE, NULL, NULL ); AES_AddToCounter( &aesCounter, size / AES_BLOCK_SIZE ); MI_WaitNDma( DMA_RECV ); } @@ -155,7 +154,7 @@ static u32 GetTransferSize( u32 offset, u32 size ) { size = aes_end - offset; } - AESi_LoadKey( AES_KEY_SLOT_A ); + AES_LoadKey( AES_KEY_SLOT_A ); EnableAes( offset ); } else diff --git a/build/libraries/fs/ARM9/src/fs_firm.c b/build/libraries/fs/ARM9/src/fs_firm.c index 258b24ed..20b955c2 100644 --- a/build/libraries/fs/ARM9/src/fs_firm.c +++ b/build/libraries/fs/ARM9/src/fs_firm.c @@ -429,107 +429,8 @@ BOOL FS_LoadStatic( void ) /* 以下、LoadBufferを使わない版 (通常FS APIを使用する) - !!!! AESの通信バッファをメインメモリにおかないといけない! (pending) + AES非対応!! */ -#include - -static BOOL aesFlag; -static AESCounter aesCounter; -static u8* const aesBuffer = (u8*)HW_FIRM_FS_AES_BUFFER; // 0x2ff0000 - -static void AesCallback( AESResult result, void* arg ) -{ - BOOL* pBusyFlag = (BOOL*)arg; - *pBusyFlag = FALSE; - if (result != AES_RESULT_SUCCESS) - { - OS_TPrintf("Failed to decrypt by AES (%d)\n", result); - } -} - -static void CopyWithAes( const void* src, void* dest, u32 size ) -{ - volatile BOOL aesBusy = TRUE; - if ( AES_RESULT_SUCCESS == AES_CtrDecrypt( rh->s.developer_encrypt ? AES_KEY_TYPE_RAW : AES_KEY_TYPE_APP, - &aesCounter, src, size, dest, AesCallback, (void*)&aesBusy) ) - { - while (aesBusy) - { - } - } - AES_AddToCounter( &aesCounter, size / AES_BLOCK_SIZE ); -} - -static void EnableAes( u32 offset ) -{ - aesFlag = TRUE; - MI_CpuCopy8( rh->s.main_static_digest, &aesCounter, AES_BLOCK_SIZE ); - AES_AddToCounter( &aesCounter, (offset - rh->s.aes_target_rom_offset) / AES_BLOCK_SIZE ); -} -static void DisableAes( void ) -{ - aesFlag = FALSE; -} - -/*---------------------------------------------------------------------------* - Name: GetSrlTransferSize - - Description: get size to transfer once - - 一度に受信するサイズを返します。 - AESのセットアップもすべきです。 - - 転送範囲がAES領域をまたぐ場合は、境界までのサイズ (引数より - 小さなサイズ) を返します。 - makerom.TWLまたはIPLの使用に依存します。 - - Arguments: offset offset of region from head of ROM_Header - size size of region - - Returns: size to transfer once - *---------------------------------------------------------------------------*/ -static u32 GetSrlTransferSize( u32 offset, u32 size ) -{ - u32 aes_offset = rh->s.aes_target_rom_offset; - u32 aes_end = aes_offset + RoundUpModuleSize(rh->s.aes_target_size); - u32 end = offset + RoundUpModuleSize(size); - if ( rh->s.enable_aes ) - { - if ( offset >= aes_offset && offset < aes_end ) - { - if ( end > aes_end ) - { - size = aes_end - offset; - } - if ( size >= HW_FIRM_FS_AES_BUFFER_SIZE ) - { - size = HW_FIRM_FS_AES_BUFFER_SIZE; - } - if ( rh->s.developer_encrypt ) - { - AES_SetKey( AES_KEY_TYPE_RAW, FS_GetAesKeySeed() ); - } - else - { - AES_SetKey( AES_KEY_TYPE_APP, FS_GetAesKeySeed() ); - } - EnableAes( offset ); - } - else - { - if ( offset < aes_offset && offset + size > aes_offset ) - { - size = aes_offset - offset; - } - DisableAes(); - } - } - else - { - DisableAes(); - } - return size; -} /*---------------------------------------------------------------------------* Name: FS_LoadSrlModule @@ -558,22 +459,10 @@ BOOL FS_LoadSrlModule( FSFile *pFile, u8* dest, u32 offset, u32 size, const u8 d } while ( size > 0 ) { - u32 unit = GetSrlTransferSize( offset, size ); - if (aesFlag) + u32 unit = GetTransferSize( offset, size ); // AES対象ならうまく動かない + if ( !FS_ReadFile( pFile, dest, (s32)unit ) ) { - if ( !FS_ReadFile( pFile, aesBuffer, (s32)unit ) ) - { - return FALSE; - } - DC_FlushRange( aesBuffer, unit ); - CopyWithAes( aesBuffer, dest, unit ); - } - else - { - if ( !FS_ReadFile( pFile, dest, (s32)unit ) ) - { - return FALSE; - } + return FALSE; } dest += unit; offset += unit; diff --git a/include/firm/aes.h b/include/firm/aes.h index 13f1c4dc..98e63da4 100644 --- a/include/firm/aes.h +++ b/include/firm/aes.h @@ -19,10 +19,11 @@ #define PXI_FIFO_TAG_DATA PXI_FIFO_TAG_USER_0 -#include -#include +#include #ifdef SDK_ARM7 +#include +#include #include #include #else // !SDK_ARM7 diff --git a/include/firm/aes/common/aes_util.h b/include/firm/aes/common/aes_util.h deleted file mode 100644 index 3f36a086..00000000 --- a/include/firm/aes/common/aes_util.h +++ /dev/null @@ -1,35 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlIPL - AES - include - File: aes_util.h - - Copyright 2007 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. - - $Date:: 2007-09-06$ - $Rev$ - $Author$ - *---------------------------------------------------------------------------*/ - -#ifndef TWL_AES_AES_UTIL_H_ -#define TWL_AES_AES_UTIL_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/*---------------------------------------------------------------------------* - 関数定義 - *---------------------------------------------------------------------------*/ -void AESi_AddCounter(AESCounter* pCounter, u32 nums); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -/* TWL_AES_AES_UTIL_H_ */ -#endif