User's Manual
53
return EXIT_SUCCESS;
}
10.3.6 Example 7 – Scrambling confidential data
This example shows how to hide confidential data with the Scrambling operation.
In the example the pi value is stored as follows:
#include "skeylink.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
/* Scrambled data */
unsigned char scrambled_data[SCRAMBLE_LENGTH] = {
0x0c, 0xd8, 0xb3, 0xf6, 0x57, 0x6f, 0x4d, 0xe5
};
/* Scrambled input */
unsigned char scrambling_in[SCRAMBLE_LENGTH] = {
0x45, 0x34, 0x67, 0x23, 0xa5, 0x8f, 0x2c, 0x6d
};
int main() {
KEY_NET k;
unsigned i;
double pi;
/* Scrambling */
k.net_command = NET_KEY_ACCESS;
k.command = SCRAMBLING_MODE;
memcpy(k.data,scrambling_in,SCRAMBLE_LENGTH);
smartlink(&k);
if (k.status != ST_OK) {
printf("Error in SCRAMBLING_MODE\n");
exit(EXIT_FAILURE);
}
for(i=0;i<sizeof(pi);++i)
((unsigned char*)&pi)[i] = k.data[i] ^ scrambled_data[i];
printf("Pi greco is %g\n",pi);
/* 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.7 Example 8/9–Generating and using a large Scrambling table
This example shows how to generate and use a large scrambling table. The input values of the scrambling operation are
calculated during execution, using the index as the initialization of a simple random function.
Generating the “table.h” file
This example generates the
table.h file
#include "skeylink.h"
#include <stdio.h>