TwlIPL/build/libraries_sysmenu/hotsw/ARM7/src/hotswBlowfish.c
nakasima f55ccdae1c NANDアプリの製品版システムコール復号化。
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1813 b08762b0-b915-fc4b-9d8c-17b2551a87ff
2008-07-08 03:08:57 +00:00

115 lines
3.8 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: blowfish.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.
*---------------------------------------------------------------------------*/
#include <twl.h>
#include <blowfish.h>
#include <firm/format/from_firm.h>
#include <firm/hw/ARM7/mmap_firm.h>
// Function Prototype -------------------------------------------------------
/*---------------------------------------------------------------------------*
Name: MakeBlowfishTableDSForNAND
Description: NANDƒAƒvƒŠ—pKeyTableÌ<E2809A><EFBFBD>¬
*---------------------------------------------------------------------------*/
void HOTSWi_MakeBlowfishTableDSForNAND(void)
{
CardBootData *cbd = HOTSWi_GetCardBootData();
cbd->pBootSegBuf = (void*)SYSM_APP_ROM_HEADER_BUF;
MakeBlowfishTableDS(cbd, 8);
}
/*---------------------------------------------------------------------------*
Name: MakeBlowfishTableDS
Description: KeyTableÌ<E2809A><EFBFBD>¬
*---------------------------------------------------------------------------*/
void MakeBlowfishTableDS(CardBootData *cbd, s32 keyLen)
{
const BLOWFISH_CTX *initTable = &HotSwBlowfishInitTableBufDS;
u32 *RomHeaderGameCode = (u32 *)cbd->pBootSegBuf->rh.s.game_code;
u32 *keyBuf = cbd->keyBuf;
BLOWFISH_CTX *ctx = &cbd->keyTable;
MI_CpuCopyFast((void *)initTable, (void *)ctx, sizeof(BLOWFISH_CTX));
keyBuf[0] = *RomHeaderGameCode;
keyBuf[1] = *RomHeaderGameCode >> 1;
keyBuf[2] = *RomHeaderGameCode << 1;
InitBlowfishKeyAndTableDS(ctx, keyBuf, keyLen);
InitBlowfishKeyAndTableDS(ctx, keyBuf, keyLen);
}
/*---------------------------------------------------------------------------*
Name: MakeBlowfishTableTWL
Description: KeyTable2Ì<E2809A><EFBFBD>¬
*---------------------------------------------------------------------------*/
void MakeBlowfishTableTWL(CardBootData *cbd, s32 keyLen, u16 bondingOp)
{
u32 *RomHeaderGameCode = (u32 *)cbd->pBootSegBuf->rh.s.game_code;
u32 *keyBuf = cbd->keyBuf2;
BLOWFISH_CTX *ctx = &cbd->keyTable2;
void *tempCTX;
// <20>»•i@Ì<E2809A>ê<EFBFBD>
if(bondingOp == SCFG_OP_PRODUCT){
MI_CpuCopyFast((void *)((OSFromFirm7Buf *)HW_FIRM_FROM_FIRM_BUF)->twl_blowfish, (void *)ctx, sizeof(BLOWFISH_CTX));
}
// ŠJ”­@Ì<E2809A>ê<EFBFBD>
else{
MI_CpuCopyFast(&HotSwBlowfishInitTableTWL_dev, (void *)ctx, sizeof(BLOWFISH_CTX));
// ƒXƒ^ƒbƒN—̈檃I<C692>[ƒo<C692>[ƒtƒ<74><C692>[·é©ç<E2809A>Aƒq<C692>[ƒv—̈æ©ç—̈æðŠm•Û·é<E2809A>B
tempCTX = OS_AllocFromSubPrivWram( sizeof(BLOWFISH_CTX) );
if(tempCTX != NULL){
ctx = tempCTX;
}
else{
return;
}
}
keyBuf[0] = *RomHeaderGameCode;
keyBuf[1] = *RomHeaderGameCode >> 1;
keyBuf[2] = *RomHeaderGameCode << 1;
InitBlowfishKeyAndTableDS(ctx, keyBuf, keyLen);
// HeapÌŠJ•ú
if(bondingOp != SCFG_OP_PRODUCT){
OS_FreeToSubPrivWram( tempCTX );
}
}
/*---------------------------------------------------------------------------*
Name: InitBlowfishKeyAndTableDS
Description:
*---------------------------------------------------------------------------*/
void InitBlowfishKeyAndTableDS(BLOWFISH_CTX *ctx, u32 *keyBufp, s32 keyLen)
{
EncryptByBlowfish(ctx, (void*)&(keyBufp)[2], (void*)&(keyBufp)[1]);
EncryptByBlowfish(ctx, (void*)&(keyBufp)[1], (void*)&(keyBufp)[0]);
InitBlowfish(ctx, (u8 *)keyBufp, keyLen);
}