Wasabi ExpressPlay SDK for Embedded Systems  1.10
Ts2Protection.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | MPEG2 Transport Stream - Protection
4 |
5 | $Id: Ts2Protection.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_PROTECTION_H_
18 #define _TS2_PROTECTION_H_
19 
20 /*----------------------------------------------------------------------
21 | includes
22 +---------------------------------------------------------------------*/
23 #include "Atomix.h"
24 #include "Ts2Packet.h"
25 #include "Ts2Iec62455.h"
26 #include "Ts2Crypto.h"
27 
28 /*----------------------------------------------------------------------
29 | constants
30 +---------------------------------------------------------------------*/
31 #define TS2_PROTECTION_KEY_LENGTH 16
32 
33 /*----------------------------------------------------------------------
34 | types
35 +---------------------------------------------------------------------*/
39 
44 typedef struct TS2_Secret TS2_Secret;
45 
46 typedef struct {
47  void* instance;
48 
76  ATX_Result (*GetDrmKey)(void* instance,
77  const char* content_id,
78  ATX_Byte* drm_key,
79  ATX_Size* drm_key_len);
81 
85 typedef enum {
86  TS2_KEYFORMAT_CLEAR, /* <- clear traffic key (can be disabled at build time) */
87  TS2_KEYFORMAT_SKB /* <- SecureKeyBox exported traffic key */
89 
94 typedef struct {
95  void* instance;
96  ATX_Result (*Decrypt)(void* instance,
97  const ATX_Byte* enc_data,
98  ATX_Size data_size,
99  ATX_Byte* dec_data);
100  void (*Destroy)(void* instance);
102 
106 #define TS2_SecretAesCbcDecrypter_Decrypt(self,a,b,c) \
107  self->Decrypt(self->instance,a,b,c)
108 
109 #define TS2_SecretAesCbcDecrypter_Destroy(self) \
110  self->Destroy(self)
111 
112 
118 typedef struct {
119  void* instance;
120 
137  ATX_Result (*GetDrmKey)(void* instance,
138  const char* content_id,
139  /* returns */
140  const TS2_Secret** drm_key);
141 
155  ATX_Result (*TruncatedSha1)(void* instance,
156  const TS2_Secret* in_key,
157  /* returns */
158  const TS2_Secret** out_key);
159 
191  ATX_Result (*ExportSecret)(void* instance,
192  const TS2_Secret* key,
193  /* returns */
194  ATX_Byte* key_data,
195  ATX_Size* key_data_size);
196 
197 
209  ATX_Result (*GetKeyFormat)(void* instance,
210  TS2_TrafficKeyFormat* key_format,
211  const void** parameters);
212 
213 
223  ATX_Result (*EqualSecret)(void* instance,
224  const TS2_Secret* key_a,
225  const TS2_Secret* key_b,
226  /*returns*/
227  ATX_Boolean* equal);
228 
237  void (*ReleaseSecret)(void* instance,
238  const TS2_Secret* secret);
239 
255  ATX_Result (*UnwrapSecret)(void* instance,
256  const TS2_Secret* key,
257  const ATX_Byte* wrapped_key,
258  ATX_Size wrapped_key_size,
259  /* returns */
260  const TS2_Secret** unwrapped_key);
261 
274  ATX_Result (*GetMacKey)(void* instance,
275  const TS2_Secret* mac_key,
276  const ATX_Byte* data,
277  ATX_Size data_size,
278  /* returns */
279  ATX_Byte mac_key_output[TS2_SHA1_DIGEST_SIZE]);
280 
281 
296  ATX_Result (*CreateSecretAesCbcDecrypter)(void* instance,
297  const ATX_Byte* key,
298  ATX_Size key_size,
299  const ATX_Byte* iv,
300  TS2_SecretAesCbcDecrypter** decrypter);
302 
303 
307 #define TS2_Crypto_GetDrmKey(self,a,b) \
308  self.GetDrmKey(self.instance,a,b)
309 
310 #define TS2_Crypto_TruncatedSha1(self,in_key,out_key) \
311  self.TruncatedSha1(self.instance,in_key,out_key)
312 
313 #define TS2_Crypto_ExportSecret(self,a,b,c) \
314  self.ExportSecret(self.instance,a,b,c)
315 
316 #define TS2_Crypto_GetKeyFormat(self,a,b) \
317  self.GetKeyFormat(self.instance,a,b)
318 
319 #define TS2_Crypto_EqualSecret(self,a,b,c) \
320  self.EqualSecret(self.instance,a,b,c)
321 
322 #define TS2_Crypto_ReleaseSecret(self,a) \
323  self.ReleaseSecret(self.instance,a)
324 
325 #define TS2_Crypto_UnwrapSecret(self,a,b,c,d) \
326  self.UnwrapSecret(self.instance,a,b,c,d)
327 
328 #define TS2_Crypto_GetMacKey(self,a,b,c,d) \
329  self.GetMacKey(self.instance,a,b,c,d)
330 
331 #define TS2_Crypto_CreateSecretAesCbcDecrypter(self,a,b,c,d) \
332  self.CreateSecretAesCbcDecrypter(self.instance,a,b,c,d)
333 
334 typedef enum {
341 
342 #ifdef __cplusplus
343 extern "C" {
344 #elif 0
345 }
346 #endif /* __cplusplus */
347 
348 /*----------------------------------------------------------------------
349 | TS2_PacketEncrypter functions
350 +---------------------------------------------------------------------*/
351 ATX_Result
353  const ATX_Byte* drm_key,
354  const ATX_Byte* cid_extension,
355  ATX_Boolean is_service,
356  ATX_UInt32 crypto_period,
357  const ATX_Byte* traffic_seed,
358  ATX_Size seed_size,
359  ATX_UInt32 segment_start_index,
360  const ATX_Byte* common_iv,
361  ATX_Boolean single_key_layer,
362  TS2_KSMT* ksmt, /* doesn't take ownership */
363  const ATX_Byte* access_criteria,
364  ATX_Size access_criteria_size,
365  TS2_PacketEncrypter** encrypter);
366 
367 ATX_Result
369  const ATX_Byte* drm_key,
370  const ATX_Byte* cid_extension,
371  ATX_Boolean is_service,
372  const ATX_Byte* access_criteria,
373  ATX_Size access_criteria_size);
374 
375 ATX_Result
377 
378 void
380 
381 ATX_Result
383  TS2_Packet* packet);
384 
385 void
387 
388 /*----------------------------------------------------------------------
389 | TS2_KsmDecrypter functions
390 +---------------------------------------------------------------------*/
391 typedef enum {
395 
396 typedef struct {
397  ATX_Byte tag;
398  ATX_Byte length;
399  ATX_Byte* value;
401 
402 typedef enum {
406  TS2_KIF_NEXT_IV = (1<<3),
412 
413 typedef struct {
414  ATX_UInt32 present_mask; /* from TS2_KsmInfoFlag */
415 
417  const void* format_params;
419  const ATX_Byte* current_key;
421  const ATX_Byte* current_iv;
422  ATX_Size current_iv_size;
423  const ATX_Byte* next_key;
424  ATX_Size next_key_size;
425  const ATX_Byte* next_iv;
426  ATX_Size next_iv_size;
427  ATX_Byte* access_criteria;
429  ATX_UInt64 timestamp;
430  ATX_UInt8 key_lifetime;
433 } TS2_KsmInfo;
434 
435 typedef struct {
436  void *instance;
437  void (*OnKsmInfoChange)(void *instance,
438  const TS2_KsmInfo* ksm_info,
439  ATX_UInt32 change_mask /* from TS2_KsmInfoFlag */);
441 
443 
444 ATX_Result
445 TS2_KsmDecrypter_Create(const char* cid_base,
446  TS2_CryptoInterface crypto,
447  TS2_KsmDecrypterListener listener,
448  TS2_TrafficProtectionSystem protection,
449  ATX_UInt32 kdf_type,
450  TS2_KsmDecrypter** decrypter);
451 
452 ATX_Result
454  const TS2_KSM* ksm);
455 
456 void
458 
459 
460 /*----------------------------------------------------------------------
461 | TS2_PacketDecrypter functions
462 +---------------------------------------------------------------------*/
463 ATX_Result
465  ATX_UInt32 kdf_type,
466  const char* cid_base,
467  TS2_DrmKeyResolver key_resolver,
468  TS2_CryptoInterface* crypto,
469  TS2_PacketDecrypter** decrypter);
470 
471 ATX_Result
473  const TS2_KSM* ksm);
474 
475 ATX_Result
477  TS2_Packet* packet);
478 
479 void
481 
482 /*----------------------------------------------------------------------
483 | TS2_ProtectionKeyMap functions
484 +---------------------------------------------------------------------*/
485 ATX_Result
487 
489 ATX_Result
491  const char* content_id,
492  const ATX_Byte* key);
493 
494 const ATX_Byte*
496  const char* content_id);
497 
500 
501 void
503 
504 /*----------------------------------------------------------------------
505 | Key Material Generation functions
506 +---------------------------------------------------------------------*/
507 ATX_Result
508 TS2_GenerateTrafficKey(const ATX_Byte* seed,
509  ATX_Size seed_size,
510  ATX_UInt32 index,
511  ATX_Byte* traffic_key);
512 
513 ATX_Result
514 TS2_GenerateInitializationVector(const ATX_Byte* seed,
515  ATX_Size seed_size,
516  ATX_UInt32 index,
517  ATX_Byte* iv);
518 
519 #ifdef __cplusplus
520 }
521 #endif /* __cplusplus */
522 
523 
524 #endif /* _TS2_PROTECTION_H_ */