User's Manual
58
#include <stdio.h>
#include <time.h>
#include <windows.h>
/* Serial */
unsigned char serial[16] = {
0x39, 0x9d, 0x81, 0xd0, 0x6f, 0x78, 0x94, 0x41, 0xec, 0xfe, 0x71, 0xa1, 0x21,
0xd4, 0xe1, 0x6d,
};
/* 20 AES keys */
unsigned char aeskey[16*20] = {
0x27, 0xe1, 0x4e, 0xf4, 0x82, 0x3a, 0x1d, 0xa2, 0xbd, 0xee, 0xc7, 0xd2, 0x50,
0xe1, 0x37, 0x66,
…stripped…
0x57, 0x4b, 0x21, 0x94, 0x82, 0x38, 0x68, 0xf8, 0xf8, 0x54, 0x38, 0xa1, 0x6d,
0x05, 0x70, 0x39,
};
int main() {
SKEY_DATA key;
aes_context aes;
unsigned key_index;
unsigned char result_buffer[16];
unsigned char random_buffer[16];
unsigned i;
printf("SmartKey AES example\n");
/* initialize the random number generator */
srand(time(0));
memset(&key, 0, sizeof(key));
strncpy(key.label, "SMARTKEY", LABEL_LENGTH);
key.command = LOCATING_MODE;
msclink(&key);
if (key.status != 0) {
MessageBox(NULL, "SmartKey not found", "Error", MB_ICONERROR |
MB_SYSTEMMODAL);
exit(1);
}
key.command = EXT_MODEL_READING_MODE;
msclink(&key);
if (key.status != 0) {
MessageBox(NULL, "SmartKey not found", "Error", MB_ICONERROR |
MB_SYSTEMMODAL);
exit(1);
}
if ((key.data[3] & 0x1) == 0) {
MessageBox(NULL, "This SmartKey model doesn't support AES commands",
"Error", MB_ICONERROR | MB_SYSTEMMODAL);
exit(1);
}
/* set the random value */
for(i=0;i<16;++i)
random_buffer[i] = rand() % 256;
/* set the key number */
key_index = rand() % 20;
memcpy(key.data, random_buffer, 16);