mkb.h 4.99 KB
Newer Older
1
2
/*
 * This file is part of libaacs
3
 * Copyright (C) 2009-2010  Obliter0n
4
 *
gates's avatar
gates committed
5
6
7
8
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
9
 *
gates's avatar
gates committed
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
gates's avatar
gates committed
12
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
14
 *
gates's avatar
gates committed
15
16
17
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see
 * <http://www.gnu.org/licenses/>.
18
19
 */

cRTrn13's avatar
cRTrn13 committed
20
21
22
#ifndef MKB_H_
#define MKB_H_

npzacs's avatar
npzacs committed
23
#include "util/attributes.h"
24

25
#include <stdlib.h>
cRTrn13's avatar
cRTrn13 committed
26
27
28
29
#include <stdint.h>

typedef struct mkb MKB;

npzacs's avatar
npzacs committed
30
31
struct aacs_file_s;

npzacs's avatar
npzacs committed
32
BD_PRIVATE MKB *mkb_init(uint8_t *data, size_t len); // init MKB from data
npzacs's avatar
npzacs committed
33
BD_PRIVATE void mkb_close(MKB *mkb);           // free MKB
cRTrn13's avatar
cRTrn13 committed
34

npzacs's avatar
npzacs committed
35
36
BD_PRIVATE const uint8_t *mkb_data(MKB *mkb);
BD_PRIVATE size_t mkb_data_size(MKB *mkb);
37

gates's avatar
gates committed
38
// returns type
John Doe's avatar
John Doe committed
39
BD_PRIVATE uint32_t mkb_type(MKB *mkb);
gates's avatar
gates committed
40
// returns version
npzacs's avatar
npzacs committed
41
BD_PRIVATE uint32_t mkb_version(MKB *mkb);
npzacs's avatar
npzacs committed
42
// returns type and version record (required to verify signatures)
npzacs's avatar
npzacs committed
43
BD_PRIVATE const uint8_t *mkb_type_and_version_record(MKB *mkb);
gates's avatar
gates committed
44
// returns list of revoked host entries
npzacs's avatar
npzacs committed
45
BD_PRIVATE const uint8_t *mkb_host_revokation_entries(MKB *mkb, size_t *len);
gates's avatar
gates committed
46
// returns list of revoked drive entries
npzacs's avatar
npzacs committed
47
BD_PRIVATE const uint8_t *mkb_drive_revokation_entries(MKB *mkb, size_t *len);
gates's avatar
gates committed
48
// returns subset-diff records
npzacs's avatar
npzacs committed
49
BD_PRIVATE const uint8_t *mkb_subdiff_records(MKB *mkb, size_t *len);
gates's avatar
gates committed
50
// returns list of subset-diff offsets
npzacs's avatar
npzacs committed
51
BD_PRIVATE const uint8_t *mkb_subdiff_offsets(MKB *mkb, size_t *len);
gates's avatar
gates committed
52
// returns list of cvalues
npzacs's avatar
npzacs committed
53
BD_PRIVATE const uint8_t *mkb_cvalues(MKB *mkb, size_t *len);
gates's avatar
gates committed
54
// media key verification data return in param (always 16 bytes)
npzacs's avatar
npzacs committed
55
BD_PRIVATE const uint8_t *mkb_mk_dv(MKB *mkb);
gates's avatar
gates committed
56
// returns MKB signature
npzacs's avatar
npzacs committed
57
BD_PRIVATE const uint8_t *mkb_signature(MKB *mkb, size_t *len);
cRTrn13's avatar
cRTrn13 committed
58

npzacs's avatar
npzacs committed
59
60
BD_PRIVATE int mkb_host_cert_is_revoked(MKB *mkb, const uint8_t *cert_id);
BD_PRIVATE int mkb_drive_cert_is_revoked(MKB *mkb, const uint8_t *cert_id);
61

cRTrn13's avatar
cRTrn13 committed
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* The Media Key block is of variable size but must be a multiple of 4
 * MKB Structure:
 *      Type and Version record (12 bytes)
 *          0   | type = 0x10
 *          1-3 | length = 0x00000c
 *          4-7 | MKB type = 0x000?1003
 *          8-11| MKB version
 *          
 *      Host Revokation List record (variable - multiple of 4 bytes)
 *          0                        | type = 0x21
 *          1-3                      | length
 *          4-7                      | total entries
 *          8-11                     | entires in signature block 1 (N1)
 *          12-19                    | host revokation list entry 0
 *          .
 *          .
 *          (12+(N1-1)*8)-(12+N1*8)-1| entry n
 *          (12+ N1*8)-(52+ N1*8)-1  | block 1 signature
 *          (52+ N1*8)-(length-1)    | more signature blocks
 *          
 *          Host Rekovation List entry (8 bytes)
 *              0-1| range
 *              2-7| host id
 *              
 *      Drive Revokation List record (variable - multiple of 4 bytes)
 *          0                        | type = 0x20
 *          1-3                      | length
 *          4-7                      | total entries
 *          8-11                     | entires in signature block 1 (N1)
 *          12-19                    | drive revokation list entry 0
 *          .
 *          .
 *          (12+(N1-1)*8)-(12+N1*8)-1| entry n
 *          (12+ N1*8)-(52+ N1*8)-1  | block 1 signature
 *          (52+ N1*8)-(length-1)    | more signature blocks
 *          
 *          Drive Rekovation List entry (8 bytes)
 *              0-1| range
 *              2-7| host id
 *              
 *      Verify Media Key record
 *          0   | type = 0x81
 *          1-3 | length = 0x14
 *          4-19| verification data (Dv)
 *          
 *      Explicit Subset-Difference record (variable - multiple of 4 bytes)
 *          0       | type = 0x04
 *          1-3     | length
 *          4       | uv mask 0
 *          5-8     | uv number 0
 *          .
 *          .
 *          length-1| end of uv number n
 *      
 *      Subset-Difference Index record (variable, padded - multiple of 4 bytes)
 *          0       | type = 0x07
 *          1-3     | length
 *          4-7     | span (number of devices)
 *          8-10    | offset 0
 *          .
 *          .
 *          length-1| end of offset n
 *          
 *      Media Key Data / cvalue record (variable - muliple of 4 bytes)
 *          0       | type = 0x05
 *          1-3     | length
 *          4-19    | media key data 0
 *          .
 *          .
 *          length-1| end of media key data n
 *          
 *      End of Media Key Block record (variable - multiple of 4 bytes)
 *          0         | type = 0x02
 *          1-3       | length
 *          4-length-1| signature
*/

#endif /* MKB_H_ */