Wasabi ExpressPlay SDK for Embedded Systems  1.23.0
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,
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_ */
ATX_Result TS2_KSM_Service_Construct(TS2_KSM_Service *self, const ATX_Byte *cid_extension)
Initialize the KSM Service structure.
ATX_Result TS2_KSM_AccessCriteria_Parse(const ATX_Byte *ac_data, ATX_Size *ac_size, TS2_KSM_AccessCriteria **ac)
Parses the access_criteria block in the KSM.
ATX_Result TS2_Mpeg2TsCryptKSM_Create(ATX_UInt32 content_key_index, ATX_UInt32 crypto_period, ATX_UInt8 odd_even_flag, const ATX_Byte *enc_key_material, const ATX_Byte *next_enc_key_material, const ATX_Byte *iv, const ATX_Byte *next_iv, const TS2_KSM_Programme *programme, const TS2_KSM_Service *service, const ATX_Byte *mac_key, ATX_Size mac_key_size, const ATX_Byte *access_criteria, ATX_Size access_criteria_size, TS2_KSM **ksm)
Create a Marlin BBTS Key Stream Message (KSM) object.
#define TS2_KSM_MAC_SIZE
Definition: Ts2Iec62455.h:34
ATX_Byte reserved_byte
Definition: Ts2Iec62455.h:65
ATX_Size mac_key_size
Definition: Ts2Iec62455.h:99
ATX_UInt16 flags
Definition: Ts2Iec62455.h:86
ATX_Size signed_payload_size
Definition: Ts2Iec62455.h:80
void TS2_Mpeg2TsCryptKSM_SwitchOddEvenFlag(TS2_Mpeg2TsCryptKSM *self)
Definition: Ts2Iec62455.h:64
void TS2_KSM_AccessCriteria_Destroy(TS2_KSM_AccessCriteria *self)
Destroys the TS2_KSM_AccessCriteria object.
TS2_KSM_Service * service
Definition: Ts2Iec62455.h:95
ATX_Byte * next_enc_key_material
Definition: Ts2Iec62455.h:90
ATX_Size signed_payload_size
Definition: Ts2Iec62455.h:74
Definition: Ts2Iec62455.h:69
ATX_Result TS2_Mpeg2TsCryptKSM_Serialize(TS2_Mpeg2TsCryptKSM *m2ksm, ATX_DataBuffer **buffer)
Serialize a Marlin Key Stream Message.
Definition: Ts2Iec62455.h:111
ATX_Byte * enc_key_material
Definition: Ts2Iec62455.h:88
TS2_KSM_AccessCriteria * access_criteria
Definition: Ts2Iec62455.h:93
Definition: Ts2Iec62455.h:78
TS2_Table base
Definition: Ts2Iec62455.h:112
#define TS2_KSM_ENCRYPTED_PEK_SIZE
Definition: Ts2Iec62455.h:33
#define TS2_EXPORT
Definition: Ts2Config.h:67
ATX_UInt64 timestamp
Definition: Ts2Iec62455.h:92
ATX_UInt8 permissions
Definition: Ts2Iec62455.h:71
ATX_List * descriptors
Definition: Ts2Iec62455.h:66
TS2_KSM_Programme * programme
Definition: Ts2Iec62455.h:94
Definition: Ts2Tables.h:68
ATX_Byte * mac_key
Definition: Ts2Iec62455.h:98
#define TS2_KSM_CID_EXTENSION_SIZE
Definition: Ts2Iec62455.h:35
ATX_Result TS2_KSM_Programme_Construct(TS2_KSM_Programme *self, const ATX_Byte *encrypted_pek, const ATX_Byte *cid_extension)
Initialize the KSM Programme structure.
ATX_Result TS2_KSM_CreateFromBuffer(const ATX_Byte *buffer, ATX_Size buffer_size, TS2_KSM **ksm)
ATX_Byte * iv
Definition: Ts2Iec62455.h:107
TS2_KSM * ksm
Definition: Ts2Iec62455.h:113
ATX_UInt8 enc_key_material_size
Definition: Ts2Iec62455.h:89
ATX_UInt8 permission_flag
Definition: Ts2Iec62455.h:70
void(* Destroy)(TS2_KSM *self)
Definition: Ts2Iec62455.h:100
Definition: Ts2Iec62455.h:85
ATX_UInt8 info
Definition: Ts2Iec62455.h:105
ATX_UInt8 iv_size
Definition: Ts2Iec62455.h:106
ATX_Byte * signed_payload
Definition: Ts2Iec62455.h:87
ATX_Result TS2_KSM_AccessCriteria_Serialize(TS2_KSM_AccessCriteria *ac, ATX_Byte *buffer, ATX_Size *buffer_size)
Serializes the TS2_KSM_AccessCriteria object to a data-buffer.
TS2_KSM base
Definition: Ts2Iec62455.h:104
Definition: Ts2Iec62455.h:103
TS2_EXPORT ATX_Result TS2_KSMT_Construct(TS2_KSMT *self)
ATX_UInt8 key_lifetime
Definition: Ts2Iec62455.h:91
ATX_Byte * next_iv
Definition: Ts2Iec62455.h:108