uOFW
Reverse engineered PSP kernel 6.60.
Loading...
Searching...
No Matches
idstorage.h
1/* Copyright (C) The uOFW team
2 See the file COPYING for copying permission.
3*/
4
5#ifndef IDSTORAGE_H
6#define IDSTORAGE_H
7
8#include "common_header.h"
9#include "openpsid_kernel.h"
10
11/* Size of an ID storage leaf. In byte. */
12#define SCE_ID_STORAGE_LEAF_SIZE 512
13
14#define SCE_ID_STORAGE_LEAF_CONSOLE_ID_OPEN_PSID_1 0x100
15#define SCE_ID_STORAGE_LEAF_CONSOLE_ID_OPEN_PSID_2 0x101
16#define SCE_ID_STORAGE_LEAF_CONSOLE_ID_OPEN_PSID_3_UMD_1 0x102
17#define SCE_ID_STORAGE_LEAF_ID_UMD_2 0x103
18#define SCE_ID_STORAGE_LEAF_ID_UMD_3 0x104
19#define SCE_ID_STORAGE_LEAF_ID_UMD_4 0x105
20#define SCE_ID_STORAGE_LEAF_ID_UMD_5 0x106
21
22/* Offset into leaf [SCE_ID_STORAGE_LEAF_CONSOLE_ID_OPEN_PSID_3_UMD_1] at which region-code-info related data can be found. */
23#define SCE_ID_STORAGE_LEAF_CONSOLE_ID_OPEN_PSID_3_UMD_1_OFFSET_REGION_CODES 0xB0
24#define SCE_ID_STORAGE_LEAF_CONSOLE_ID_OPEN_PSID_3_UMD_1_OFFSET_REGION_CODES_SIZE (4 * SCE_ID_STORAGE_LEAF_SIZE)
25
26#define SCE_ID_STORAGE_LEAF_ID_BACKUP_CONSOLE_ID_OPEN_PSID_1 0x120
27#define SCE_ID_STORAGE_LEAF_ID_BACKUP_CONSOLE_ID_OPEN_PSID_2 0x121
28#define SCE_ID_STORAGE_LEAF_ID_BACKUP_CONSOLE_ID_OPEN_PSID_3_UMD_1 0x122
29#define SCE_ID_STORAGE_LEAF_ID_BACKUP_UMD_2 0x123
30#define SCE_ID_STORAGE_LEAF_ID_BACKUP_UMD_3 0x124
31#define SCE_ID_STORAGE_LEAF_ID_BACKUP_UMD_4 0x125
32#define SCE_ID_STORAGE_LEAF_ID_BACKUP_UMD_5 0x126
33
34#define SCE_ID_STORAGE_LEAF_ID_UMD_COUNT ((SCE_ID_STORAGE_LEAF_ID_UMD_5 - SCE_ID_STORAGE_LEAF_CONSOLE_ID_OPEN_PSID_3_UMD_1) + 1)
35
36/* Offset into the leaf [SCE_ID_STORAGE_LEAF_CONSOLE_ID_OPEN_PSID_1] to the start of the first ConsoleId certificate. */
37#define SCE_ID_STORAGE_LEAF_CONSOLE_ID_OPEN_PSID_1_OFFSET_CONSOLE_ID_CERTIFICATE_1 0x38
38/* Offset into the leaf [SCE_ID_STORAGE_LEAF_CONSOLE_ID_OPEN_PSID_2] to the start of the OpenPSID certificate. */
39#define SCE_ID_STORAGE_LEAF_CONSOLE_ID_OPEN_PSID_2_OFFSET_OPEN_PSID_CERTIFICATE 0x1D0
40
41/*
42 * ID Storage layout (WIP):
43 *
44 * Each ID storage leaf has a size of 512 bytes. Some leafs are "self-contained", that is, they do not share data with
45 * their neighboring leafs. Examples for such leafs are the leafs with IDs 0x4 - 0x8. Other leafs are "continious" leafs,
46 * meaning they share data with their neighboring leafs. Examples of such leafs are the leafs 0x100 - 0x102.
47 *
48 *
49 * .
50 * .
51 * .
52 *
53 * The leafs 0x100 - 0x102 contain the ConsoleId (termed "PSID" on the PSP) and the OpenPSID. As an additional security feature
54 * to prevent successfully tampering them, they are stored inside a certificate, which can be used to verify the ConsoleId and
55 * OpenPSID. For more info, see SceIdStorageConsoleIdCertificate and SceIdStorageOpenPSIDCertificate.
56 *
57 * These leafs are "continious leafs" and contain 5 ConsoleId certificates (totalling 5 * 184 = 920 bytes)
58 * followed by a single OpenPSID certificate (for a total size of 920 + 184 = 1104 bytes).
59 *
60 * Of these 5 certificates, only the first ConsoleId certificate and the OpenPSID certificate are used in the system.
61 * It is unknown what the purpose the remaining four ConsoleId certificates is.
62 *
63 * +------------------------------------------------------------+----------------
64 * | unknown data (size: 0x38) | |
65 * |------------------------------------------------------------| |
66 * | SceIdStorageConsoleIdCertificate (size: 0xB8) | |
67 * |------------------------------------------------------------| Leaf 0x100
68 * | SceIdStorageConsoleIdCertificate (size: 0xB8) | |
69 * |------------------------------------------------------------| |
70 * | SceIdStorageConsoleIdCertificate_part1 (size: 0x58) | |
71 * |------------------------------------------------------------|----------------
72 * | SceIdStorageConsoleIdCertificate_part2 (size: 0x60) | |
73 * |------------------------------------------------------------| |
74 * | SceIdStorageConsoleIdCertificate (size: 0xB8) | |
75 * |------------------------------------------------------------| Leaf 0x101
76 * | SceIdStorageConsoleIdCertificate (size: 0xB8) | |
77 * |------------------------------------------------------------| |
78 * | SceIdStorageOpenPSIDCertificate_part1 (size: 0x30) | |
79 * |------------------------------------------------------------|----------------
80 * | SceIdStorageOpenPSIDCertificate_part2 (size: 0x88) | |
81 * |------------------------------------------------------------| Leaf 0x102
82 * | unknown data (size: 0x178) | |
83 * |------------------------------------------------------------|----------------
84 * .
85 * .
86 * .
87 *
88 * The leafs 0x120 - 0x126 are backups of leafs 0x100 - 0x106. See the description of those leafs for more information.
89 *
90 * .
91 * .
92 * .
93 *
94 */
95
96/*
97 * This structure contains the ConsoleId (termed "PSID" on the PSP) and an ECDSA signature used to verify the correctness of the
98 * ConsoleId.
99 * The ConsoleId is used, for example, in PSN DRM, DNAS and system configuration (with its derived PSCode).
100 */
101typedef struct {
102 /* Unique per-console identifier. */
103 SceConsoleId consoleId; // 0
104 /* Contains the public key of the certificate. No padding. */
105 u8 plantextPublicKey[0x28]; // 16
106 /* The 'r' part of the ECDSA signature pair (r, s). */
107 u8 r[0x14]; // 56
108 /* The 's' part of the ECDSA signature pair (r, s). */
109 u8 s[0x14]; // 76
110 /* The ECDSA public key (can be used to verify ECDSA signature rs). */
111 u8 publicKey[0x28]; // 96
112 /* Contains the encrypted private key of the certificate (with padding). */
113 u8 encPrivateKey[0x20]; // 136
114 /* Hash of previous data. */
115 u8 hash[0x10]; // 168
116} SceIdStorageConsoleIdCertificate; // size = 184
117
118/*
119 * This structure contains the OpenPSID (random 16 byte value) and an ECDSA signature used to verify the correctness
120 * of the OpenPSID. The OpenPSID value is used, for example, in PSN matchmaking.
121 */
122typedef struct {
123 /* Unique per-console identifier. */
124 u8 openPSID[0x10]; // 0
125 /* Contains the public key of the certificate. No padding. */
126 u8 plantextPublicKey[0x28]; // 16
127 /* The 'r' part of the ECDSA signature pair (r, s). */
128 u8 r[0x14]; // 56
129 /* The 's' part of the ECDSA signature pair (r, s). */
130 u8 s[0x14]; // 76
131 /* The ECDSA public key (can be used to verify ECDSA signature rs). */
132 u8 publicKey[0x28]; // 96
133 /* Contains the encrypted private key of the certificate (with padding). */
134 u8 encPrivateKey[0x20]; // 136
135 /* Hash of previous data. */
136 u8 hash[0x10]; // 168
137} SceIdStorageOpenPSIDCertificate; // size = 184
138
139typedef struct {
140 u32 umdMediaTypeRegionCode; // 0
141 u32 unk4; // 4
142} SceIdStorageUMDRegionCodeInfo;
143
144typedef void (*sceIdStorageEnumCB)(u16 id, s32 ppn, void *opt);
145
146s32 sceIdStorageInit(void);
147s32 sceIdStorageEnd(void);
148s32 sceIdStorageGetLeafSize(void);
149s32 sceIdStorageIsFormatted(void);
150s32 sceIdStorageIsReadOnly(void);
151s32 sceIdStorageIsDirty(void);
152s32 sceIdStorageFormat(void);
153s32 sceIdStorageUnformat(void);
154s32 sceIdStorageReadLeaf(u16 id, void *buf);
155s32 sceIdStorageWriteLeaf(u16 id, void *buf);
156s32 sceIdStorageFlush(void);
157s32 sceIdStorageGetFreeLeaves(void);
158s32 sceIdStorageEnumId(sceIdStorageEnumCB cb, void *opt);
159s32 sceIdStorageCreateLeaf(u16 id);
160s32 sceIdStorageCreateAtomicLeaves(u16 *ids, s32 size);
161s32 sceIdStorageDeleteLeaf(u16 id);
162s32 sceIdStorageLookup(u16 id, u32 offset, void *buf, u32 len);
163s32 sceIdStorageUpdate(u16 id, u32 offset, void *buf, u32 len);
164
165#endif /* IDSTORAGE_H */
166
Definition openpsid_kernel.h:52