-
Notifications
You must be signed in to change notification settings - Fork 0
/
commondefs.py
88 lines (74 loc) · 2.52 KB
/
commondefs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
##########
# Crypto #
##########
SD_KEY = bytearray([
0xab, 0x01, 0xb9, 0xd8, 0xe1, 0x62, 0x2b, 0x08,
0xaf, 0xba, 0xd8, 0x4d, 0xbf, 0xc2, 0xa5, 0x5d
])
SD_IV = bytearray([
0x21, 0x67, 0x12, 0xe6, 0xaa, 0x1f, 0x68, 0x9f,
0x95, 0xc5, 0xa2, 0x23, 0x24, 0xdc, 0x6a, 0x98
])
IV_SIZE = len(SD_IV)
DEFAULT_DEVICE_ID = 0x0403AC68
DEFAULT_KEY_ID = 0x6AAB8C59
DEFAULT_PRIVATE_KEY = bytearray([
0x00, 0xAB, 0xEE, 0xC1, 0xDD, 0xB4, 0xA6, 0x16, 0x6B, 0x70, 0xFD, 0x7E, 0x56, 0x67, 0x70, 0x57,
0x55, 0x27, 0x38, 0xA3, 0x26, 0xC5, 0x46, 0x16, 0xF7, 0x62, 0xC9, 0xED, 0x73, 0xF2
])
# DEFAULT_PUBLIC_KEY = ec.privToPub(commondefs.DEFAULT_PRIVATE_KEY)
DEFAULT_PUBLIC_KEY = bytearray([ # generating the public key can take a while, so it's pre-calculated
0x01, 0x04, 0x0b, 0xe0, 0x46, 0xea, 0x95, 0x19, 0xf2, 0x85, 0x9b, 0x0d, 0x94, 0x29, 0xa2, 0xc6,
0x91, 0x80, 0x15, 0x89, 0x8f, 0x2e, 0xba, 0x20, 0xcf, 0xfd, 0xb3, 0x16, 0x4f, 0x0c, 0x01, 0x38,
0xc5, 0xd2, 0x2f, 0xc1, 0xe9, 0xee, 0x17, 0x6c, 0x2d, 0x8f, 0xa4, 0x74, 0xb0, 0xe9, 0x38, 0x66,
0x6e, 0x60, 0xcf, 0x06, 0xd5, 0x08, 0x7a, 0xc2, 0x4f, 0x01, 0x39, 0x79
])
DEFAULT_SIGNATURE = bytearray([
0x00, 0xD8, 0x81, 0x63, 0xB2, 0x00, 0x6B, 0x0B, 0x54, 0x82, 0x88, 0x63, 0x81, 0x1C, 0x00, 0x71,
0x12, 0xED, 0xB7, 0xFD, 0x21, 0xAB, 0x0E, 0x50, 0x0E, 0x1F, 0xBF, 0x78, 0xAD, 0x37, 0x00, 0x71,
0x8D, 0x82, 0x41, 0xEE, 0x45, 0x11, 0xC7, 0x3B, 0xAC, 0x08, 0xB6, 0x83, 0xDC, 0x05, 0xB8, 0xA8,
0x90, 0x1F, 0xA8, 0x2A, 0x0E, 0x4E, 0x76, 0xEF, 0x44, 0x72, 0x99, 0xF8
])
SIGNATURE_END_MAGIC = 0x2f536969
##################
# Cert Structure #
##################
CERT_SIG_TYPE_ECC = 0x10002
CERT_KEY_TYPE_ECC = 2
CERT_SIG_TYPE_OFFSET = 0x0
CERT_SIG_OFFSET = 0x4
CERT_ISSUER_OFFSET = 0x80
CERT_KEY_TYPE_OFFSET = 0xc0
CERT_NAME_OFFSET = 0xc4
CERT_KEY_ID_OFFSET = 0x104
CERT_PUBLIC_KEY_OFFSET = 0x108
##################
# File Structure #
##################
HEADER_SIZE = 0xf0c0
BK_SIZE = 0x80
BK_TRUE_SIZE = 0x70
BK_MAGIC = 0x426b0001
BK_SIZE_OFFSET = 0x0
BK_MAGIC_OFFSET = 0x4
BK_NG_ID_OFFSET = 0x8
BK_FILE_COUNT_OFFSET = 0xc
BK_FILE_SIZE_OFFSET = 0x10
BK_TOTAL_SIZE_OFFSET = 0x1c
BK_TITLE_ID_OFFSET = 0x60
FILE_HEADER_SIZE = 0x80
FILE_MAGIC = 0x3adf17e
FILE_NAME_SIZE = 0x44
FILE_TYPE_FILE = 1
FILE_TYPE_DIR = 2
FILE_MAGIC_OFFSET = 0x0
FILE_SIZE_OFFSET = 0x4
FILE_PERM_OFFSET = 0x8
FILE_ATTR_OFFSET = 0x9
FILE_TYPE_OFFSET = 0xa
FILE_NAME_OFFSET = 0xb
FILE_IV_OFFSET = 0x50
SIG_SIZE = 0x40
NG_CERT_SIZE = 0x180
AP_CERT_SIZE = 0x180
TOTAL_CERTS_SIZE = SIG_SIZE + NG_CERT_SIZE + AP_CERT_SIZE