Wasabi ExpressPlay SDK for Embedded Systems  1.10
Ts2Iec62455.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | MPEG2 Transport Stream - IEC 62455
4 |
5 | $Id: Ts2Iec62455.h 296 2014-06-25 11:20:09Z jebaseelir $
6 | Original author: Julien Boeuf
7 |
8 | This software is provided to you pursuant to your agreement
9 | with Intertrust Technologies Corporation ("Intertrust").
10 | This software may be used only in accordance with the terms
11 | of the agreement.
12 |
13 | Copyright (c) 2010-2014 by Intertrust. All rights reserved.
14 |
15 ****************************************************************/
16 
17 #ifndef _TS2_IEC_62455_H_
18 #define _TS2_IEC_62455_H_
19 
20 /*----------------------------------------------------------------------
21 | includes
22 +---------------------------------------------------------------------*/
23 #include "Ts2Tables.h"
24 
25 /*----------------------------------------------------------------------
26 | constants
27 +---------------------------------------------------------------------*/
28 #define TS2_KSM_TABLE80_ID 0x80
29 #define TS2_KSM_TABLE81_ID 0x81
30 
31 #define TS2_KSM_PROTOCOL_VERSION_1 0x01
32 
33 #define TS2_KSM_ENCRYPTED_PEK_SIZE 16
34 #define TS2_KSM_MAC_SIZE 12
35 #define TS2_KSM_CID_EXTENSION_SIZE 4
36 
37 #define TS2_KSM_ALGO_IPSEC 0
38 #define TS2_KSM_ALGO_SRTP 1
39 #define TS2_KSM_ALGO_ISMACRYPT 2
40 #define TS2_KSM_ALGO_MPEG2_TS_CRYPT 7
41 
42 #define TS2_KSM_FLAG_EVEN 0
43 #define TS2_KSM_FLAG_ODD 1
44 
45 #define TS2_KSM_CONTENT_KEY_INDEX_DVB_CSA_64 0x00
46 #define TS2_KSM_CONTENT_KEY_INDEX_DES_56 0x01
47 #define TS2_KSM_CONTENT_KEY_INDEX_3DES_168 0x02
48 #define TS2_KSM_CONTENT_KEY_INDEX_3DES_112 0x03
49 #define TS2_KSM_CONTENT_KEY_INDEX_3DES_56 0x04
50 #define TS2_KSM_CONTENT_KEY_INDEX_AES_128 0x05 /* BBTS 1.0/1.1 */
51 #define TS2_KSM_CONTENT_KEY_INDEX_M2_64 0x06
52 #define TS2_KSM_CONTENT_KEY_INDEX_AES_128_KDF 0x0F /* BBTS 2.0, Key Derivation Function */
53 
54 #define TS2_KSM_CIPHER_MODE_ECB 0x00
55 #define TS2_KSM_CIPHER_MODE_CBC 0x01
56 #define TS2_KSM_CIPHER_MODE_CSA 0x02
57 
58 #define TS2_KSM_FLAG_EVEN 0
59 #define TS2_KSM_FLAG_ODD 1
60 
61 /*----------------------------------------------------------------------
62 | types
63 +---------------------------------------------------------------------*/
64 typedef struct {
65  ATX_Byte reserved_byte;
66  ATX_List* descriptors;
68 
69 typedef struct {
70  ATX_UInt8 permission_flag;
71  ATX_UInt8 permissions;
72  ATX_Byte encrypted_pek[TS2_KSM_ENCRYPTED_PEK_SIZE];
73  ATX_Byte cid_extension[TS2_KSM_CID_EXTENSION_SIZE];
75  ATX_Byte mac[TS2_KSM_MAC_SIZE];
77 
78 typedef struct {
79  ATX_Byte cid_extension[TS2_KSM_CID_EXTENSION_SIZE];
81  ATX_Byte mac[TS2_KSM_MAC_SIZE];
83 
84 typedef struct TS2_KSM TS2_KSM;
85 struct TS2_KSM {
86  ATX_UInt16 flags; /* use with TS2_KSM_Flags_XXXX */
87  ATX_Byte* signed_payload;
88  ATX_Byte* enc_key_material;
91  ATX_UInt8 key_lifetime; /* use TS2_GetKeyLifetimeInSecs to get the value in secs */
92  ATX_UInt64 timestamp;
96 
97  /* internal */
98  ATX_Byte* mac_key;
99  ATX_Size mac_key_size;
100  void (*Destroy)(TS2_KSM* self);
101 };
102 
103 typedef struct {
105  ATX_UInt8 info;
106  ATX_UInt8 iv_size;
107  ATX_Byte* iv;
108  ATX_Byte* next_iv;
110 
111 typedef struct {
114 } TS2_KSMT;
115 
116 /*----------------------------------------------------------------------
117 | functions
118 +---------------------------------------------------------------------*/
119 #ifdef __cplusplus
120 extern "C" {
121 #endif
122 
123 TS2_EXPORT ATX_Result
125 
136 ATX_Result
138  const ATX_Byte* encrypted_pek, /* can be NULL */
139  const ATX_Byte* cid_extension);
140 
148 ATX_Result
150  const ATX_Byte* cid_extension);
151 
176 ATX_Result
177 TS2_Mpeg2TsCryptKSM_Create(ATX_UInt32 content_key_index,
178  ATX_UInt32 crypto_period, /* between 1 and 120 */
179  ATX_UInt8 odd_even_flag,
180  const ATX_Byte* enc_key_material,
181  const ATX_Byte* next_enc_key_material,
182  const ATX_Byte* iv,
183  const ATX_Byte* next_iv,
184  const TS2_KSM_Programme* programme,
185  const TS2_KSM_Service* service,
186  const ATX_Byte* mac_key,
187  ATX_Size mac_key_size,
188  const ATX_Byte* access_criteria,
189  ATX_Size access_criteria_size,
190  TS2_KSM** ksm);
191 
201 ATX_Result
203  ATX_DataBuffer** buffer);
204 
205 ATX_Result
206 TS2_KSM_CreateFromBuffer(const ATX_Byte* buffer,
207  ATX_Size buffer_size,
208  TS2_KSM** ksm);
209 
210 void
212 
213 
225 ATX_Result
226 TS2_KSM_AccessCriteria_Parse(const ATX_Byte* ac_data,
227  ATX_Size* ac_size,
229 
239 ATX_Result
240 TS2_KSM_AccessCriteria_Serialize(TS2_KSM_AccessCriteria* ac, ATX_Byte* buffer, ATX_Size* buffer_size);
241 
242 
248 void
250 
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 
256 /*----------------------------------------------------------------------
257 | helpers
258 +---------------------------------------------------------------------*/
259 #define TS2_KSM_Flags_ProtocolVersion(flags) (((flags) & 0xF000) >> 12)
260 #define TS2_KSM_Flags_AccessCriteriaFlag(flags) (((flags) & 0x0100) >> 8)
261 #define TS2_KSM_Flags_TrafficProtectionProtocol(flags) (((flags) & 0x00E0) >> 5)
262 #define TS2_KSM_Flags_TrafficAuthenticationFlag(flags) (((flags) & 0x0010) >> 4)
263 #define TS2_KSM_Flags_NextTrafficKeyFlag(flags) (((flags) & 0x0008) >> 3)
264 #define TS2_KSM_Flags_TimestampFlag(flags) (((flags) & 0x0004) >> 2)
265 #define TS2_KSM_Flags_ProgrammeFlag(flags) (((flags) & 0x0002) >> 1)
266 #define TS2_KSM_Flags_ServiceFlag(flags) (((flags) & 0x0001) )
267 
268 #define TS2_Mpeg2TsCryptKSM_ContentKeyIndex(m2ksm) ((((m2ksm)->info) & 0xF0) >> 4)
269 #define TS2_Mpeg2TsCryptKSM_OddEvenFlag(m2ksm) ((((m2ksm)->info) & 0x08) >> 3)
270 #define TS2_Mpeg2TsCryptKSM_CipherMode(m2ksm) ((((m2ksm)->info) & 0x07) )
271 
272 #define TS2_GetKeyLifetimeInSecs(klf) (1 << (klf))
273 
277 #define TS2_KSM_Destroy(KSM) \
278 do { \
279  TS2_KSM* __ksm = (KSM); \
280  if (__ksm && __ksm->Destroy) { \
281  __ksm->Destroy(__ksm); \
282  } \
283 } while (0)
284 
285 #endif /* _TS2_IEC_62455_H_ */