1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     FsSampleSecureSave.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  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   $Rev: 47440 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_SAMPLE_DEMOS_FS_SAMPLE_SECURE_SAVE_H_
17 #define NN_SAMPLE_DEMOS_FS_SAMPLE_SECURE_SAVE_H_
18 
19 namespace sample { namespace fs { namespace securesave {
20 
21 // The number of save data slots used by the application
22 const u32   DATA_FILE_NUM       = 3;
23 // If a rollback prevention value is going to be used for each separate instance of save data, implementation is possible by dividing the number of instances of save data by 64 bits.
24 // For example, specify as follows if there are three instances of save data:
25 // Save data 0: 0000000000000000000000000000000000000000000*********************
26 // Save data 1: 0000000000000000000000*********************000000000000000000000
27 // Save data 2: 0*********************000000000000000000000000000000000000000000
28 // Here, we use rollback prevention values that are 21 bits long for each instance of save data.
29 const u32   SECURE_VALUE_SHIFT  = 64 / DATA_FILE_NUM;
30 const bit64 SECURE_VALUE_MASK = SECURE_VALUE_SHIFT == 64 ? 0xFFFFFFFFFFFFFFFFllu : ((1llu << SECURE_VALUE_SHIFT) - 1);
31 
32 // An example of save data used by an application
33 struct UserData
34 {
35     s32 data1;
36     s32 data2;
37 };
38 
39 struct SaveData
40 {
41     bit64    version;
42     UserData userData;
43 
44     void Reset();
45     void UpdateVersion();
46 };
47 
48 void Save(SaveData &saveData, u32 fileIndex);
49 bool Load(SaveData &saveData, u32 fileIndex);
50 bool InitializeSaveData();
51 
52 }}}
53 
54 #endif
55