1 #ifndef BASIC_DEMO6_WIN32_H 2 #define BASIC_DEMO6_WIN32_H 5 #error "Multiple ports included" 13 #include "ssp_helpers.h" 16 #define usleep(x) Sleep(x/1000) 23 #define getchar _getch 27 typedef UINT (CALLBACK* LPFNDLLFUNC1)(
SSP_COMMAND* cmd);
28 LPFNDLLFUNC1 openPort;
29 typedef UINT (CALLBACK* LPFNDLLFUNC2)(void);
30 LPFNDLLFUNC2 closePort;
32 LPFNDLLFUNC3 sspSendCommand;
34 LPFNDLLFUNC4 initiateSSPHostKeys;
35 typedef UINT (CALLBACK* LPFNDLLFUNC5)(
SSP_KEYS* key);
36 LPFNDLLFUNC5 createSSPHostEncryptionKey;
39 return openPort(sspC);
41 static void close_ssp_port () {
45 static int init_lib(
void)
51 hinstLib = LoadLibrary(TEXT(
"ITLSSPProc.dll"));
52 if (hinstLib == NULL) {
53 printf(
"ERROR: unable to load DLL\n");
57 openPort = (LPFNDLLFUNC1)GetProcAddress(hinstLib,
"OpenSSPComPortUSB");
58 if (openPort == NULL) {
59 printf(
"ERROR: unable to find DLL function OpenSSPComPort\n");
60 FreeLibrary(hinstLib);
64 closePort = (LPFNDLLFUNC2)GetProcAddress(hinstLib,
"CloseSSPComPortUSB");
65 if (closePort == NULL) {
66 printf(
"ERROR: unable to find DLL function CloseSSPComPort\n");
67 FreeLibrary(hinstLib);
71 sspSendCommand = (LPFNDLLFUNC3)GetProcAddress(hinstLib,
"SSPSendCommand");
72 if (sspSendCommand == NULL) {
73 printf(
"ERROR: unable to find DLL function SSPSendCommand\n");
74 FreeLibrary(hinstLib);
77 initiateSSPHostKeys = (LPFNDLLFUNC4)GetProcAddress(hinstLib,
"InitiateSSPHostKeys");
78 if (initiateSSPHostKeys == NULL) {
79 printf(
"ERROR: unable to find DLL function initiateSSPHostKeys\n");
80 FreeLibrary(hinstLib);
83 createSSPHostEncryptionKey = (LPFNDLLFUNC5)GetProcAddress(hinstLib,
"CreateSSPHostEncryptionKey");
84 if (createSSPHostEncryptionKey == NULL) {
85 printf(
"ERROR: unable to find DLL function createSSPHostEncryptionKey\n");
86 FreeLibrary(hinstLib);
104 for(i = 0; i < sp->CommandDataLength; i++)
105 ssp.CommandData[i] = sp->CommandData[i];
106 ssp.CommandDataLength = sp->CommandDataLength;
108 while(reTries < sp->RetryLevel){
112 if(sspSendCommand(sp,si) == 0){
113 sp->ResponseStatus = SSP_RESPONSE_TIMEOUT;
117 if(sp->ResponseData[0] == SSP_RESPONSE_OK){
118 sp->ResponseStatus = SSP_RESPONSE_OK;
123 if(sp->ResponseData[0] == SSP_RESPONSE_COMMAND_NOT_PROCESSED && sp->ResponseDataLength == 2 && sp->ResponseData[1] == 0x03 ){
126 for(i = 0; i < sp->CommandDataLength; i++)
127 sp->CommandData[i] = ssp.CommandData[i];
128 sp->CommandDataLength = ssp.CommandDataLength;
132 if(sp->ResponseData[0] == SSP_RESPONSE_COMMAND_NOT_PROCESSED && sp->ResponseDataLength == 2 && sp->ResponseData[1] == 0x01 ){
133 sp->ResponseStatus = SSP_RESPONSE_COMMAND_NOT_PROCESSED;
136 if(sp->ResponseData[0] == SSP_RESPONSE_COMMAND_NOT_PROCESSED && sp->ResponseDataLength == 2 && sp->ResponseData[1] == 0x02 ){
137 sp->ResponseStatus = SSP_RESPONSE_COMMAND_NOT_PROCESSED;
140 if(sp->ResponseData[0] == SSP_RESPONSE_COMMAND_NOT_PROCESSED && sp->ResponseDataLength == 2 && sp->ResponseData[1] == 0x04 ){
141 sp->ResponseStatus = SSP_RESPONSE_COMMAND_NOT_PROCESSED;
145 if(sp->ResponseData[0] == SSP_RESPONSE_KEY_NOT_SET){
146 sp->ResponseStatus = SSP_RESPONSE_KEY_NOT_SET;
155 if(reTries >= sp->RetryLevel) {
156 sp->ResponseStatus = SSP_RESPONSE_TIMEOUT;
160 sp->ResponseStatus = SSP_RESPONSE_OK;
165 return SendSSPCommand(sspC, &si);
177 if(initiateSSPHostKeys(&sKey,sspC) == 0){
178 printf(
"ERROR: Cannot Initiate host keys\n");
183 sspC->EncryptionStatus = 0;
184 sspC->CommandDataLength = 1;
185 sspC->CommandData[0] = SSP_CMD_SYNC;
186 if(send_ssp_command(sspC) == 0){
187 printf(
"ERROR: Error sending sync command to slave\n");
195 sspC->EncryptionStatus = 0;
196 sspC->CommandDataLength = 9;
197 sspC->CommandData[0] = SSP_CMD_SET_GENERATOR;
198 for(i = 0; i < 8; i++)
199 sspC->CommandData[i + 1] = (
unsigned char)(sKey.Generator >> (i*8));
200 if(send_ssp_command(sspC) == 0){
201 printf(
"ERROR: Error sending GENERATOR command to slave\n");
206 sspC->EncryptionStatus = 0;
207 sspC->CommandDataLength = 9;
208 sspC->CommandData[0] = SSP_CMD_SET_MODULUS;
209 for(i = 0; i < 8; i++)
210 sspC->CommandData[i + 1] = (
unsigned char)(sKey.Modulus >> (i*8));
211 if(send_ssp_command(sspC) == 0){
212 printf(
"ERROR: Error sending MODULUS command to slave\n");
217 sspC->EncryptionStatus = 0;
218 sspC->CommandDataLength = 9;
219 sspC->CommandData[0] = SSP_CMD_KEY_EXCHANGE;
220 for(i = 0; i < 8; i++)
221 sspC->CommandData[i + 1] = (
unsigned char)(sKey.HostInter >> (i*8));
222 if(send_ssp_command(sspC) == 0){
223 printf(
"ERROR: Error sending KEY_EXCHANGE command to slave\n");
227 sKey.SlaveInterKey = 0;
228 for(i = 0; i < 8; i++)
229 sKey.SlaveInterKey += ((
unsigned __int64)sspC->ResponseData[i + 1]) << (i*8);
233 if(createSSPHostEncryptionKey(&sKey) == 0){
234 printf(
"ERROR: Cannot Create host keys\n");
238 hostKey->EncryptKey = sKey.KeyHost;
Definition: port_win32_ssp.h:35
Definition: port_win32_ssp.h:67
Definition: port_win32_ssp.h:57
Definition: port_win32_ssp.h:30