1 /*---------------------------------------------------------------------------* 2 Project: TwlSDK - OS 3 File: os_entropy.c 4 5 Copyright 2003-2008 Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Date:: 2008-09-18#$ 14 $Rev: 8573 $ 15 $Author: okubata_ryoma $ 16 *---------------------------------------------------------------------------*/ 17 #include <nitro/os.h> 18 #include <nitro/gx.h> 19 20 //---------------------------------------------------------------------- 21 22 extern vu64 OSi_TickCounter; 23 24 /*---------------------------------------------------------------------------* 25 Name: OS_GetLowEntropyData 26 27 Description: Gets low entropy data array that changes according to the system status. 28 29 Arguments: buffer: Pointer to the array that holds the data string 30 31 Returns: None. 32 *---------------------------------------------------------------------------*/ OS_GetLowEntropyData(u32 buffer[OS_LOW_ENTROPY_DATA_SIZE/sizeof (u32)])33void OS_GetLowEntropyData(u32 buffer[OS_LOW_ENTROPY_DATA_SIZE / sizeof(u32)]) 34 { 35 // RTC work area in the System Work Memory 36 const OSSystemWork *work = OS_GetSystemWork(); 37 const u8 *macAddress = 38 (u8 *)((u32)(work->nvramUserInfo) + ((sizeof(NVRAMConfig) + 3) & ~0x00000003)); 39 40 buffer[0] = (u32)((GX_GetVCount() << 16) | OS_GetTickLo()); 41 buffer[1] = (u32)(*(u16 *)(macAddress + 4) << 16) ^ (u32)(OSi_TickCounter); 42 buffer[2] = (u32)(OSi_TickCounter >> 32) ^ *(u32 *)macAddress ^ work->vblankCount; 43 #ifdef reg_G3X_GXSTAT 44 buffer[2] ^= reg_G3X_GXSTAT; 45 #endif 46 buffer[3] = *(u32 *)(&work->real_time_clock[0]); 47 buffer[4] = *(u32 *)(&work->real_time_clock[4]); 48 buffer[5] = (((u32)work->mic_sampling_data) << 16) ^ work->mic_last_address; 49 buffer[6] = (u32)((*(u16 *)(&work->touch_panel[0]) << 16) | *(u16 *)(&work->touch_panel[2])); 50 buffer[7] = (u32)((work->wm_rssi_pool << 16) | (reg_PAD_KEYINPUT | *(vu16 *)HW_BUTTON_XY_BUF)); 51 } 52