TwlIPL/build/libraries_sysmenu/sysmenu/ARM7/src/setAESKey.c
yosiokat 07841a7981 NANDファームでのAES種セットの調整。
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1277 b08762b0-b915-fc4b-9d8c-17b2551a87ff
2008-04-30 06:35:26 +00:00

133 lines
4.7 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*---------------------------------------------------------------------------*
Project: TwlIPL
File: setAESKey.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 <twl.h>
#include <twl/aes/ARM7/lo.h>
#include <firm/aes/ARM7/aes_init.h>
#include <firm/hw/ARM7/mmap_firm.h>
#include <firm/format/from_firm.h>
#include <firm/os/common/boot.h>
#include <sysmenu.h>
#include "internal_api.h"
// define data-----------------------------------------------------------------
// extern data-----------------------------------------------------------------
// function's prototype-------------------------------------------------------
// global variable-------------------------------------------------------------
// static variable-------------------------------------------------------------
// const data------------------------------------------------------------------
// dev_commonKey̓xƒ^ÅŽ<C385>ÁÄ¢¢<E2809A>B
static const u8 dev_commonKey[] = {
0xA1, 0x60, 0x4A, 0x6A, 0x71, 0x23, 0xB5, 0x29,
0xAE, 0x8B, 0xEC, 0x32, 0xC8, 0x16, 0xFC, 0xAA
};
static const u8 dev_seedES[] = {
0x2D, 0xD4, 0x03, 0x98, 0xA7, 0x6B, 0x03, 0x28,
0xCE, 0x61, 0x04, 0xBB, 0x0A, 0xBB, 0x03, 0x5B,
};
static const u8 dev_seedNAM[] = {
0x4D, 0x04, 0xA4, 0x7F, 0xE3, 0x02, 0x30, 0x2E,
0x2A, 0x07, 0x06, 0xE6, 0xD9, 0x06, 0x47, 0x76,
};
static const u8 dev_seedSlotC[] = {
0x3B, 0x06, 0x86, 0x57, 0x33, 0x04, 0x88, 0x11,
0x49, 0x04, 0x6B, 0x33, 0x12, 0x02, 0xAC, 0xF3,
};
// ============================================================================
//
// AESŒ®ƒXƒ<58>ƒbƒg<C692>Ýè
//
// ============================================================================
void SYSMi_SetAESKeysForAccessControl( BOOL isNtrMode, ROM_Header *pROMH )
{
BOOL isClearSlotB = TRUE;
BOOL isClearSlotC = TRUE;
// Œ®ÌƒZƒbƒg
MI_CpuClearFast( (void *)HW_LAUNCHER_DELIVER_PARAM_BUF, HW_LAUNCHER_DELIVER_PARAM_BUF_SIZE );
if( !isNtrMode &&
( pROMH->s.titleID_Hi & TITLE_ID_HI_SECURE_FLAG_MASK ) ) {
SYSMi_SetAESKeysForAccessControlCore( pROMH, (u8 *)HW_LAUNCHER_DELIVER_PARAM_BUF, &isClearSlotB, &isClearSlotC );
}
// ƒu<C692>[ƒg·éƒAƒvƒŠÉ‰žÄ<E2809A>AAESƒL<C692>[ƒXƒ<58>ƒbƒg̃NƒŠƒAð<E2809A>s¤<E2809A>B
{
AESi_ResetAesKeyA();
if( isClearSlotB ) AESi_ResetAesKeyB();
if( isClearSlotC ) AESi_ResetAesKeyC();
// NANDɃAƒNƒZƒXµÈ¢ƒAƒvƒŠÍ<E2809A>AƒXƒ<58>ƒbƒgDÌŒ®ðƒNƒŠƒA·é<E2809A>@
// if( th->s.access_control.nand_access == 0 ) AESi_ResetAesKeyD();<3B>@<40>¦rebootÌÌREBOOTi_DetachAllDrivesÅNANDɃAƒNƒZƒX·é<E2809A>ê<EFBFBD>ª éÌÅ<E2809A>A±±ÅƒNƒŠƒAÍūȢ<E2809A>BâéÈç»ÌŒãëÅ<E2809A>B
}
// »Ì¼ÌŒ®Í•s—vÉÈéÌÅ<E2809A>A<EFBFBD>ÁµÄ¨­
{
OSFromFirmBuf* fromFirm = (void*)HW_FIRM_FROM_FIRM_BUF;
MI_CpuClearFast(fromFirm, sizeof(OSFromFirmBuf));
}
}
void SYSMi_SetAESKeysForAccessControlCore( ROM_Header *pROMH, u8 *pDst, BOOL *pIsClearSlotB, BOOL *pIsClearSlotC )
{
// commonClientKey
if( pROMH->s.access_control.common_client_key ) {
void *pCommonKey = ( SCFG_GetBondingOption() == SCFG_OP_PRODUCT ) ?
OSi_GetFromFirmAddr()->aes_key[ 0 ] : (void *)dev_commonKey;
MI_CpuCopy8( pCommonKey, pDst, AES_BLOCK_SIZE );
}
// commonClientKeyForDebugger
else if( pROMH->s.access_control.common_client_key_for_debugger_sysmenu ) {
MI_CpuCopy8( OSi_GetFromFirmAddr()->aes_key[ 1 ], pDst, AES_BLOCK_SIZE );
}
// HW AES Slot B
if( pROMH->s.access_control.hw_aes_slot_B ) {
void *pSeedES = ( SCFG_GetBondingOption() == SCFG_OP_PRODUCT ) ?
&( OSi_GetFromFirmAddr()->rsa_pubkey[ 3 ][ 0 ] ) : (void *)dev_seedES;
MI_CpuCopy8( pSeedES, pDst + 0x10, AES_BLOCK_SIZE );
if( pIsClearSlotB ) {
*pIsClearSlotB = FALSE;
}
// AESƒXƒ<58>ƒbƒg̃fƒtƒHƒƒglƒZƒbƒgÍ•s—v
}
// HW AES Slot C
if( pROMH->s.access_control.hw_aes_slot_C ) {
void *pSeedNAM = ( SCFG_GetBondingOption() == SCFG_OP_PRODUCT ) ?
&( OSi_GetFromFirmAddr()->rsa_pubkey[ 3 ][ 0x10 ] ) : (void *)dev_seedNAM;
void *pSeedSlotC = ( SCFG_GetBondingOption() == SCFG_OP_PRODUCT ) ?
&( OSi_GetFromFirmAddr()->rsa_pubkey[ 3 ][ 0x20 ] ) : (void *)dev_seedSlotC;
MI_CpuCopy8( pSeedNAM, pDst + 0x20, AES_BLOCK_SIZE );
if( pIsClearSlotC ) {
*pIsClearSlotC = FALSE;
}
// AESƒXƒ<58>ƒbƒg̃fƒtƒHƒƒglƒZƒbƒg
AES_Lock();
AES_SetKeySeedC( pSeedSlotC );
AES_Unlock();
}
}