mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
内部static領域をworkに含めた (合計513KB必要)
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1160 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
parent
ce82cbc906
commit
53786510bb
@ -54,7 +54,8 @@ static const u8 hmac_key[] = DHT_HMAC_KEY;
|
|||||||
|
|
||||||
static DHTReadFunc ReadFunc;
|
static DHTReadFunc ReadFunc;
|
||||||
static void* readArg;
|
static void* readArg;
|
||||||
#define PAGE_SIZE 512
|
static DHTPhase2Work* p2work;
|
||||||
|
static int fatPage;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
自家製bsearch
|
自家製bsearch
|
||||||
@ -303,42 +304,48 @@ BOOL DHT_CheckHashPhase1(const u8* hash, const ROM_Header_Short* pROMHeader, con
|
|||||||
対象領域の読み込みとチェックを行う
|
対象領域の読み込みとチェックを行う
|
||||||
FSを用いたテストの場合とCARDアプリの場合で異なる
|
FSを用いたテストの場合とCARDアプリの場合で異なる
|
||||||
*/
|
*/
|
||||||
static BOOL ImageHMACSHA1Update(SVCHMACSHA1Context* ctx, s32 offset, s32 length, void* buffer)
|
static BOOL ImageHMACSHA1Update(SVCHMACSHA1Context* ctx, s32 offset, s32 length)
|
||||||
{
|
{
|
||||||
if ( !ReadFunc(buffer, offset, length, readArg) )
|
if ( !p2work )
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
SVC_HMACSHA1Update(ctx, buffer, (u32)length);
|
if ( !ReadFunc(p2work->buffer, offset, length, readArg) )
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
SVC_HMACSHA1Update(ctx, p2work->buffer, (u32)length);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL GetOverlayInfo(int no, int fat_offset, int* pOffset, int* pLength)
|
static BOOL GetOverlayInfo(int no, int fat_offset, int* pOffset, int* pLength)
|
||||||
{
|
{
|
||||||
ROM_FAT *fat;
|
ROM_FAT *fat;
|
||||||
static u8 fat_cache[PAGE_SIZE*2];
|
int page = (fat_offset + no * (s32)sizeof(ROM_FAT)) / DHT_FAT_PAGE_SIZE;
|
||||||
static int last_page = 0;
|
if ( !p2work )
|
||||||
int page = (fat_offset + no * (s32)sizeof(ROM_FAT)) / PAGE_SIZE;
|
|
||||||
if ( last_page != page )
|
|
||||||
{
|
{
|
||||||
if ( last_page + 1 == page ) // 1ページはキャッシュ済み
|
return FALSE;
|
||||||
|
}
|
||||||
|
if ( fatPage != page )
|
||||||
{
|
{
|
||||||
MI_CpuCopy8( &fat_cache[PAGE_SIZE], &fat_cache[0], PAGE_SIZE );
|
if ( fatPage + 1 == page ) // 1ページはキャッシュ済み
|
||||||
if ( !ReadFunc(&fat_cache[PAGE_SIZE], (page+1) * PAGE_SIZE, PAGE_SIZE, readArg) )
|
{
|
||||||
|
MI_CpuCopy8( &p2work->fatCache[DHT_FAT_PAGE_SIZE], &p2work->fatCache[0], DHT_FAT_PAGE_SIZE );
|
||||||
|
if ( !ReadFunc(&p2work->fatCache[DHT_FAT_PAGE_SIZE], (page+1) * DHT_FAT_PAGE_SIZE, DHT_FAT_PAGE_SIZE, readArg) )
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // 通常は2ページ読み
|
else // 通常は2ページ読み
|
||||||
{
|
{
|
||||||
if ( !ReadFunc(fat_cache, page * PAGE_SIZE, PAGE_SIZE*2, readArg) )
|
if ( !ReadFunc(p2work->fatCache, page * DHT_FAT_PAGE_SIZE, DHT_FAT_CACHE_SIZE, readArg) )
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last_page = page;
|
fatPage = page;
|
||||||
}
|
}
|
||||||
fat = (ROM_FAT*)(fat_cache + fat_offset + no * sizeof(ROM_FAT) - page * PAGE_SIZE);
|
fat = (ROM_FAT*)(p2work->fatCache + fat_offset + no * sizeof(ROM_FAT) - page * DHT_FAT_PAGE_SIZE);
|
||||||
if ( pOffset )
|
if ( pOffset )
|
||||||
{
|
{
|
||||||
*pOffset = (s32)fat->top.offset;
|
*pOffset = (s32)fat->top.offset;
|
||||||
@ -350,7 +357,7 @@ static BOOL GetOverlayInfo(int no, int fat_offset, int* pOffset, int* pLength)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, void* buffer, DHTReadFunc func, void* arg)
|
BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, DHTPhase2Work* work, DHTReadFunc func, void* arg)
|
||||||
{
|
{
|
||||||
int overlay_nums = (int)(pROMHeader->main_ovt_size / sizeof(ROM_OVT));
|
int overlay_nums = (int)(pROMHeader->main_ovt_size / sizeof(ROM_OVT));
|
||||||
u8 md[20];
|
u8 md[20];
|
||||||
@ -362,26 +369,28 @@ BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, voi
|
|||||||
int total_sectors;
|
int total_sectors;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if ( !func )
|
if ( !func || !work )
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
ReadFunc = func;
|
ReadFunc = func;
|
||||||
readArg = arg;
|
readArg = arg;
|
||||||
|
p2work = work;
|
||||||
|
fatPage = -2; // default value = out of range
|
||||||
|
|
||||||
// 準備
|
// 準備
|
||||||
PROFILE_COUNT();
|
PROFILE_COUNT();
|
||||||
SVC_HMACSHA1Init(&ctx, hmac_key, sizeof(hmac_key));
|
SVC_HMACSHA1Init(&ctx, hmac_key, sizeof(hmac_key));
|
||||||
// OVT
|
// OVT
|
||||||
PROFILE_COUNT();
|
PROFILE_COUNT();
|
||||||
if ( !ImageHMACSHA1Update(&ctx, (s32)pROMHeader->main_ovt_offset, (s32)pROMHeader->main_ovt_size, buffer) )
|
if ( !ImageHMACSHA1Update(&ctx, (s32)pROMHeader->main_ovt_offset, (s32)pROMHeader->main_ovt_size) )
|
||||||
{
|
{
|
||||||
OS_TPrintf("Cannot calc HMAC-SHA1 for OVT.\n");
|
OS_TPrintf("Cannot calc HMAC-SHA1 for OVT.\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
// FAT
|
// FAT
|
||||||
PROFILE_COUNT();
|
PROFILE_COUNT();
|
||||||
if ( !ImageHMACSHA1Update(&ctx, (s32)pROMHeader->fat_offset, overlay_nums * (s32)sizeof(ROM_FAT), buffer) )
|
if ( !ImageHMACSHA1Update(&ctx, (s32)pROMHeader->fat_offset, overlay_nums * (s32)sizeof(ROM_FAT)) )
|
||||||
{
|
{
|
||||||
OS_TPrintf("Cannot calc HMAC-SHA1 for %d of FAT.\n", overlay_nums);
|
OS_TPrintf("Cannot calc HMAC-SHA1 for %d of FAT.\n", overlay_nums);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -404,7 +413,7 @@ BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, voi
|
|||||||
{
|
{
|
||||||
length = max_sectors;
|
length = max_sectors;
|
||||||
}
|
}
|
||||||
if ( !ImageHMACSHA1Update(&ctx, offset, length * 512, buffer) )
|
if ( !ImageHMACSHA1Update(&ctx, offset, length * 512) )
|
||||||
{
|
{
|
||||||
OS_TPrintf("Cannot calc HMAC-SHA1 for %d of overlay.\n", i);
|
OS_TPrintf("Cannot calc HMAC-SHA1 for %d of overlay.\n", i);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|||||||
@ -168,7 +168,7 @@ static CardSecureModeFunction s_funcTable[] = {
|
|||||||
#ifdef DHT_TEST
|
#ifdef DHT_TEST
|
||||||
#include <sysmenu/dht/dht.h>
|
#include <sysmenu/dht/dht.h>
|
||||||
DHTFile* dht;
|
DHTFile* dht;
|
||||||
static void* ov_buffer = (void*)0x02e80000;
|
static DHTPhase2Work* p2work = (void*)0x02e80000;
|
||||||
static BOOL ReadImage(void* dest, s32 offset, s32 length, void* arg)
|
static BOOL ReadImage(void* dest, s32 offset, s32 length, void* arg)
|
||||||
{
|
{
|
||||||
HotSwState retval = ReadPageGame((CardBootData*)arg, (u32)offset, dest, (u32)length);
|
HotSwState retval = ReadPageGame((CardBootData*)arg, (u32)offset, dest, (u32)length);
|
||||||
@ -971,7 +971,7 @@ static HotSwState LoadStaticModule(void)
|
|||||||
OS_TPrintf(" Done.\n");
|
OS_TPrintf(" Done.\n");
|
||||||
|
|
||||||
OS_TPrintf("DHT Pahse2...");
|
OS_TPrintf("DHT Pahse2...");
|
||||||
if ( !DHT_CheckHashPhase2(hash1, &s_cbData.pBootSegBuf->rh.s, ov_buffer, ReadImage, &s_cbData) )
|
if ( !DHT_CheckHashPhase2(hash1, &s_cbData.pBootSegBuf->rh.s, p2work, ReadImage, &s_cbData) )
|
||||||
{
|
{
|
||||||
OS_TPrintf(" Failed.\n");
|
OS_TPrintf(" Failed.\n");
|
||||||
return HOTSW_HASH_CHECK_ERROR;
|
return HOTSW_HASH_CHECK_ERROR;
|
||||||
|
|||||||
@ -36,7 +36,7 @@ static DHTFile *const dht = (DHTFile*)dht_buffer;
|
|||||||
/*
|
/*
|
||||||
Phase2用バッファ
|
Phase2用バッファ
|
||||||
*/
|
*/
|
||||||
static u8 ov_buffer[DHT_OVERLAY_MAX];
|
static DHTPhase2Work p2work;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
実際にはアドレス固定
|
実際にはアドレス固定
|
||||||
@ -159,7 +159,7 @@ static BOOL CheckValidation(FSFile* fp)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
// ハッシュ計算 (2) - 隠蔽は難しいか
|
// ハッシュ計算 (2) - 隠蔽は難しいか
|
||||||
if ( !DHT_CheckHashPhase2(db->hash[1], &rom_header, ov_buffer, ReadImage, fp) )
|
if ( !DHT_CheckHashPhase2(db->hash[1], &rom_header, &p2work, ReadImage, fp) )
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,16 @@
|
|||||||
#include <twl/os/common/format_rom.h>
|
#include <twl/os/common/format_rom.h>
|
||||||
#include <sysmenu/dht/dht_format.h>
|
#include <sysmenu/dht/dht_format.h>
|
||||||
|
|
||||||
|
#define DHT_FAT_PAGE_SIZE 512
|
||||||
|
#define DHT_FAT_CACHE_SIZE (DHT_FAT_PAGE_SIZE * 2)
|
||||||
|
|
||||||
|
typedef struct DHTPhase2Work
|
||||||
|
{
|
||||||
|
u32 buffer[DHT_OVERLAY_MAX/sizeof(u32)]; // multiple usage
|
||||||
|
u8 fatCache[DHT_FAT_CACHE_SIZE]; // for fat cache only
|
||||||
|
}
|
||||||
|
DHTPhase2Work;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -137,11 +147,11 @@ BOOL DHT_CheckHashPhase1(const u8* hash, const ROM_Header_Short* pROMHeader, con
|
|||||||
fctx (FS版) FSFile構造体へのポインタ
|
fctx (FS版) FSFile構造体へのポインタ
|
||||||
(CARD版) dma番号をvoid*にキャストしたもの
|
(CARD版) dma番号をvoid*にキャストしたもの
|
||||||
(HOTSW版) CardBootData構造体へのポインタ
|
(HOTSW版) CardBootData構造体へのポインタ
|
||||||
buffer 本APIで使用するワーク (DHT_OVERLAY_MAXだけ必要)
|
work 本APIで使用するワーク (DHT_OVERLAY_MAXだけ必要)
|
||||||
|
|
||||||
Returns: 問題なければTRUE
|
Returns: 問題なければTRUE
|
||||||
*---------------------------------------------------------------------------*/
|
*---------------------------------------------------------------------------*/
|
||||||
BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, void* buffer, DHTReadFunc func, void* arg);
|
BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, DHTPhase2Work* work, DHTReadFunc func, void* arg);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user