User's Manual

48
Names of data files, DLL.
Names of functions called on the other DLLs.
10.3 Examples of implementation
This chapter contains some examples of C implementation of the guidelines we have described. Furthermore, they can
be found in the archive:
SmartKeyProtectionGuidelinesExample.zip
.
In all the examples, we suppose that you are working with a SmartKey Demo with Label “SMARTKEY” and Password
“EUTRON” as default.
10.3.1 Example 1 – Basic Use
This example shows the basic use of SmartKey. The purpose of the program is to initialize the variables for SmartKey
and check if the dongle is actually present. The example MUST NOT BE USED IN A REAL PROGRAM, because the
label and password are included in the code without using any protection technique and one could trace them by
analyzing the executable file.
#include "skeylink.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
KEY_NET k;
memset(&k,0,sizeof(k));
strncpy(k.label,"SMARTKEY",LABEL_LENGTH);
strncpy(k.password,"EUTRON",PASSWORD_LENGTH);
/* Open */
k.net_command = NET_KEY_OPEN;
smartlink(&k); /* Chiamata a sistema */
if (k.status != ST_OK) {
printf("Error in NET_KEY_OPEN\n");
exit(EXIT_FAILURE);
}
/* Close */
k.net_command = NET_KEY_CLOSE;
smartlink(&k);
if (k.status != ST_OK) {
printf("Error in NET_KEY_CLOSE\n");
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
10.3.2 Example 2 – Basic use of Scrambling
This example shows the basic use of the scrambling operation. This example too MUST NOT BE USED IN A REAL
PROGRAM, because the values included in the code are not protected.
#include "skeylink.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Scrambling input/output */
unsigned char scrambling_in[SCRAMBLE_LENGTH] = { 0x45, 0x34, 0x67, 0x23, 0xa5,
0x8f, 0x2c, 0x6d };