mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
TwlSDK 3286-3305
AESの仕様変更に対応 git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@413 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
parent
89fd2d6640
commit
cb9c7ea513
@ -85,7 +85,6 @@ FIRM_LIBS_BASE ?= \
|
||||
libpxi \
|
||||
libfs \
|
||||
libfatfs \
|
||||
libaes \
|
||||
libmi \
|
||||
|
||||
else # ($(CODEGEN_PROC),ARM7)
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -18,8 +18,6 @@
|
||||
#include <firm/aes.h>
|
||||
#include <firm/pxi.h>
|
||||
|
||||
#include <twl/aes/ARM7/lo.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 =====
|
||||
@ -21,7 +21,7 @@ include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = ARM9 ARM7
|
||||
SUBDIRS = ARM7
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -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 <firm/aes.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@
|
||||
|
||||
#include <firm.h>
|
||||
#include <twl/os/common/format_rom.h>
|
||||
#include <twl/aes/ARM7/lo.h>
|
||||
#include <rtfs.h>
|
||||
#include <devices/sdif_reg.h>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
#include <symbols.h>
|
||||
#include <firm.h>
|
||||
#include <rtfs.h>
|
||||
#include <twl/aes/common/aes.h>
|
||||
|
||||
//#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
|
||||
|
||||
@ -429,107 +429,8 @@ BOOL FS_LoadStatic( void )
|
||||
|
||||
/*
|
||||
以下、LoadBufferを使わない版 (通常FS APIを使用する)
|
||||
!!!! AESの通信バッファをメインメモリにおかないといけない! (pending)
|
||||
AES非対応!!
|
||||
*/
|
||||
#include <twl/aes.h>
|
||||
|
||||
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;
|
||||
|
||||
@ -19,10 +19,11 @@
|
||||
|
||||
#define PXI_FIFO_TAG_DATA PXI_FIFO_TAG_USER_0
|
||||
|
||||
#include <twl/aes/common/type.h>
|
||||
#include <firm/aes/common/aes_util.h>
|
||||
#include <twl/aes/common/types.h>
|
||||
|
||||
#ifdef SDK_ARM7
|
||||
#include <twl/aes/ARM7/hi.h>
|
||||
#include <twl/aes/ARM7/lo.h>
|
||||
#include <firm/aes/ARM7/aes_init.h>
|
||||
#include <firm/aes/ARM7/aes_ids.h>
|
||||
#else // !SDK_ARM7
|
||||
|
||||
@ -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
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
ŠÖ<EFBFBD>”’è‹`
|
||||
*---------------------------------------------------------------------------*/
|
||||
void AESi_AddCounter(AESCounter* pCounter, u32 nums);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* TWL_AES_AES_UTIL_H_ */
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user