📄 psfdemux_drm.c
字号:
/* * Already setup ciphertable index? */ if (!ecm_key->ciphertable_done) { /* * scrambling = ? offset_control = ? offset_value = ? */ if (key_type == EVEN_KEY) { ecm_key->scrambling = EMhwlibScramblingBits_10; } else { ecm_key->scrambling = EMhwlibScramblingBits_11; } ecm_key->offset_control = EMhwlibInbandOffset_Ignore; ecm_key->offset_value = 0; /* * Set key for entry #emc_key->index_cipher_table in CipherTable */ outband.cipher_type = EMhwlibCipher_Multi2; outband.cipher_index = ecm_key->index_cipher_table; outband.scrambling = ecm_key->scrambling; outband.key_index = ecm_key->multi2_key.key_index; err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_OutbandKeyChange, &outband, sizeof(outband), 0); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "Error RMDemuxTaskPropertyID_OutbandKeyChange\n")); return(err); } ecm_key->ciphertable_done = TRUE; } return(err);#else return RM_NOTIMPLEMENTED;#endif // #if (ALLOW_LIBRMARIB)}/************************************************************************ * Select the special way to setup Multi2 key entry. ************************************************************************/RMstatus Multi2KeySetup(struct context_per_task *context, enum key_setup_ways ways, RMuint32 index, enum key_type key_type){ RMstatus err; switch (ways) { default: case OUTBAND_COMMAND: err = Multi2KeyOutband(context, index, key_type); break; case INBAND_COMMAND: err = Multi2KeyInband(context, index, key_type); break;#if (ALLOW_LIBRMARIB) case XTASK_CLEAR: err = Multi2KeyXtask(context, index, key_type); break; case XTASK_CIPHER: err = Multi2KeyXtaskEncrypted(context, index, key_type); break;#endif } if (RMFAILED(err)) { fprintf(stderr, "multi2 key setup failure\n"); } return err;}RMstatus InitKeyAndCipherTable(struct context_per_task *context){ RMstatus err; RMuint32 key_1st; RMuint32 key_2nd; RMuint32 key_3rd; RMuint32 key_4th; RMuint32 i; enum EMhwlibCipher cipher_type;#ifdef MULTI2_EIGHT_KEYS RMuint32 default_number_of_ciphers = 8;#else RMuint32 default_number_of_ciphers = 2;#endif context->cipher_count = 0; context->key_count = 0; // allocate two cipher for now (for video and audio) // Allocate the first cipher for current task for( i=0; i<default_number_of_ciphers; i++ ) { RMuint32 cipher_1st; err = RUAGetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AllocateCipherEntry, &cipher_1st, sizeof(cipher_1st)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error RMDemuxTaskPropertyID_AllocateCipherEntry")); return err; } context->cipher_index[context->cipher_count] = cipher_1st; context->cipher_count++; RMDBGLOG((KEYDBG, "InitKeyAndCipherTable RMDemuxTaskPropertyID_AllocateCipherEntry %ld\n", cipher_1st)); }#if 0 /* enable cipher in Pid entries - InitPidTablePerTask will use this information */ for (i = 0; i < context->pid_table_count; i++) { struct PidEntry_type *p = context->pid_table; p[i].cipher_mask = 1<<context->cipher_index[0]; // only one cipher per pid is supported for now p[i].cipher_index[0] = context->cipher_index[0]; // assigned the first cipher to all pids as the default RMDBGLOG((KEYDBG, "InitKeyAndCipherTable added cipher %ld to pid %d\n", context->cipher_index[0], i)); }#endif if (context->app_type == dvbcsa_decryption) { struct DemuxTask_DVBCSACipherEntry_type cipher; // 1st cipher entry cipher.index = context->cipher_index[0]; err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_DVBCSACipherEntry, &cipher, sizeof(cipher), 0); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error RMDemuxTaskPropertyID_DVBCSACipherEntry\n")); return RM_ERROR; } /* allocate two keys even and odd */ cipher_type = EMhwlibCipher_DVBCSA; err = RUAExchangeProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AllocateKeyEntry, &cipher_type, sizeof(cipher_type), &(key_1st), sizeof(key_1st)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error 1st RMDemuxTaskPropertyID_AllocateKeyEntry\n")); return RM_ERROR; } RMDBGLOG((ENABLE, "DvbCSA [%ld] RMDemuxTaskPropertyID_AllocateKeyEntry %ld\n", context->key_count, key_1st)); context->key_index[context->key_count] = key_1st; context->key_count++; err = RUAExchangeProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AllocateKeyEntry, &cipher_type, sizeof(cipher_type), &(key_2nd), sizeof(key_2nd)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error 2nd RMDemuxTaskPropertyID_AllocateKeyEntry\n")); return RM_ERROR; } RMDBGLOG((ENABLE, "DvbCSA [%ld] RMDemuxTaskPropertyID_AllocateKeyEntry %ld\n", context->key_count, key_2nd)); context->key_index[context->key_count] = key_2nd; context->key_count++; // 2nd cipher entry cipher.index = context->cipher_index[1]; err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_DVBCSACipherEntry, &cipher, sizeof(cipher), 0); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error RMDemuxTaskPropertyID_DVBCSACipherEntry\n")); return RM_ERROR; } /* allocate two keys even and odd */ cipher_type = EMhwlibCipher_DVBCSA; err = RUAExchangeProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AllocateKeyEntry, &cipher_type, sizeof(cipher_type), &(key_3rd), sizeof(key_3rd)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error 1st RMDemuxTaskPropertyID_AllocateKeyEntry\n")); return RM_ERROR; } RMDBGLOG((ENABLE, "DvbCSA [%ld] RMDemuxTaskPropertyID_AllocateKeyEntry %ld\n", context->key_count, key_3rd)); context->key_index[context->key_count] = key_3rd; context->key_count++; err = RUAExchangeProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AllocateKeyEntry, &cipher_type, sizeof(cipher_type), &(key_4th), sizeof(key_4th)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error 2nd RMDemuxTaskPropertyID_AllocateKeyEntry\n")); return RM_ERROR; } RMDBGLOG((ENABLE, "DvbCSA [%ld] RMDemuxTaskPropertyID_AllocateKeyEntry %ld\n", context->key_count, key_4th)); context->key_index[context->key_count] = key_4th; context->key_count++; } else if (context->app_type == multi2_decryption) { cipher_type = EMhwlibCipher_Multi2; // Setup cipher entry and key indices in CipherTable for(i=0;i<default_number_of_ciphers;i++) { struct DemuxTask_Multi2CipherEntry_type cipher; // hard code the relation between cipher and key // cipher[i] uses key[i*2] and key[i*2+1] // EVEN key for DVB-Arib context->arib_key_table[i*2].new_key = FALSE; context->arib_key_table[i*2].ciphertable_done = FALSE; context->arib_key_table[i*2].index_cipher_table = context->cipher_index[i]; //cipher table entry // ODD key for DVB-Arib context->arib_key_table[i*2+1].new_key = FALSE; context->arib_key_table[i*2+1].ciphertable_done = FALSE; context->arib_key_table[i*2+1].index_cipher_table = context->cipher_index[i]; //cipher table entry // hard coded the mode and round value cipher.mode = EMhwlibMulti2_CBC_decryption; cipher.round_value = 32; // Hardcoded 32 for Arib cipher.index = context->cipher_index[i]; err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_Multi2CipherEntry, &cipher, sizeof(cipher), 0); if (RMFAILED(err)) { RMDBGLOG((ENABLE,"Error RMDemuxTaskPropertyID_Mult2CipherEntry\n")); return err; } // Allocate two keys even and odd err = RUAExchangeProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AllocateKeyEntry, &cipher_type, sizeof(cipher_type), &(key_1st), sizeof(key_1st)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error 1st RMDemuxTaskPropertyID_AllocateKeyEntry\n")); return RM_ERROR; } context->arib_key_table[i*2].multi2_key.key_index = key_1st; context->key_index[i*2] = key_1st; //the key_index is used in the same way as arib_key_table context->key_count++; err = RUAExchangeProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AllocateKeyEntry, &cipher_type, sizeof(cipher_type), &(key_2nd), sizeof(key_2nd)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error 2nd" " RMDemuxTaskPropertyID_AllocateKeyEntry\n")); return RM_ERROR; } context->arib_key_table[i*2+1].multi2_key.key_index = key_2nd; context->key_index[i*2+1] = key_2nd; context->key_count++; } } else if((context->app_type == aes_cbc_decryption) || (context->app_type == aes_ecb_decryption) || (context->app_type == aes_nsa_decryption) || (context->app_type == aes_ofb_decryption) ) { struct DemuxTask_AESCipherEntry_type cipher; // 1st cipher entry cipher.index = context->cipher_index[0]; if (context->app_type == aes_cbc_decryption) { cipher.mode = EMhwlibAES_CBC_decryption; cipher.key_size = (context->key_size) << 3; /* 16 * 8 = 128bits */ cipher.block_size = (context->key_size) << 3; /* 16 * 8 = 128bits */ cipher.encrypted_packet_format = EMhwlibAES_UDAC; /* encryption starting from start of TS payload */ } else if(context->app_type == aes_ecb_decryption) { cipher.mode = EMhwlibAES_ECB_decryption; cipher.key_size = (context->key_size) << 3; /* 16 * 8 = 128bits */ cipher.block_size = (context->key_size) << 3; /* 16 * 8 = 128bits */#ifdef AES_ECB_KEY_TABLE cipher.encrypted_packet_format = EMhwlibAES_UDAC; /* encryption starting from end of TS payload */#else cipher.encrypted_packet_format = EMhwlibAES_Synamedia; /* encryption starting from end of TS payload */#endif } else if( context->app_type == aes_ofb_decryption ) { cipher.mode = EMhwlibAES_CBC_decryption; cipher.key_size = (context->key_size) << 3; /* 16 * 8 = 128bits */ cipher.block_size = (context->key_size) << 3; /* 16 * 8 = 128bits */ cipher.encrypted_packet_format = EMhwlibAES_OFB; /* encryption starting from end of TS payload */ } else if( context->app_type == aes_nsa_decryption ) { cipher.mode = EMhwlibAES_CFB_decryption; cipher.key_size = 128; /* ucode set this */ cipher.block_size = 128; /* ucode set this */ cipher.encrypted_packet_format = EMhwlibAES_NSA; RMDBGLOG((KEYDBG, "InitKeyAndCipherTable mode=0x%lx key_size=%ld block_size=%ld format=0x%lx\n", cipher.mode, cipher.key_size, cipher.block_size, cipher.encrypted_packet_format)); } else { RMDBGLOG((KEYDBG, "InitKeyAndCipherTable Error unknown app_type\n")); } err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AESCipherEntry, &cipher, sizeof(cipher), 0); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error RMDemuxTaskPropertyID_AESCipherEntry\n")); return RM_ERROR; } /* allocate the first pair keys one even one odd */ cipher_type = EMhwlibCipher_AES; err = RUAExchangeProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AllocateKeyEntry, &cipher_type, sizeof(cipher_type), &(key_1st), sizeof(key_1st)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error 1st RMDemuxTaskPropertyID_AllocateKeyEntry\n")); return RM_ERROR; } context->key_index[context->key_count] = key_1st; context->key_count++; RMDBGLOG((KEYDBG, "InitKeyAndCipherTable Allocated key %ld, index %ld for cipher %ld\n", context->key_count-1, key_1st, context->cipher_index[0] )); err = RUAExchangeProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AllocateKeyEntry, &cipher_type, sizeof(cipher_type), &(key_2nd), sizeof(key_2nd)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error 2nd RMDemuxTaskPropertyID_AllocateKeyEntry\n")); return RM_ERROR; } context->key_index[context->key_count] = key_2nd; context->key_count++; RMDBGLOG((KEYDBG, "InitKeyAndCipherTable Allocated key %ld, index %ld for cipher %ld\n", context->key_count-1, key_2nd, context->cipher_index[0] )); /* 2nd cipher entry */ cipher.index = context->cipher_index[1]; err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AESCipherEntry, &cipher, sizeof(cipher), 0); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error RMDemuxTaskPropertyID_AESCipherEntry\n")); return RM_ERROR; } /* allocate the second pair keys one even one odd */ cipher_type = EMhwlibCipher_AES; err = RUAExchangeProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AllocateKeyEntry, &cipher_type, sizeof(cipher_type), &(key_3rd), sizeof(key_3rd)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error 2nd RMDemuxTaskPropertyID_AllocateKeyEntry\n")); return RM_ERROR; } context->key_index[context->key_count] = key_3rd; context->key_count++; RMDBGLOG((KEYDBG, "InitKeyAndCipherTable Allocated key %ld, index %ld for cipher %ld\n", context->key_count-1, key_3rd, context->cipher_index[1] )); err = RUAExchangeProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AllocateKeyEntry, &cipher_type, sizeof(cipher_type), &(key_4th), sizeof(key_4th)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "InitKeyAndCipherTable Error 2nd RMDemuxTaskPropertyID_AllocateKeyEntry\n")); return RM_ERROR; } context->key_index[context->key_count] = key_4th; context->key_count++; RMDBGLOG((KEYDBG, "InitKeyAndCipherTable Allocated key %ld, index %ld for cipher %ld\n", context->key_count-1, key_4th, context->cipher_index[1])); } /* ############## AES_CBC_PRECIPHER CODE BEGIN ############## */ else if ((context->test_aes_precipher == TRUE) || (context->dtcpip_streaming == TRUE)) { struct DemuxTask_AESCipherEntry_type cipher; /************** set AES CipherEntry ****************/ context->key_size = 16; cipher.index = context->cipher_index[0]; cipher.mode = EMhwlibAES_CBC_decryption; cipher.key_size = (context->key_size)<< 3; /* 16 * 8 = 128bits */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -