Rockey1.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. {**************************************************************************************
  2. * Copyright (c)
  3. * All rights reserved.
  4. *
  5. * FileName:
  6. *
  7. * History:
  8. * ------------------------------------------------------------
  9. * 2011/08/01 Create
  10. *
  11. *******************************************************************************************}
  12. unit Rockey1;
  13. interface
  14. uses
  15. SysUtils, Windows, WinSock, Nb30;
  16. // const definition
  17. const R1_S_SUCCESS =$00000000; //** 操作成功*/
  18. const R1_E_OPEN_FAILED =$F0000001; //** 打开锁失败*/
  19. const R1_E_NO_LIST =$F0000002; //** 没有找到设备列表*/
  20. const R1_E_KEY_REMOVED =$F0000003; //** 设备未连接,或者被移除*/
  21. const R1_E_INVALID_PARAMETER =$F0000004; //** 参数错误*/
  22. const R1_E_WORNG_USER_PIN =$F0000005; //** 错误的用户口令*/
  23. const R1_E_WORNG_SO_PIN =$F0000006; //** 错误的开发商口令*/
  24. const R1_E_CHANGE_USER_PIN =$F0000007; //** 修改用户口令错误*/
  25. const R1_E_CHANGE_SO_PIN =$F0000008; //** 修改开发商口令错误*/
  26. const R1_E_TDES_BUF_LENGTH_ERROR =$F0000009; //** 3DES加解密的内容长度错误。(必须被8整除)*/
  27. const R1_E_RSA_BUF_LENGTH_ERROR =$F000000A; //** RSA加解密的内容长度错误*/
  28. const R1_E_RSA_ID_ERROR =$F000000B; //** RSA密钥对ID错误*/
  29. const R1_E_RSA_ENC_ERROR =$F000000C; //** RSA公钥加密失败*/
  30. const R1_E_SET_UPDATE_ERROR =$F000000D; //** 请先设置升级内容*/
  31. const R1_E_RSA_UPDATE_ERROR =$F000000E; //** 制作升级RSA密钥时失败*/
  32. const R1_E_DES_UPDATE_ERROR =$F000000F; //** 制作升级3des密钥时失败*/
  33. const R1_E_FORMAT_UPDATE_ERROR =$F000001A; //**升级包格式不合法*/
  34. const R1_E_GET_TIME_ERROR =$F0000010; //** 获得时间失败*/
  35. const R1_E_SHARING_VIOLATION =$F0000011; //** 打开设备失败*/
  36. const R1_E_ACCESS_DENIED =$F0000012; //** 打开设备权限失败*/
  37. const R1_E_CREATE_SHARE_M =$F0000013; //** 创建共享内存失败*/
  38. const R1_E_EXIST_SHARE_M =$F0000014; //** 共享内存存在*/
  39. const R1_E_GET_RSA_KEY =$F0000015; //** 获得RSA密钥对失败*/
  40. const R1_E_RSA_NOT_PAIR =$F0000016; //** RSA密钥对不匹配*/
  41. const R1_E_GEN_RSA_PEM =$F0000017; //** 产生RSA PEM文件失败*/
  42. const R1_E_PEM_BITS_ERR =$F0000018; //** RSA PEM文件与设置的位数不匹配*/
  43. const R1_E_RSA_KEY_1024 =$F0000019; //** RSA 密钥对文件必须是1024*/
  44. //! 底层设备的错误码
  45. const ERR_SUCCEF =$d0;//成功
  46. const ERR_VERIFYUSERPIN =$d1;//验证用户密码失败
  47. const ERR_VERIFYSOPIN =$d2;//验证开发商密码失败
  48. const ERR_NOUSRPERMISSION =$d3;//没有usr权限
  49. const ERR_UPCOUNTUSRPIN =$d4;//已超过usrpin设置上限
  50. const ERR_NOSOPERMISSION =$d5;//没有开发商权限
  51. const ERR_UPCOUNTSOPIN =$d6;//已超过sopin设置上限
  52. const ERR_UPREADSOMEMORY =$d7;//读私有内存越界错误
  53. const ERR_UPREADUSRMEMORY =$d8;//读公有内存越界错误
  54. const ERR_UPWRITESOMEMORY =$d9;//写私有内存越界错误
  55. const ERR_UPWRITEUSRMEMORY =$da;//写公有内存越界错误
  56. const ERR_RESETSTATE =$db;//返回匿名态错误
  57. const ERR_NODESKEY =$dc;//未知的DESKEYID
  58. const ERR_NOFILE =$dd;//未知的文件格式
  59. const ERR_NOHID =$de;//错误的HID
  60. const ERR_NOPID =$df;//错误的PID
  61. const ERR_UPDATE_TIME =$e0;//升级包已过期
  62. const ERR_PARAMETERS =$e1;//参数错误
  63. const ERR_UNFINISHED =$e2;//数据包接收不完全
  64. const ERR_INACTIVE =$e3;//COS未激活
  65. const ERR_NOKEY =$e4;//密钥未设置
  66. const ERR_AUTHORIZATION =$e5;//授权已用完
  67. const ERR_CLEANCOS =$e6;//清COS错误
  68. const ERR_PID_IS_F =$e7;//pid的8个字节都为=$ff错误
  69. const ERR_RSA_ENC_DATA =$ec;//使用512对数据加密,数据每64个字节的前两个字节不为=0x00,使用1024对数据加密,数据每128个字节的前两个字节不为=0x00错误
  70. const ERR_CHECK_SUM =$ed;//校验和错误
  71. const R1_E_ERROR_TONGXIN =$FFFFFFFE; //** 通信错误*/
  72. const R1_E_ERROR_UNKNOWN =$FFFFFFFF; //** 未知的错误*/
  73. const MEM_PUB =$00;
  74. const MEM_PRI =$01;
  75. const LED_OFF =$00;
  76. const LED_ON =$01;
  77. const RSA_PAIRS_512 =$00;
  78. const RSA_PAIRS_1024 =$01;
  79. const PUB_KEY =$00;
  80. const PRI_KEY =$01;
  81. const Update_TYPE_HID =$01; //HID
  82. const Update_TYPE_PID =$02; //PID
  83. const Update_TYPE_Count =$03; //计次
  84. const Update_TYPE_PubKey =$04; //公钥数据
  85. const Update_TYPE_PriKey =$05; //私钥数据
  86. const Update_TYPE_3DesKey =$06; //3DES密钥数据
  87. const Update_TYPE_Memory =$07; //8192字节数据区
  88. msvcrtdll = 'msvcrt.dll';
  89. hiddll = 'HID.DLL';
  90. setupapidll = 'SETUPAPI.DLL';
  91. ws2_32dll = 'WSOCK32.dll';
  92. Netapi32dll = 'Netapi32.dll';
  93. libeay32dll = 'libeay32.dll';
  94. kernel32dll = 'kernel32.dll';
  95. User32dll = 'User32.dll';
  96. OleAut32dll = 'OleAut32.dll';
  97. BN_CTX_NUM = 16;
  98. BN_CTX_NUM_POS = 12;
  99. type
  100. {$IF CompilerVersion >= 20}
  101. PCharacter = PAnsiChar;
  102. {$ELSE}
  103. PCharacter = PChar;
  104. {$IFEND}
  105. PWord = ^Word;
  106. PLongword = ^Longword;
  107. PHIDP_PREPARSED_DATA = ^Byte;
  108. PPHIDP_PREPARSED_DATA = ^PHIDP_PREPARSED_DATA;
  109. PCSTR = ^Char;
  110. PByte = ^Byte;
  111. psize_t = ^size_t;
  112. size_t = Cardinal;
  113. pRSA = pointer;
  114. pBIO_METHOD = pointer;
  115. pBIO = pointer;
  116. pEVP_CIPHER = pointer;
  117. UpdateFileHeader = packed record
  118. bSign:Array [0..3] of Byte; //** 升级文件标识。0x4654524b,*/
  119. bVersion:Array [0..1] of Byte; //** 升级文件版本信息。第一个字节是主版本号,第二个字节是次版本号*/
  120. bBind:Byte; //** 升级文件绑定信息。0x00 什么也不绑定。0x01绑定HID.0x02绑定PID*/
  121. bReserve:Byte; //** 保留*/
  122. bHid:Array [0..19] of Byte; //** 升级文件要绑定的HID*/
  123. bPid:Array [0..19] of Byte; //** 升级文件要绑定的PID*/
  124. dwDate:DWord; //** 日期*/
  125. end;
  126. PUpdateFileHeader = ^UpdateFileHeader;
  127. RSAKey = packed record
  128. bID:Byte; //** 如果是RSA密钥对,最高位=0代表是512,=1代表是1024.剩下7位代表RSA密钥对序号(0~7)*/
  129. bPubkey:Array [0..1023] of Byte;
  130. bPrikey:Array [0..1023] of Byte;
  131. end;
  132. PRSAKey = ^RSAKey;
  133. TDESKey = packed record
  134. bID:Byte; //** 如果是3DES密钥对,代表3DES密钥序号(0~7)*/
  135. bTDESkey:Array [0..15] of Byte;
  136. end;
  137. PTDESKey = ^TDESKey;
  138. GUID = record
  139. Data1:Longword;
  140. Data2:Word;
  141. Data3:Word;
  142. Data4: array [0..7] of Byte;
  143. end;
  144. Array128 = array[0..127]of WORD;
  145. pArray128 = ^Array128;
  146. LPGUID = ^GUID;
  147. HIDP_CAPS = record
  148. Usage:Word;
  149. UsagePage:Word;
  150. InputReportByteLength:Word;
  151. OutputReportByteLength:Word;
  152. FeatureReportByteLength:Word;
  153. Reserved: array [0..16] of Word;
  154. NumberLinkCollectionNodes:Word;
  155. NumberInputButtonCaps:Word;
  156. NumberInputValueCaps:Word;
  157. NumberInputDataIndices:Word;
  158. NumberOutputButtonCaps:Word;
  159. NumberOutputValueCaps:Word;
  160. NumberOutputDataIndices:Word;
  161. NumberFeatureButtonCaps:Word;
  162. NumberFeatureValueCaps:Word;
  163. NumberFeatureDataIndices:Word;
  164. end;
  165. PHIDP_CAPS = ^HIDP_CAPS;
  166. HIDD_ATTRIBUTES = record
  167. Size:Longword;
  168. VendorID:Word;
  169. ProductID:Word;
  170. VersionNumber:Word;
  171. end;
  172. PHIDD_ATTRIBUTES = ^HIDD_ATTRIBUTES;
  173. SP_DEVICE_INTERFACE_DATA = record
  174. cbSize:Longword;
  175. InterfaceClassGuid:GUID;
  176. Flags:Longword;
  177. Reserved:Longword;
  178. end;
  179. PSP_DEVICE_INTERFACE_DATA = ^SP_DEVICE_INTERFACE_DATA;
  180. SP_DEVICE_INTERFACE_DETAIL_DATA_A = record
  181. cbSize:Longword;
  182. DevicePath: array [0..4096] of Char;
  183. end;
  184. PSP_DEVICE_INTERFACE_DETAIL_DATA_A = ^SP_DEVICE_INTERFACE_DETAIL_DATA_A;
  185. PSP_DEVICE_INTERFACE_DETAIL_DATA = ^SP_DEVICE_INTERFACE_DETAIL_DATA_A;
  186. SP_DEVINFO_DATA = record
  187. cbSize:Longword;
  188. ClassGuid:GUID;
  189. DevInst:Longword;
  190. Reserved:Longword;
  191. end;
  192. PSP_DEVINFO_DATA = ^SP_DEVINFO_DATA;
  193. Feature_Report = packed record
  194. id: Byte;
  195. command: array[0..4] of Byte;
  196. data: array[0..17] of Byte;
  197. CrcData: Byte;
  198. end;
  199. PFeature_Report = ^Feature_Report;
  200. Device_Descript = record
  201. device_path: array[0..255] of Char;
  202. device_handle: THandle;
  203. uid: Longword;
  204. hid: Longword;
  205. hver: Word;
  206. mutex: THandle;
  207. KeyPass:array[0..8] of char;
  208. Encrypt:integer;
  209. end;
  210. tm = record
  211. tm_sec:Integer; //* seconds after the minute - [0,59] */
  212. tm_min:Integer; //* minutes after the hour - [0,59] */
  213. tm_hour:Integer; //* hours since midnight - [0,23] */
  214. tm_mday:Integer; //* day of the month - [1,31] */
  215. tm_mon:Integer; //* months since January - [0,11] */
  216. tm_year:Integer; //* years since 1900 */
  217. tm_wday:Integer; //* days since Sunday - [0,6] */
  218. tm_yday:Integer; //* days since January 1 - [0,365] */
  219. tm_isdst:Integer; //* daylight savings time flag */
  220. end;
  221. PTm = ^tm;
  222. pBN_ULONG = ^BN_ULONG;
  223. BN_ULONG = array of byte;
  224. BIGNUM = record
  225. d: pBN_ULONG; // Pointer to an array of 'BN_BITS2' bit chunks.
  226. top: integer; // Index of last used d +1.
  227. // The next are internal book keeping for bn_expand.
  228. dmax: integer; // Size of the d array.
  229. neg: integer; // one if the number is negative
  230. flags: integer;
  231. end;
  232. pBIGNUM = ^BIGNUM;
  233. pBN_CTX = ^BN_CTX;
  234. BN_CTX = record
  235. tos: integer;
  236. bn: array [0..BN_CTX_NUM-1] of BIGNUM;
  237. flags: integer;
  238. depth: integer;
  239. pos: array [0..BN_CTX_NUM_POS-1] of integer;
  240. too_many: integer;
  241. end;
  242. pBN_RECP_CTX = ^BN_RECP_CTX;
  243. BN_RECP_CTX = record
  244. N: BIGNUM; // the divisor
  245. Nr: BIGNUM; // the reciprocal
  246. num_bits: integer;
  247. shift: integer;
  248. flags: integer;
  249. end;
  250. SHA_CTX = record
  251. h0, h1, h2, h3, h4: cardinal;
  252. Nl, Nh: cardinal;
  253. data: array [0..16] of cardinal;
  254. num: integer;
  255. end;
  256. pSHA_CTX = ^SHA_CTX;
  257. SYSTEMTIME = record
  258. wYear:WORD;
  259. wMonth:WORD;
  260. wDayOfWeek:WORD;
  261. wDay:WORD;
  262. wHour:WORD;
  263. wMinute:WORD;
  264. wSecond:WORD;
  265. wMilliseconds:WORD;
  266. end;
  267. PSYSTEMTIME = ^SYSTEMTIME;
  268. LPSYSTEMTIME = ^SYSTEMTIME;
  269. TPWCallbackFunction = function(buffer: PCharacter; length: integer;
  270. verify: integer; data: pointer): integer; cdecl;
  271. TProgressCallbackFunction = procedure(status: integer; progress: integer;
  272. data: pointer);
  273. // @brief 查找计算机上指定PID的加密锁,返回找到指定PID的加密锁的个数
  274. function R1_Find( pid : PByte ; dwCount :PLongWord):LongWord;stdcall;
  275. {$EXTERNALSYM R1_Find}
  276. //打开计算机上指定的加密锁。
  277. function R1_Open( handle:PHANDLE; pid:PByte; nIndex:Integer):LongWord;stdcall;
  278. {$EXTERNALSYM R1_Open}
  279. //关闭计算机上指定的加密锁。
  280. function R1_Close( handle:THandle):LongWord;stdcall;
  281. {$EXTERNALSYM R1_Close}
  282. //获得计算机上指定PID的加密锁的版本信息
  283. function R1_GetVersion( handle:THandle; bVersionMajor:PByte; bVersionMinor:PByte):LongWord;stdcall;
  284. {$EXTERNALSYM R1_GetVersion}
  285. //控制计算机上LED。(用户或者开发商权限)
  286. function R1_LEDControl( handle:THandle; bFlag:Byte):LongWord;stdcall;
  287. {$EXTERNALSYM R1_LEDControl}
  288. //重新产生计算机上指定加密锁的PID。需要开发商权限
  289. function R1_ProducePID( handle:THandle; seed:PByte; leng:BYTE; pid:PByte):LongWord;stdcall;
  290. {$EXTERNALSYM R1_ProducePID}
  291. //获取计算机上指定加密锁的HID
  292. function R1_GetHID( handle:THandle; hid:PByte):LongWord;stdcall;
  293. {$EXTERNALSYM R1_GetHID}
  294. //获取计算机上指定加密锁的PID
  295. function R1_GetPID( handle:THandle; pid:PByte):LongWord;stdcall;
  296. {$EXTERNALSYM R1_GetPID}
  297. //核实计算机上指定加密锁的用户密码
  298. function R1_VerifyUserPin( handle:THandle; pin:PByte; tryCount:PByte):LongWord;stdcall;
  299. {$EXTERNALSYM R1_VerifyUserPin}
  300. //修改计算机上指定加密锁的用户密码,(匿名权限),当有开发商密码的权限时,直接传入新的用户口令即可
  301. function R1_ChangeUserPin( handle:THandle; oldPin:PByte; newPin:PByte):LongWord;stdcall;
  302. {$EXTERNALSYM R1_ChangeUserPin}
  303. //重置计算机上指定加密锁的用户密码。需要开发商密码
  304. function R1_ResetUserPin( handle:THandle):LongWord;stdcall;
  305. {$EXTERNALSYM R1_ResetUserPin}
  306. //设置计算机上指定加密锁的用户密码的重试次数。(需要开发商权限)
  307. //如果不调用设置重置次数,加密锁默认是255,即没有限制
  308. function R1_SetTryCountForUserPin( handle:THandle; tryCount:Byte):LongWord;stdcall;
  309. {$EXTERNALSYM R1_SetTryCountForUserPin}
  310. //核实计算机上指定加密锁的开发商密码
  311. function R1_VerifySoPin( handle:THandle; pin:PByte; tryCount:PByte):LongWord;stdcall;
  312. {$EXTERNALSYM R1_VerifySoPin}
  313. //通过种子生成开发商的密码,(开发商权限)
  314. function R1_ProduceSoPin( handle:THandle; seed:PByte; len:BYTE; newPin:PByte):LongWord;stdcall;
  315. {$EXTERNALSYM R1_ProduceSoPin}
  316. //产生随机数,(用户权限)
  317. function R1_GenRandom( handle:THandle; buffer:PByte):LongWord;stdcall;
  318. {$EXTERNALSYM R1_GenRandom}
  319. //设置计算机上指定加密锁的开发商密码的重试次数。(需要开发商权限)
  320. //如果不调用设置重置次数,加密锁默认是255,即没有限制
  321. function R1_SetTryCountForSoPin( handle:THandle; tryCount:Byte):LongWord;stdcall;
  322. {$EXTERNALSYM R1_SetTryCountForSoPin}
  323. //读取计算机上指定加密锁的指定内存。
  324. //公有内存私有内存都是0~4k
  325. //开发商权限可以读写公有内存,读写私有内存
  326. //用户权限可以读写公有内存,读私有内存
  327. function R1_Read( handle:THandle; offset:WORD; length:WORD; buf:PByte; len:PWORD; bType:BYTE):LongWord;stdcall;
  328. {$EXTERNALSYM R1_Read}
  329. //写计算机上指定加密锁的指定内存。
  330. //公有内存私有内存都是0~4k
  331. //开发商权限可以读写公有内存,读写私有内存
  332. //用户权限可以读写公有内存,读私有内存
  333. function R1_Write( handle:THandle; offset:WORD; length:WORD; buf:PByte; len:PWORD; bType:BYTE):LongWord;stdcall;
  334. {$EXTERNALSYM R1_Write}
  335. ///重置锁的安全状态,回到匿名状态
  336. function R1_ResetSecurityState( handle:THandle):LongWord;stdcall;
  337. {$EXTERNALSYM R1_ResetSecurityState}
  338. //设置3DES密钥。(需要开发商权限)
  339. function R1_SetTDesKey( handle:THandle; id:BYTE; buf:PByte):LongWord;stdcall;
  340. {$EXTERNALSYM R1_SetTDesKey}
  341. //利用3DES密钥加密。(需要用户权限)
  342. function R1_TDesEnc( handle:THandle; id:BYTE; buf:PByte; len:DWORD):LongWord;stdcall;
  343. {$EXTERNALSYM R1_TDesEnc}
  344. //利用3DES密钥解密。(需要用户权限)
  345. function R1_TDesDec( handle:THandle; id:BYTE; buf:PByte; len:DWORD):LongWord;stdcall;
  346. {$EXTERNALSYM R1_TDesDec}
  347. //产生RSA密钥对。(需要开发商权限)
  348. function R1_GenRSAKey( handle:THandle; bFlag:BYTE; id:BYTE; pubkey:PChar; prikey:PChar):LongWord;stdcall;
  349. {$EXTERNALSYM R1_GenRSAKey}
  350. //设置RSA密钥对。(需要开发商权限)
  351. function R1_SetRSAKey( handle:THandle; bFlag:BYTE; id:BYTE; pubkey:PChar; prikey:PChar):LongWord;stdcall;
  352. {$EXTERNALSYM R1_SetRSAKey}
  353. //利用RSA密钥对加密。(需要用户权限)
  354. //受RSA算法本身限制。如果是512密钥对,则每64字节的前两字节必须是0,如果是1024密钥对,则每128字节的前两字节必须是0
  355. function R1_RSAEnc( handle:THandle; bFlag:BYTE; id:BYTE; bBuf:PByte; len:DWORD):LongWord;stdcall;
  356. {$EXTERNALSYM R1_RSAEnc}
  357. //利用RSA密钥对解密。(需要用户权限)
  358. //受RSA算法本身限制。如果是512密钥对,则每64字节的前两字节必须是0,如果是1024密钥对,则每128字节的前两字节必须是0
  359. function R1_RSADec( handle:THandle; bFlag:BYTE; id:BYTE; bBuf:PByte; len:DWORD):LongWord;stdcall;
  360. {$EXTERNALSYM R1_RSADec}
  361. //设置计次模块次数。(需要开发商权限)
  362. function R1_SetCounter( handle:THandle; bCount:BYTE):LongWord;stdcall;
  363. {$EXTERNALSYM R1_SetCounter}
  364. //获得计次模块次数。(需要用户权限)
  365. function R1_GetCounter( handle:THandle; bCount:PBYTE):LongWord;stdcall;
  366. {$EXTERNALSYM R1_GetCounter}
  367. //设置升级包数据。(匿名权限)
  368. function R1_SetUpdatePacket( UpdateType:DWORD; first:WORD; second:WORD; pBuf:PByte; len:DWORD):LongWord;stdcall;
  369. {$EXTERNALSYM R1_SetUpdatePacket}
  370. //制作升级包。(匿名权限)
  371. function R1_GenUpdatePacket( pubkey:PChar; pEncBuf:PBYTE; pEncLen:PWORD):LongWord;stdcall;
  372. {$EXTERNALSYM R1_GenUpdatePacket}
  373. //升级。(匿名权限)
  374. function R1_Update( handle:THandle; bPacket:PBYTE; len:WORD):LongWord;stdcall;
  375. {$EXTERNALSYM R1_Update}
  376. //根据错误码得到错误信息。(匿名权限)
  377. function R1_GetErrInfo( Error:DWORD):LongWord;stdcall;
  378. {$EXTERNALSYM R1_GetErrInfo}
  379. {$EXTERNALSYM HidD_FreePreparsedData}
  380. function HidD_FreePreparsedData (PreparsedData:PHIDP_PREPARSED_DATA):Boolean;cdecl;
  381. {$EXTERNALSYM HidP_GetCaps}
  382. function HidP_GetCaps (PreparsedData:PHIDP_PREPARSED_DATA; Capabilities:PHIDP_CAPS):Longint;cdecl;
  383. {$EXTERNALSYM HidD_GetPreparsedData}
  384. function HidD_GetPreparsedData (HidDeviceObject:THandle; PreparsedData:PPHIDP_PREPARSED_DATA):Boolean;cdecl;
  385. {$EXTERNALSYM HidD_SetFeature}
  386. function HidD_SetFeature (HidDeviceObject:THandle; ReportBuffer:pointer; ReportBufferLength:Longword):Boolean;cdecl;
  387. {$EXTERNALSYM HidD_GetFeature}
  388. function HidD_GetFeature (HidDeviceObject:THandle; ReportBuffer:pointer; ReportBufferLength:Longword):Boolean;cdecl;
  389. {$EXTERNALSYM HidD_FlushQueue}
  390. function HidD_FlushQueue (HidDeviceObject:THandle):Boolean;cdecl;
  391. {$EXTERNALSYM HidD_GetSerialNumberString}
  392. function HidD_GetSerialNumberString(HidDeviceObject:THandle; Buffer:PChar; BufferLength:Longword):Boolean;cdecl;
  393. {$EXTERNALSYM HidD_GetProductString}
  394. function HidD_GetProductString(HidDeviceObject:THandle; Buffer:PChar; BufferLength:Longword):Boolean;cdecl;
  395. {$EXTERNALSYM HidD_GetAttributes}
  396. function HidD_GetAttributes (HidDeviceObject:THandle; Attributes:PHIDD_ATTRIBUTES):Boolean;cdecl;
  397. {$EXTERNALSYM HidD_GetHidGuid}
  398. function HidD_GetHidGuid ( HidGuid:LPGUID ):integer;cdecl;
  399. {$EXTERNALSYM HidD_GetManufacturerString}
  400. function HidD_GetManufacturerString(HidDeviceObject:THANDLE;Buffer:PCHAR; BufferLength:ULONG):Boolean;cdecl;
  401. {$EXTERNALSYM SetupDiDestroyDeviceInfoList}
  402. function SetupDiDestroyDeviceInfoList (DeviceInfoSet:THandle):Boolean;cdecl;
  403. {$EXTERNALSYM SetupDiGetDeviceInterfaceDetailA}
  404. function SetupDiGetDeviceInterfaceDetailA (DeviceInfoSet:THandle; DeviceInterfaceData:PSP_DEVICE_INTERFACE_DATA; DeviceInterfaceDetailData:PSP_DEVICE_INTERFACE_DETAIL_DATA_A; DeviceInterfaceDetailDataSize:Longword; RequiredSize:PLongword; DeviceInfoData:PSP_DEVINFO_DATA):Boolean;cdecl;
  405. {$EXTERNALSYM SetupDiEnumDeviceInterfaces}
  406. function SetupDiEnumDeviceInterfaces (DeviceInfoSet:THandle; DeviceInfoData:PSP_DEVINFO_DATA; InterfaceClassGuid:LPGUID; MemberIndex:Longword; DeviceInterfaceData:PSP_DEVICE_INTERFACE_DATA):Boolean;cdecl;
  407. {$EXTERNALSYM SetupDiGetClassDevsA}
  408. function SetupDiGetClassDevsA (ClassGuid:LPGUID; Enumerator:PCSTR; hwndParent:HWND; Flags:Longword):THandle;cdecl;
  409. {$EXTERNALSYM _wsprintfW}
  410. function _wsprintfW(lpOut:LPWSTR; lpFmt:LPCWSTR; str:size_t): Integer; cdecl;
  411. {$EXTERNALSYM _wcslen}
  412. function _wcslen(const str: PWideChar): size_t; cdecl;
  413. {$EXTERNALSYM _wcscpy}
  414. function _wcscpy(const strDestination: PWideChar; strSource:PWideChar): PWideChar; cdecl;
  415. {$EXTERNALSYM _memset}
  416. function _memset(s: Pointer; c: Integer; n: size_t): Pointer; cdecl;
  417. {$EXTERNALSYM _memcpy}
  418. function _memcpy(s1: Pointer; const s2: Pointer; n: size_t): Pointer; cdecl;
  419. {$EXTERNALSYM _memcmp}
  420. function _memcmp(s1: Pointer; const s2: Pointer; n: size_t): Integer; cdecl;
  421. {$EXTERNALSYM _strcpy}
  422. function _strcpy(s1: PChar; const s2: PChar): PChar; cdecl;
  423. {$EXTERNALSYM _strlen}
  424. function _strlen(const s: PChar): size_t; cdecl;
  425. {$EXTERNALSYM _strcmp}
  426. function _strcmp(const s1, s2: PChar): Integer; cdecl;
  427. {$EXTERNALSYM _strcat}
  428. function _strcat(dest: PChar; src: PChar): PChar; cdecl;
  429. {$EXTERNALSYM _strncmp}
  430. function _strncmp(const s1, s2: PChar; n: size_t): Integer; cdecl;
  431. {$EXTERNALSYM _strncpy}
  432. function _strncpy(s1: PChar; const s2: PChar; n: size_t): PChar; cdecl;
  433. {$EXTERNALSYM _sscanf}
  434. function _sscanf(const s, format: PChar): Integer; cdecl; varargs;
  435. {$EXTERNALSYM _sprintf}
  436. function _sprintf(s: PChar; const format: PChar): Integer; cdecl; varargs;
  437. {$EXTERNALSYM __ltoa}
  438. function __ltoa(value : Integer; s: PChar; radix: Integer): PChar; cdecl;
  439. {$EXTERNALSYM _atol}
  440. function _atol(const s: PChar): Integer; cdecl;
  441. {$EXTERNALSYM _atof}
  442. function _atof(const s: PChar): Double; cdecl;
  443. {$EXTERNALSYM _malloc}
  444. function _malloc(size : size_t) : Pointer; cdecl;
  445. {$EXTERNALSYM _free}
  446. function _free(size : size_t) : Pointer; cdecl;
  447. {$EXTERNALSYM _rand}
  448. function _rand() : Integer; cdecl;
  449. {$EXTERNALSYM _srand}
  450. procedure _srand(seed : size_t);cdecl;
  451. {$EXTERNALSYM _mktime}
  452. function _mktime(dtm:PTm):Int64;cdecl;
  453. function _localtime(const time:PInt64):PTm;cdecl;
  454. function __ftol(f:Real):Integer;cdecl;
  455. function SystemTimeToVariantTime(lpSystemTime:LPSYSTEMTIME; pvtime:PDouble):Integer;cdecl;
  456. function VariantTimeToSystemTime(pvtime:Double; lpSystemTime:LPSYSTEMTIME):Integer;cdecl;
  457. //Openssl
  458. procedure _RSA_free(r: pRSA); cdecl;
  459. function _RSA_size(pkey: pRSA): integer; cdecl;
  460. function _RSA_new: pRSA; cdecl;
  461. function _RSA_check_key(arg0: pRSA): integer; cdecl;
  462. function _RSA_generate_key(bits: integer; exp: Cardinal;
  463. progress: TProgressCallbackFunction; cb_arg: pointer):pRSA; cdecl;
  464. function _RSA_public_encrypt(flen: integer; from: PCharacter; _to: PCharacter; rsa: pRSA; padding: integer): integer; cdecl;
  465. function _RSA_public_decrypt(flen: integer; from: PCharacter; _to: PCharacter; rsa: pRSA; padding: integer): integer; cdecl;
  466. function _BIO_new(_type: pBIO_METHOD): pBIO; cdecl;
  467. function _BIO_s_file: pBIO_METHOD; cdecl;
  468. function _BIO_ctrl(bp: pBIO; cmd: Integer; larg: Longint;
  469. parg: Pointer): Longint; cdecl;
  470. procedure _BIO_free_all(a: pBIO); cdecl;
  471. function _BIO_free(a: pBIO): integer; cdecl;
  472. function _BIO_write(b: pBIO; const buf: pointer; len: integer): integer; cdecl;
  473. function _BIO_s_mem: pBIO_METHOD; cdecl;
  474. function _PEM_read_bio_RSAPublicKey(bp: pBIO; var x: pRSA;
  475. cb: TPWCallbackFunction; u: pointer): pRSA; cdecl;
  476. function _PEM_read_bio_RSAPrivateKey(bp: pBIO; var x: pRSA;
  477. cb: TPWCallbackFunction; u: pointer): pRSA; cdecl;
  478. function _PEM_write_bio_RSAPrivateKey(bp: pBIO; x: pRSA; const enc: pEVP_CIPHER;
  479. kstr: PCharacter; klen: integer; cb: TPWCallbackFunction;
  480. u: pointer): integer; cdecl;
  481. function _PEM_write_bio_RSAPublicKey(bp: pBIO; x: pRSA): integer; cdecl;
  482. function _BN_div(dv: pBIGNUM; rem: pBIGNUM; const a, d: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
  483. function _BN_new(): pBIGNUM; cdecl;
  484. function _BN_sub(r: pBIGNUM; const a, b: pBIGNUM): integer; cdecl;
  485. function _BN_value_one(): pBIGNUM; cdecl;
  486. procedure _BN_free(bn: pBIGNUM); cdecl;
  487. function _BN_CTX_new: pBN_CTX; cdecl;
  488. function _BN_mod(rem: pBIGNUM; const a, m: pBIGNUM; ctx: pBN_CTX): integer;cdecl;
  489. procedure _BN_CTX_free(ctx: pBN_CTX); cdecl;
  490. function _BN_mod_inverse(ret, a: pBIGNUM; const n: pBIGNUM; ctx: pBN_CTX): pBIGNUM; cdecl;
  491. procedure _SHA1_Init(c:pSHA_CTX);cdecl;
  492. procedure _SHA1_Update(c:pSHA_CTX; const data:pointer; len:cardinal);cdecl;
  493. procedure _SHA1_Final(md:PChar; c:pSHA_CTX); cdecl;
  494. implementation
  495. {$LINK 'Rockey1Smart.obj'} //链接外部OBJ文件
  496. function R1_Find;external;
  497. function R1_Open;external;
  498. function R1_Close;external;
  499. function R1_GetVersion;external;
  500. function R1_LEDControl;external;
  501. function R1_ProducePID;external;
  502. function R1_GetHID;external;
  503. function R1_GetPID;external;
  504. function R1_VerifyUserPin;external;
  505. function R1_ChangeUserPin;external;
  506. function R1_ResetUserPin;external;
  507. function R1_SetTryCountForUserPin;external;
  508. function R1_VerifySoPin;external;
  509. function R1_ProduceSoPin;external;
  510. function R1_GenRandom;external;
  511. function R1_SetTryCountForSoPin;external;
  512. function R1_Read;external;
  513. function R1_Write;external;
  514. function R1_ResetSecurityState;external;
  515. function R1_SetTDesKey;external;
  516. function R1_TDesEnc;external;
  517. function R1_TDesDec;external;
  518. function R1_GenRSAKey;external;
  519. function R1_SetRSAKey;external;
  520. function R1_RSAEnc;external;
  521. function R1_RSADec;external;
  522. function R1_SetCounter;external;
  523. function R1_GetCounter;external;
  524. function R1_SetUpdatePacket;external;
  525. function R1_GenUpdatePacket;external;
  526. function R1_Update;external;
  527. function R1_GetErrInfo;external;
  528. //hid function
  529. function HidD_FreePreparsedData ; external hiddll name 'HidD_FreePreparsedData' ;
  530. function HidP_GetCaps; external hiddll name 'HidP_GetCaps' ;
  531. function HidD_GetPreparsedData ; external hiddll name 'HidD_GetPreparsedData' ;
  532. function HidD_SetFeature ; external hiddll name 'HidD_SetFeature' ;
  533. function HidD_GetFeature ; external hiddll name 'HidD_GetFeature' ;
  534. function HidD_FlushQueue ; external hiddll name 'HidD_FlushQueue';
  535. function HidD_GetSerialNumberString; external hiddll name 'HidD_GetSerialNumberString';
  536. function HidD_GetProductString; external hiddll name 'HidD_GetProductString';
  537. function HidD_GetAttributes ; external hiddll name 'HidD_GetAttributes';
  538. function HidD_GetHidGuid ; external hiddll name 'HidD_GetHidGuid';
  539. function HidD_GetManufacturerString; external hiddll name 'HidD_GetManufacturerString';
  540. //setupapi function
  541. function SetupDiDestroyDeviceInfoList ; external setupapidll name 'SetupDiDestroyDeviceInfoList';
  542. function SetupDiGetDeviceInterfaceDetailA ; external setupapidll name 'SetupDiGetDeviceInterfaceDetailA';
  543. function SetupDiEnumDeviceInterfaces ;external setupapidll name 'SetupDiEnumDeviceInterfaces' ;
  544. function SetupDiGetClassDevsA ; external setupapidll name 'SetupDiGetClassDevsA';
  545. //msvcrt function
  546. function _wcslen; external msvcrtdll name 'wcslen';
  547. function _wcscpy; external msvcrtdll name 'wcscpy';
  548. function _memset; external msvcrtdll name 'memset';
  549. function _memcpy; external msvcrtdll name 'memcpy';
  550. function _memcmp; external msvcrtdll name 'memcmp';
  551. function _strcpy; external msvcrtdll name 'strcpy';
  552. function _strlen; external msvcrtdll name 'strlen';
  553. function _strcmp; external msvcrtdll name 'strcmp';
  554. function _strncmp; external msvcrtdll name 'strncmp';
  555. function _strncpy; external msvcrtdll name 'strncpy';
  556. function _sscanf; external msvcrtdll name 'sscanf';
  557. function _sprintf; external msvcrtdll name 'sprintf';
  558. function __ltoa; external msvcrtdll name '_ltoa';
  559. function _atol; external msvcrtdll name 'atol';
  560. function _atof; external msvcrtdll name 'atof';
  561. function _malloc; external msvcrtdll name 'malloc';
  562. function _free; external msvcrtdll name 'free';
  563. function _rand;external msvcrtdll name 'rand';
  564. procedure _srand;external msvcrtdll name 'srand';
  565. function _strcat;external msvcrtdll name 'strcat';
  566. function _mktime;external msvcrtdll name 'mktime';
  567. function _localtime;external msvcrtdll name 'localtime';
  568. function __ftol;external msvcrtdll name '_ftol';
  569. function _wsprintfW;external User32dll name 'wsprintfW';
  570. function SystemTimeToVariantTime;external OleAut32dll name 'SystemTimeToVariantTime';
  571. function VariantTimeToSystemTime;external OleAut32dll name 'VariantTimeToSystemTime';
  572. procedure _RSA_free; external libeay32dll name 'RSA_free';
  573. function _RSA_size; external libeay32dll name 'RSA_size';
  574. function _RSA_new; external libeay32dll name 'RSA_new';
  575. function _RSA_check_key; external libeay32dll name 'RSA_check_key';
  576. function _RSA_generate_key; external libeay32dll name 'RSA_generate_key';
  577. function _RSA_public_encrypt; external libeay32dll name 'RSA_public_encrypt';
  578. function _RSA_public_decrypt; external libeay32dll name 'RSA_public_decrypt';
  579. function _BIO_new; external libeay32dll name 'BIO_new';
  580. function _BIO_s_file; external libeay32dll name 'BIO_s_file';
  581. function _BIO_ctrl; external libeay32dll name 'BIO_ctrl';
  582. procedure _BIO_free_all; external libeay32dll name 'BIO_free_all';
  583. function _BIO_free; external libeay32dll name 'BIO_free';
  584. function _BIO_write; external libeay32dll name 'BIO_write';
  585. function _BIO_s_mem; external libeay32dll name 'BIO_s_mem';
  586. function _PEM_read_bio_RSAPublicKey; external libeay32dll name 'PEM_read_bio_RSAPublicKey';
  587. function _PEM_read_bio_RSAPrivateKey; external libeay32dll name 'PEM_read_bio_RSAPrivateKey';
  588. function _PEM_write_bio_RSAPrivateKey; external libeay32dll name 'PEM_write_bio_RSAPrivateKey';
  589. function _PEM_write_bio_RSAPublicKey; external libeay32dll name 'PEM_write_bio_RSAPublicKey';
  590. function _BN_div; external libeay32dll name 'BN_div';
  591. function _BN_new; external libeay32dll name 'BN_new';
  592. function _BN_sub; external libeay32dll name 'BN_sub';
  593. function _BN_value_one; external libeay32dll name 'BN_value_one';
  594. procedure _BN_free; external libeay32dll name 'BN_free';
  595. function _BN_CTX_new; external libeay32dll name 'BN_CTX_new';
  596. function BN_mod(rem: pBIGNUM; const a, m: pBIGNUM; ctx: pBN_CTX): integer;
  597. begin
  598. result := _BN_div(nil, rem, a, m, ctx);
  599. end;
  600. function _BN_mod;external libeay32dll name 'BN_mod';
  601. procedure _BN_CTX_free; external libeay32dll name 'BN_CTX_free';
  602. function _BN_mod_inverse; external libeay32dll name 'BN_mod_inverse';
  603. procedure _SHA1_Init;external libeay32dll name 'SHA1_Init';
  604. procedure _SHA1_Update;external libeay32dll name 'SHA1_Update';
  605. procedure _SHA1_Final;external libeay32dll name 'SHA1_Final';
  606. var __turboFloat: LongBool = False;
  607. end.