Commit 0344002f8a29dc62e1ab8ffb932e66fa664cd334
1 parent
691a0ae0
feat(dlcm&doc):支持华大智宝cpu卡,并增加相关文档资料
支持华大智宝cpu卡,并增加相关文档资料。主要修改替换秘钥接口和创建文件接口。
Showing
5 changed files
with
92 additions
and
23 deletions
Too many changes to show.
To preserve performance only 5 of 22 files are displayed.
dlcm/dlcm/DLCCard.cc
... | ... | @@ -280,8 +280,7 @@ int DLCCard::InstallCardKey(const unsigned char* dir, const unsigned char key_id |
280 | 280 | { |
281 | 281 | int result = 0; |
282 | 282 | |
283 | - | |
284 | - unsigned char dir_hex[2] = { 0 }, key_hex[16] = { 0 },/* au8OldKey[16] = { 0 },*/ main_key_hex[16] = { 0 }; | |
283 | + unsigned char dir_hex[2] = { 0 }, key_hex[16] = { 0 }, main_key_hex[16] = { 0 }; | |
285 | 284 | StringToHex(dir, 4, dir_hex); |
286 | 285 | StringToHex(key, 32, key_hex); |
287 | 286 | StringToHex(key_main, 32, main_key_hex); |
... | ... | @@ -393,6 +392,41 @@ int DLCCard::InstallCardKey(const unsigned char* dir, const unsigned char key_id |
393 | 392 | CalculateMac(cmd, 37, random, main_key_hex, &cmd[37]); |
394 | 393 | result = InstallKey(cmd, 41); |
395 | 394 | } |
395 | + case kCardHDZB: | |
396 | + { | |
397 | + unsigned char cmd[33] = { 0x84, 0xd4, 0x01, 0x00, 0x1c }; | |
398 | + unsigned char key_data[24] = { 0 }; | |
399 | + key_data[0] = 0x13; | |
400 | + key_data[3] = 0x00; | |
401 | + memcpy(&key_data[4], key_hex, 16); | |
402 | + key_data[20] = 0x80; | |
403 | + key_data[21] = 0x00; | |
404 | + key_data[22] = 0x00; | |
405 | + key_data[23] = 0x00; | |
406 | + | |
407 | + if (key_type == 0) | |
408 | + { | |
409 | + key_data[1] = 0x00; | |
410 | + key_data[2] = 0x00; | |
411 | + } | |
412 | + else if (key_type == 1) | |
413 | + { | |
414 | + key_data[1] = 0x00; | |
415 | + key_data[2] = 0x01; | |
416 | + } | |
417 | + else if (key_type == 2) | |
418 | + { | |
419 | + key_data[1] = 0x01; | |
420 | + key_data[2] = 0x01; | |
421 | + } | |
422 | + | |
423 | + Encrypt(key_data, 24, main_key_hex, &cmd[5]); | |
424 | + | |
425 | + unsigned char random[8] = { 0 }; | |
426 | + GetRandom(random, 8); | |
427 | + CalculateMac(cmd, 29, random, main_key_hex, &cmd[29]); | |
428 | + result = InstallKey(cmd, 33); | |
429 | + } | |
396 | 430 | break; |
397 | 431 | } |
398 | 432 | return result; |
... | ... | @@ -717,6 +751,61 @@ int DLCCard::CreatCardFile(const unsigned char* parent_dir, const unsigned char* |
717 | 751 | } |
718 | 752 | |
719 | 753 | } |
754 | + else if (card_mf = kCardHDZB) | |
755 | + { | |
756 | + if (file_type == kFTDDF) | |
757 | + { | |
758 | + if (SelectDir(parent_dir_hex)) | |
759 | + { | |
760 | + return kCanNotFindDir; | |
761 | + } | |
762 | + | |
763 | + unsigned char key[16] = { 0 }; | |
764 | + StringToHex((const unsigned char*)k25FileKey, 32, key); | |
765 | + if (ExternalAuthenticate(0x00, key, NULL)) | |
766 | + { | |
767 | + return kVerifyKeyFailure; | |
768 | + } | |
769 | + | |
770 | + unsigned char create_file_cmd[26] = { 0x80, 0xe0, 0x00, 0x02, 0x1d }; | |
771 | + memcpy(&create_file_cmd[5], file_name_hex, 2); | |
772 | + memcpy(&create_file_cmd[7], file_size_hex, 2); | |
773 | + create_file_cmd[9] = 0x00; | |
774 | + create_file_cmd[10] = 0x00; | |
775 | + create_file_cmd[11] = 0x00; | |
776 | + create_file_cmd[12] = 0x00; | |
777 | + create_file_cmd[13] = file_name_hex[1]; | |
778 | + create_file_cmd[14] = 0xb9; | |
779 | + create_file_cmd[15] = 0x00; | |
780 | + create_file_cmd[16] = 0x01; | |
781 | + create_file_cmd[17] = 0x03; | |
782 | + memcpy(&create_file_cmd[18], kDF10FileAID, 8); | |
783 | + | |
784 | + unsigned char recv_data[kHalfBlock], recv_data_len = 0; | |
785 | + result = DLCDevice::Instance().SendCommand(create_file_cmd, 15, recv_data, recv_data_len); | |
786 | + | |
787 | + if (result != kSuccess) | |
788 | + { | |
789 | + result = kCreateKeyFileFailed; | |
790 | + break; | |
791 | + } | |
792 | + | |
793 | + unsigned char create_key_file_cmd[13] = { 0x80, 0xe0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x02, 0x00, 0x00, 0x33, 0x00, 0x00 }; | |
794 | + | |
795 | + unsigned char recv[kHalfBlock], recv_len = 0; | |
796 | + result = DLCDevice::Instance().SendCommand(create_key_file_cmd, 13, recv, recv_len); | |
797 | + } | |
798 | + else if (file_type == kFTEF) | |
799 | + { | |
800 | + unsigned char cmd[18] = { 0x80, 0xe0, 0x00, 0x03, 0x0d}; | |
801 | + memcpy(&cmd[5], file_name_hex, 2); | |
802 | + memcpy(&cmd[7], file_size_hex, 2); | |
803 | + memset(&cmd[9], 0x00, 9); | |
804 | + | |
805 | + unsigned char recv[kHalfBlock], recv_len = 0; | |
806 | + result = DLCDevice::Instance().SendCommand(cmd, 18, recv, recv_len); | |
807 | + } | |
808 | + } | |
720 | 809 | }while (0); |
721 | 810 | |
722 | 811 | return result; | ... | ... |
dlcm/dlcm/DLCCard.h
dlcm/dlcm/stdafx.h
... | ... | @@ -5,27 +5,6 @@ |
5 | 5 | #include "dcrf32.h" |
6 | 6 | #include "CDLTools.h" |
7 | 7 | |
8 | - | |
9 | -//const int NULL = 0; | |
10 | - | |
11 | -//typedef signed char int8_t; | |
12 | -//typedef short unsigned int_t; | |
13 | -//typedef int int_t; | |
14 | -//typedef long long int64_t; | |
15 | -//typedef unsigned char unsigned char; | |
16 | -//typedef unsigned short uunsigned int_t; | |
17 | -//typedef unsigned int uint_t; | |
18 | -//typedef unsigned long long uint64_t; | |
19 | -//typedef unsigned char* PBlock; | |
20 | - | |
21 | -//#define BLOCK 250 //目前文件0005和0015文件最大250个字节,可以存储500个字符 | |
22 | -//#define RBLOCK 254 //加上结尾9000,最大可返回254字节的数据 | |
23 | -//#define HBLOCK 256 | |
24 | -//#define QBLOCK 128 | |
25 | -//#define WBLOCK 521 | |
26 | -//#define DBLOCK 1024 | |
27 | -//# | |
28 | - | |
29 | 8 | const int kHalfBlock = 256; |
30 | 9 | const int kBlock = 512; |
31 | 10 | const int kDoubleBlock = 1024; | ... | ... |
doc/D8&&T10ULM最新开发包/demo/help.chm
0 → 100644
No preview for this file type
doc/D8&&T10ULM最新开发包/demo/help.chw
0 → 100644
No preview for this file type