hdmi_hdcp.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. #include "drv_types.h"
  2. #include <asm/io.h>
  3. #include "hdmi_hdcp.h"
  4. #include "../kmf/kmflib/bf.h"
  5. #include "drv_spi.h" /*spi_read_flash()*/
  6. #include <linux/slab.h> /*kmalloc(), kfree()*/
  7. #define HDCP_RAWKEY_SIZE (288)
  8. #define HDCP_CKEY_SIZE (512)
  9. #define HDCP_VKEY_SIZE (32)
  10. #define HDCP_RKEY_SIZE (40)
  11. #define HDCP_CRC_SIZE (4)
  12. #define HDCP_KEY_SIZE (HDCP_CKEY_SIZE+HDCP_VKEY_SIZE+HDCP_RKEY_SIZE)
  13. #ifdef CONFIG_SUPPORT_STORE_HDCP2X_TO_FLASH
  14. #define HDCP2X_RAWKEY_SIZE (898)
  15. #define HDCP2X_CKEY_SIZE (1024)
  16. #define HDCP2X_VKEY_SIZE (32)
  17. #define HDCP2X_RKEY_SIZE (40)
  18. #define HDCP2X_CRC_SIZE (4)
  19. #define HDCP2X_KEY_SIZE (HDCP2X_CKEY_SIZE+HDCP2X_VKEY_SIZE+HDCP2X_RKEY_SIZE)
  20. #define HDCP2X_HEADER_SIZE (4)
  21. #define HDCP2X_LIC_CONST_SIZE (36) //Licensed Constant
  22. #define HDCP2X_PUB_CERT_SIZE (522) //Public Certificate
  23. #define HDCP2X_PVT_KEY_SIZE (340) //Private Key
  24. #endif
  25. //debug message
  26. //#define SUPPORT_PRINT_HDCP_MESSAGE
  27. // ----- local static variables/functions -----
  28. #pragma pack(push,1)
  29. typedef struct __HDCPKEY_FMT
  30. {
  31. union
  32. {
  33. UINT32 data[(HDCP_KEY_SIZE/4)];
  34. struct
  35. {
  36. UINT8 ckey[HDCP_CKEY_SIZE];
  37. UINT8 vkey[HDCP_VKEY_SIZE];
  38. UINT8 rkey[HDCP_RKEY_SIZE];
  39. };
  40. };
  41. UINT32 crc;
  42. } HDCPKEY_FMT, *HDCPKEY_FMT_PTR;
  43. #ifdef CONFIG_SUPPORT_STORE_HDCP2X_TO_FLASH
  44. typedef struct __HDCP2X_KEY_FMT
  45. {
  46. union
  47. {
  48. UINT32 data[(HDCP2X_KEY_SIZE/4)];
  49. struct
  50. {
  51. UINT8 ckey[HDCP2X_CKEY_SIZE];
  52. UINT8 vkey[HDCP2X_VKEY_SIZE];
  53. UINT8 rkey[HDCP2X_RKEY_SIZE];
  54. };
  55. };
  56. UINT32 crc;
  57. } HDCP2X_KEY_FMT, *HDCP2X_KEY_FMT_PTR;
  58. typedef struct __HDCP2X_REV_KEY_SET
  59. {
  60. struct
  61. {
  62. UINT8 Header[HDCP2X_HEADER_SIZE];
  63. UINT8 LicConst[HDCP2X_LIC_CONST_SIZE];
  64. UINT8 PubCert[HDCP2X_PUB_CERT_SIZE];
  65. UINT8 PvtKey[HDCP2X_PVT_KEY_SIZE];
  66. };
  67. } HDCP2X_REV_KEY_SET, *HDCP2X_REV_KEY_SET_PTR;
  68. #endif
  69. #pragma pack(pop)
  70. static BOOL bHDCP_CRC = false;
  71. static UINT8 local_ksv[5];
  72. static UINT8 local_key_data[HDCP_RAWKEY_SIZE];
  73. #ifdef CONFIG_SUPPORT_STORE_HDCP2X_TO_FLASH
  74. static UINT8 local_2Xkey_data[HDCP2X_RAWKEY_SIZE];
  75. #endif
  76. #ifdef CONFIG_DISABLE_CIKEY_HDCPKEY_SPI_ENCRYPT
  77. extern void do_spi_encrypt(char *, unsigned int, unsigned int);
  78. #endif
  79. #ifdef SUPPORT_PRINT_HDCP_MESSAGE
  80. static void dump(const UINT8 *ptr, INT32 size)
  81. {
  82. INT32 i, n;
  83. INT8 str[3 * 0x10 + 8];
  84. for (n = 0, i = 0; i < size; i++)
  85. {
  86. if (n >= 0)
  87. {
  88. n += sprintf(&str[n], "%02x ", ptr[i]);
  89. }
  90. if (n >= 3 * 0x10 || i + 1 == size)
  91. {
  92. n = 0;
  93. printk("%s\n", str);
  94. }
  95. }
  96. }
  97. #endif
  98. /* Keep the encrypt functions for future use */
  99. #if 0
  100. static void cmN_arraBye_shift_inc(INT8 *pChar, INT32 byteLen, INT32 bitShift)
  101. {
  102. //limit 1024 byte
  103. UINT8 *pBye;
  104. UINT8 pBAck[1024];
  105. INT32 i;
  106. INT32 offByte, offBit;
  107. ULONG tempDW;
  108. pBye = (UINT8 *)pChar;
  109. if (byteLen > 1024)
  110. {
  111. return;
  112. }
  113. offByte = bitShift / 8;
  114. offByte = offByte % byteLen;
  115. offBit = bitShift & 0x07;//%8
  116. if (offByte)
  117. {
  118. memcpy(pBAck, pBye, byteLen);
  119. for (i = 0; i < byteLen ; i++)
  120. {
  121. if ((i + offByte) < byteLen)
  122. {
  123. pBye[i + offByte] = pBAck[i];
  124. }
  125. else
  126. {
  127. pBye[i + offByte - byteLen] = pBAck[i];
  128. }
  129. }
  130. }
  131. if (offBit)
  132. {
  133. memcpy(pBAck, pBye, byteLen);
  134. for (i = 0; i < byteLen ; i++)
  135. {
  136. if (i == 0)
  137. {
  138. tempDW = (((UINT32)pBAck[0]) << 8) + pBAck[byteLen - 1];
  139. }
  140. else
  141. {
  142. tempDW = (((UINT32)pBAck[i]) << 8) + pBAck[i - 1];
  143. }
  144. tempDW = tempDW >> (8 - offBit);
  145. pBye[i] = (UINT8)tempDW;
  146. }
  147. }
  148. }
  149. static void byteEncryption(UINT8 *pByte, INT32 length)
  150. {
  151. UINT8 seed1, seed2, seed3;
  152. INT32 i;
  153. UINT8 temp1, temp2;
  154. UINT8 temp3, temp4;
  155. UINT8 temp5, temp6;
  156. UINT8 tt;
  157. if (length > 4)
  158. {
  159. pByte[1] = (pByte[1] + pByte[0]) & 0xff;
  160. pByte[length - 2] = (pByte[length - 2] + pByte[length - 1]) & 0xff;
  161. cmN_arraBye_shift_inc((INT8 *)(pByte + 1), (length - 2), (INT32)(((pByte[0] + pByte[length - 1])) * 19) & 0xff);
  162. }
  163. tt = 0x98;
  164. for (i = 0; i < length; i++)
  165. {
  166. *(pByte + i) = (*(pByte + i)) ^ tt;
  167. tt++;
  168. }
  169. seed1 = 0xee;
  170. seed2 = 0x5A;
  171. seed3 = 0x63;
  172. for (i = 0; i < length; i++)
  173. {
  174. *(pByte + i) = (*(pByte + i)) ^ seed1;
  175. }
  176. if (length > 2)
  177. {
  178. for (i = 0; i < length / 2; i++)
  179. {
  180. //1234 to 41 23
  181. temp1 = (*(pByte + i)) & 0xF0;
  182. temp2 = (*(pByte + i)) & 0x0F;
  183. temp3 = (*(pByte + i + (length / 2))) & 0xF0;
  184. temp4 = (*(pByte + i + (length / 2))) & 0x0F;
  185. (*(pByte + i)) = (temp4 << 4) | (temp1 >> 4);
  186. (*(pByte + i + (length / 2))) = (temp2 << 4) | (temp3 >> 4);
  187. }
  188. }
  189. for (i = 0; i < length; i++)
  190. {
  191. *(pByte + i) = (*(pByte + i)) ^ seed2;
  192. }
  193. tt = 0x6c;
  194. for (i = 0; i < length; i++)
  195. {
  196. *(pByte + i) = (*(pByte + i)) ^ tt;
  197. tt += 0xf9;
  198. }
  199. if (length > 3)
  200. {
  201. for (i = 0; i < length / 3; i++)
  202. {
  203. //123456 to 54 16 32
  204. temp1 = (*(pByte + i)) & 0xF0;
  205. temp2 = (*(pByte + i)) & 0x0F;
  206. temp3 = (*(pByte + i + (length / 3) * 1)) & 0xF0;
  207. temp4 = (*(pByte + i + (length / 3) * 1)) & 0x0F;
  208. temp5 = (*(pByte + i + (length / 3) * 2)) & 0xF0;
  209. temp6 = (*(pByte + i + (length / 3) * 2)) & 0x0F;
  210. (*(pByte + i)) = (temp5) | (temp4);
  211. (*(pByte + i + (length / 3) * 1)) = (temp1) | (temp6);
  212. (*(pByte + i + (length / 3) * 2)) = (temp3) | (temp2);
  213. }
  214. }
  215. for (i = 0; i < length; i++)
  216. {
  217. *(pByte + i) = (*(pByte + i)) ^ seed3;
  218. }
  219. }
  220. #endif
  221. static void cmN_arraBye_shift_dec(INT8 *pChar, INT32 byteLen, INT32 bitShift)
  222. {
  223. //limit 1024 byte
  224. UINT8 *pBye;
  225. INT32 i;
  226. INT32 offByte, offBit;
  227. ULONG tempDW;
  228. UINT8 *pBAck = kmalloc(1024, GFP_KERNEL);
  229. pBye = (UINT8*)pChar;
  230. if (pBAck == NULL)
  231. {
  232. return;
  233. }
  234. if (byteLen > 1024)
  235. {
  236. kfree(pBAck) ;
  237. return;
  238. }
  239. offByte = bitShift / 8;
  240. offByte = offByte % byteLen;
  241. offBit = bitShift & 0x07;//%8
  242. if (offByte)
  243. {
  244. memcpy(pBAck, pBye, byteLen);
  245. for (i = 0; i < byteLen ; i++)
  246. {
  247. if ((i + offByte) < byteLen)
  248. {
  249. pBye[i] = pBAck[i + offByte];
  250. }
  251. else
  252. {
  253. pBye[i] = pBAck[i + offByte - byteLen];
  254. }
  255. }
  256. }
  257. if (offBit)
  258. {
  259. memcpy(pBAck, pBye, byteLen);
  260. for (i = 0; i < byteLen ; i++)
  261. {
  262. if (i == byteLen - 1)
  263. {
  264. tempDW = (((UINT32)pBAck[0]) << 8) + pBAck[byteLen - 1];
  265. }
  266. else
  267. {
  268. tempDW = (((UINT32)pBAck[i + 1]) << 8) + pBAck[i];
  269. }
  270. tempDW = tempDW >> offBit;
  271. pBye[i] = (UINT8)tempDW;
  272. }
  273. }
  274. kfree(pBAck) ;
  275. }
  276. static void byteDecryption(UINT8 *pByte, INT32 length)
  277. {
  278. UINT8 seed1, seed2, seed3;
  279. INT32 i;
  280. UINT8 temp1, temp2;
  281. UINT8 temp3, temp4;
  282. UINT8 temp5, temp6;
  283. UINT8 tt;
  284. seed1 = 0xee;
  285. seed2 = 0x5A;
  286. seed3 = 0x63;
  287. for (i = 0; i < length; i++)
  288. {
  289. *(pByte + i) = (*(pByte + i)) ^ seed3;
  290. }
  291. if (length > 3)
  292. {
  293. for (i = 0; i < length / 3; i++)
  294. {
  295. //123456 to 54 16 32
  296. temp5 = (*(pByte + i)) & 0xF0;
  297. temp4 = (*(pByte + i)) & 0x0F;
  298. temp1 = (*(pByte + i + (length / 3) * 1)) & 0xF0;
  299. temp6 = (*(pByte + i + (length / 3) * 1)) & 0x0F;
  300. temp3 = (*(pByte + i + (length / 3) * 2)) & 0xF0;
  301. temp2 = (*(pByte + i + (length / 3) * 2)) & 0x0F;
  302. (*(pByte + i)) = (temp1) | (temp2);
  303. (*(pByte + i + (length / 3) * 1)) = (temp3) | (temp4);
  304. (*(pByte + i + (length / 3) * 2)) = (temp5) | (temp6);
  305. }
  306. }
  307. tt = 0x6c;
  308. for (i = 0; i < length; i++)
  309. {
  310. *(pByte + i) = (*(pByte + i)) ^ tt;
  311. tt += 0xf9;
  312. }
  313. for (i = 0; i < length; i++)
  314. {
  315. *(pByte + i) = (*(pByte + i)) ^ seed2;
  316. }
  317. if (length > 2)
  318. {
  319. for (i = 0; i < length / 2; i++)
  320. {
  321. //1234 to 41 23
  322. temp4 = (*(pByte + i)) & 0xF0;
  323. temp1 = (*(pByte + i)) & 0x0F;
  324. temp2 = (*(pByte + i + (length / 2))) & 0xF0;
  325. temp3 = (*(pByte + i + (length / 2))) & 0x0F;
  326. (*(pByte + i)) = (temp1 << 4) | (temp2 >> 4);
  327. (*(pByte + i + (length / 2))) = (temp3 << 4) | (temp4 >> 4);
  328. }
  329. }
  330. for (i = 0; i < length; i++)
  331. {
  332. *(pByte + i) = (*(pByte + i)) ^ seed1;
  333. }
  334. tt = 0x98;
  335. for (i = 0; i < length; i++)
  336. {
  337. *(pByte + i) = (*(pByte + i)) ^ tt;
  338. tt++;
  339. }
  340. if (length > 4)
  341. {
  342. cmN_arraBye_shift_dec((INT8 *)(pByte + 1), (length - 2), (INT32)(((pByte[0] + pByte[length - 1])) * 19) & 0xff);
  343. pByte[length - 2] = (pByte[length - 2] - pByte[length - 1]) & 0xff;
  344. pByte[1] = (pByte[1] - pByte[0]) & 0xff;
  345. }
  346. }
  347. static void henx(UINT8* key_addr)
  348. {
  349. UINT8* dk_addr = key_addr + 8;
  350. UINT8 xor_bytes[7] =
  351. {
  352. 0x4a, 0x65, 0x67, 0x72, 0x6f, 0x65, 0x47
  353. };
  354. UINT8 map[40] =
  355. {
  356. 17, 36, 12, 29, 21, 10, 18, 37, 31, 1 ,
  357. 2, 23, 35, 7, 27, 39, 3, 16, 8, 33,
  358. 28, 25, 6, 14, 13, 4, 0, 20, 30, 9 ,
  359. 5, 32, 38, 11, 15, 26, 19, 22, 34, 24
  360. };
  361. UINT8 temp[280];
  362. INT32 i = 0, j = 0;
  363. for (i = 0; i < 40; i++)
  364. {
  365. for (j = 0; j < 7; j++)
  366. {
  367. temp[map[i] * 7 + j] = dk_addr[i * 7 + j] ^ xor_bytes[j];
  368. }
  369. }
  370. memcpy(dk_addr, temp, 280);
  371. }
  372. #ifdef CONFIG_SUPPORT_STORE_HDCP2X_TO_FLASH
  373. static INT32 xcrypt_HDCP2X(UINT8 *in, UINT8 *out, UINT32 len)
  374. {
  375. // input 1024-byte HDCP encoded data, output 898-byte HDCP key.
  376. UINT32 SAMPLE_KEY1_DW = 0x01234567;
  377. UINT32 SAMPLE_KEY2_DW = 0x89abcdef;
  378. INT32 i = 0;
  379. UINT8 pInSeed[sizeof(ULONG)];
  380. memcpy(pInSeed, &SAMPLE_KEY1_DW, sizeof(ULONG));
  381. for (i = 0 ; i < 36 ; i++)
  382. {
  383. *(out + i) = *(in + i) ^ pInSeed[i % 4];
  384. }
  385. memcpy(pInSeed, &SAMPLE_KEY2_DW, sizeof(ULONG));
  386. for (i = 36 ; i < 898 ; i++)
  387. {
  388. *(out + i) = *(in + i) ^ pInSeed[i % 4];
  389. }
  390. return 0;
  391. }
  392. #endif
  393. static INT32 xcrypt(UINT8 *in, UINT8 *out, UINT32 len)
  394. {
  395. // input 512-byte HDCP encoded data, output 288-byte HDCP key.
  396. UINT32 SAMPLE_KEY1_DW = 0x01234567;
  397. UINT32 SAMPLE_KEY2_DW = 0x89abcdef;
  398. INT32 i = 0;
  399. UINT8 pInSeed[sizeof(ULONG)];
  400. memcpy(pInSeed, &SAMPLE_KEY1_DW, sizeof(ULONG));
  401. for (i = 0 ; i < 5 ; i++)
  402. {
  403. *(out + i) = *(in + i) ^ pInSeed[i % 4];
  404. }
  405. memcpy(pInSeed, &SAMPLE_KEY2_DW, sizeof(ULONG));
  406. for (i = 8 ; i < 288 ; i++)
  407. {
  408. *(out + i) = *(in + i) ^ pInSeed[i % 4];
  409. }
  410. return 0;
  411. }
  412. UINT32 hdmi_get_hdcp_data(INT32 offset)
  413. {
  414. UINT32 *data = (UINT32*)local_key_data;
  415. return data[offset];
  416. }
  417. BOOL DRV_HDMI_CheckHdcpKey(void)
  418. {
  419. return bHDCP_CRC;
  420. }
  421. void DRV_HDMI_GetHDCPKeyKSV(UINT8 *ksv)
  422. {
  423. memcpy(ksv, &local_ksv, 5);
  424. }
  425. void DRV_HDMI_UpdateHDCPKey(UINT8 *key_ptr)
  426. {
  427. INT32 i;
  428. UINT32 calculated_crc;
  429. UINT8 *pbHdcpKey;
  430. HDCPKEY_FMT_PTR key;
  431. #ifdef CONFIG_DISABLE_CIKEY_HDCPKEY_SPI_ENCRYPT
  432. UINT8 *pbHdcpKey_tmp;
  433. #endif
  434. pbHdcpKey = kmalloc(sizeof(UINT8) * (HDCP_KEY_SIZE+HDCP_CRC_SIZE), GFP_KERNEL);
  435. spi_read_flash(pbHdcpKey, (UINT8*)key_ptr, (HDCP_KEY_SIZE+HDCP_CRC_SIZE));
  436. #ifdef CONFIG_DISABLE_CIKEY_HDCPKEY_SPI_ENCRYPT
  437. pbHdcpKey_tmp = kmalloc((((HDCP_KEY_SIZE+HDCP_CRC_SIZE+15)>>4)<<4), GFP_KERNEL);
  438. memcpy((void *)pbHdcpKey_tmp, (void *)pbHdcpKey, (HDCP_KEY_SIZE+HDCP_CRC_SIZE));
  439. do_spi_encrypt((INT8 *)pbHdcpKey_tmp, (((HDCP_KEY_SIZE+HDCP_CRC_SIZE+15)>>4)<<4), 0);
  440. memcpy((void *)pbHdcpKey, (void *)pbHdcpKey_tmp, (HDCP_KEY_SIZE+HDCP_CRC_SIZE));
  441. kfree(pbHdcpKey_tmp);
  442. #endif
  443. key = (HDCPKEY_FMT_PTR)pbHdcpKey;
  444. /* Input data is encrypted and decryption needed */
  445. calculated_crc = 0;
  446. for (i = 0; i < (HDCP_KEY_SIZE/4); i++)
  447. {
  448. calculated_crc += (UINT32)key->data[i];
  449. }
  450. bHDCP_CRC = (calculated_crc == key->crc) ? 1 : 0;
  451. byteDecryption(key->vkey, HDCP_VKEY_SIZE);
  452. byteDecryption(key->rkey, HDCP_RKEY_SIZE);
  453. bf_decrypt(key->ckey, HDCP_CKEY_SIZE, key->rkey, HDCP_RKEY_SIZE);
  454. xcrypt(key->ckey, key->ckey, HDCP_CKEY_SIZE);
  455. /* Update local ksv data */
  456. memcpy(local_ksv, key->ckey, 5);
  457. /* Update to local key data */
  458. memcpy(local_key_data, key->ckey, HDCP_RAWKEY_SIZE);
  459. #ifdef SUPPORT_PRINT_HDCP_MESSAGE
  460. printk("hdcp raw key\n");
  461. dump(local_key_data, HDCP_RAWKEY_SIZE);
  462. #endif
  463. /* Transform raw hdcp key into hw format */
  464. henx(local_key_data);
  465. #ifdef SUPPORT_PRINT_HDCP_MESSAGE
  466. printk("henx\n");
  467. dump(local_key_data, HDCP_RAWKEY_SIZE);
  468. #endif
  469. kfree(pbHdcpKey);
  470. }
  471. #ifdef CONFIG_SUPPORT_STORE_HDCP2X_TO_FLASH
  472. void DRV_HDMI_UpdateHDCP2XKey(UINT8 *key_ptr)
  473. {
  474. INT32 i;
  475. UINT32 calculated_crc;
  476. UINT8 *pbHdcpKey;
  477. HDCP2X_KEY_FMT_PTR key;
  478. HDCP2X_REV_KEY_SET Hdcp2X_Key;
  479. #ifdef CONFIG_DISABLE_CIKEY_HDCPKEY_SPI_ENCRYPT
  480. UINT8 *pbHdcpKey_tmp;
  481. #endif
  482. pbHdcpKey = kmalloc(sizeof(UINT8) * (HDCP2X_KEY_SIZE+HDCP2X_CRC_SIZE), GFP_KERNEL);
  483. spi_read_flash(pbHdcpKey, (UINT8*)key_ptr, (HDCP2X_KEY_SIZE+HDCP2X_CRC_SIZE));
  484. #ifdef CONFIG_DISABLE_CIKEY_HDCPKEY_SPI_ENCRYPT
  485. pbHdcpKey_tmp = kmalloc((((HDCP2X_KEY_SIZE+HDCP2X_CRC_SIZE+15)>>4)<<4), GFP_KERNEL);
  486. memcpy((void *)pbHdcpKey_tmp, (void *)pbHdcpKey, (HDCP2X_KEY_SIZE+HDCP2X_CRC_SIZE));
  487. do_spi_encrypt((INT8 *)pbHdcpKey_tmp, (((HDCP2X_KEY_SIZE+HDCP2X_CRC_SIZE+15)>>4)<<4), 0);
  488. memcpy((void *)pbHdcpKey, (void *)pbHdcpKey_tmp, (HDCP2X_KEY_SIZE+HDCP2X_CRC_SIZE));
  489. kfree(pbHdcpKey_tmp);
  490. #endif
  491. key = (HDCP2X_KEY_FMT_PTR)pbHdcpKey;
  492. /* Input data is encrypted and decryption needed */
  493. calculated_crc = 0;
  494. for (i = 0; i < (HDCP2X_KEY_SIZE/4); i++)
  495. {
  496. calculated_crc += (UINT32)key->data[i];
  497. }
  498. bHDCP_CRC = (calculated_crc == key->crc) ? 1 : 0;
  499. byteDecryption(key->vkey, HDCP2X_VKEY_SIZE);
  500. byteDecryption(key->rkey, HDCP2X_RKEY_SIZE);
  501. bf_decrypt(key->ckey, HDCP2X_CKEY_SIZE, key->rkey, HDCP2X_RKEY_SIZE);
  502. xcrypt_HDCP2X(key->ckey, key->ckey, HDCP2X_CKEY_SIZE);
  503. /* Update to local key data */
  504. memcpy(local_2Xkey_data, key->ckey, HDCP2X_RAWKEY_SIZE);
  505. #ifdef SUPPORT_PRINT_HDCP_MESSAGE
  506. printk("hdcp2X raw key\n");
  507. dump(local_2Xkey_data, HDCP2X_RAWKEY_SIZE);
  508. #endif
  509. Hdcp2X_Key.Header[0]=0x00;
  510. Hdcp2X_Key.Header[1]=0x00;
  511. Hdcp2X_Key.Header[2]=0x00;
  512. Hdcp2X_Key.Header[3]=0x02;
  513. memcpy(Hdcp2X_Key.LicConst, &(key->ckey[0]), HDCP2X_LIC_CONST_SIZE);
  514. memcpy(Hdcp2X_Key.PubCert, &(key->ckey[36]), HDCP2X_PUB_CERT_SIZE);
  515. memcpy(Hdcp2X_Key.PvtKey, &(key->ckey[558]), HDCP2X_PVT_KEY_SIZE);
  516. #ifdef SUPPORT_PRINT_HDCP_MESSAGE
  517. printk("hdcp2X key header\n");
  518. dump(Hdcp2X_Key.Header, 4);
  519. printk("hdcp2X key Licensed Constant\n");
  520. dump(Hdcp2X_Key.LicConst, HDCP2X_LIC_CONST_SIZE);
  521. printk("hdcp2X key Public Certificate\n");
  522. dump(Hdcp2X_Key.PubCert, HDCP2X_PUB_CERT_SIZE);
  523. printk("hdcp2X key Private Key\n");
  524. dump(Hdcp2X_Key.PvtKey, HDCP2X_PVT_KEY_SIZE);
  525. #endif
  526. kfree(pbHdcpKey);
  527. }
  528. #endif