User's Manual
55
/* 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;
}
Using the Scrambling table
This example uses the generated file to control the presence of the SmartKey dongle.
#include "skeylink.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "table.h"
/* Return a random index in the table */
unsigned get_scrambling_index(void) {
time_t t;
struct tm* ptm;
unsigned i;
time(&t);
ptm = localtime(&t);
i = (rand() % (SCRAMBLE_MAX / 31)) * 31;
i += ptm->tm_mday;
i = i % SCRAMBLE_MAX;
return i;
}
int main() {
KEY_NET k;
unsigned i;
/* Initialized the random number generator */
srand(time(0));
/* Get the random index in the table */
i = get_scrambling_index();
printf("Scramble index %d\n",i);
/* Do the scrambling */
k.net_command = NET_KEY_ACCESS;
k.command = SCRAMBLING_MODE;
scramble_in(k.data,i);
smartlink(&k);
if (k.status != ST_OK) {
printf("Error in SCRAMBLING_MODE\n");
exit(EXIT_FAILURE);
}
/* Check the scramble */
if (memcmp(k.data,SCRAMBLE[i],SCRAMBLE_LENGTH)!=0) {