summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-26 00:19:45 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-26 00:19:45 +0200
commitf84ea240b18ce93ae26030ce28d19af4bc9962a1 (patch)
tree0031e87ea33a0e789bdda9b2beadbf7291c8faf2 /examples
parent6a2560330da7bc05ccb9bc75e70ce745acba7d6c (diff)
downloadcryptodev-linux-f84ea240b18ce93ae26030ce28d19af4bc9962a1.tar.gz
cryptodev-linux-f84ea240b18ce93ae26030ce28d19af4bc9962a1.tar.xz
cryptodev-linux-f84ea240b18ce93ae26030ce28d19af4bc9962a1.zip
removed the data type.
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile5
-rw-r--r--examples/ncr.c399
-rw-r--r--examples/pk.c148
-rw-r--r--examples/speed.c113
4 files changed, 92 insertions, 573 deletions
diff --git a/examples/Makefile b/examples/Makefile
index ff5381d..100cc49 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,7 +1,7 @@
CC = gcc
CFLAGS = -Wall -g -O2
-progs := cipher hmac ncr pk speed ncr-direct
+progs := cipher hmac ncr pk speed
all: $(progs)
@@ -22,11 +22,10 @@ pk: pk.c
check: $(progs)
./ncr
- ./ncr-direct
./pk
./cipher
./hmac
./speed
clean:
- rm -f *.o *~ hmac cipher ncr pk speed ncr-direct
+ rm -f *.o *~ hmac cipher ncr pk speed \ No newline at end of file
diff --git a/examples/ncr.c b/examples/ncr.c
index f2c4b72..4ff59fd 100644
--- a/examples/ncr.c
+++ b/examples/ncr.c
@@ -32,11 +32,9 @@ int i;
static int
test_ncr_key(int cfd)
{
- struct ncr_data_init_st dinit;
struct ncr_key_generate_st kgen;
ncr_key_t key;
struct ncr_key_data_st keydata;
- struct ncr_data_st kdata;
uint8_t data[KEY_DATA_SIZE];
uint8_t data_bak[KEY_DATA_SIZE];
@@ -51,17 +49,6 @@ test_ncr_key(int cfd)
randomize_data(data, sizeof(data));
memcpy(data_bak, data, sizeof(data));
- dinit.max_object_size = KEY_DATA_SIZE;
- dinit.flags = NCR_DATA_FLAG_EXPORTABLE;
- dinit.initial_data = data;
- dinit.initial_data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &dinit)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
/* convert it to key */
if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
perror("ioctl(NCRIO_KEY_INIT)");
@@ -76,7 +63,8 @@ test_ncr_key(int cfd)
keydata.flags = NCR_KEY_FLAG_EXPORTABLE;
keydata.key = key;
- keydata.data = dinit.desc;
+ keydata.idata = data;
+ keydata.idata_size = sizeof(data);
if (ioctl(cfd, NCRIO_KEY_IMPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
@@ -86,43 +74,21 @@ test_ncr_key(int cfd)
/* now try to read it */
fprintf(stdout, "\tKey export...\n");
- if (ioctl(cfd, NCRIO_DATA_DEINIT, &dinit.desc)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_DEINIT)");
- return 1;
- }
-
- dinit.max_object_size = DATA_SIZE;
- dinit.flags = NCR_DATA_FLAG_EXPORTABLE;
- dinit.initial_data = NULL;
- dinit.initial_data_size = 0;
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &dinit)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
memset(&keydata, 0, sizeof(keydata));
keydata.key = key;
- keydata.data = dinit.desc;
+ keydata.idata = data;
+ keydata.idata_size = sizeof(data);
if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_IMPORT)");
return 1;
}
-
- /* now read data */
- memset(&kdata, 0, sizeof(kdata));
-
- kdata.desc = dinit.desc;
- kdata.data = data;
- kdata.data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_GET, &kdata)) {
+
+ if (keydata.idata_size != sizeof(data)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_GET)");
+ fprintf(stderr, "data returned but differ!\n");
return 1;
}
@@ -162,9 +128,12 @@ test_ncr_key(int cfd)
return 1;
}
+ memset(data, 0, sizeof(data));
+
memset(&keydata, 0, sizeof(keydata));
keydata.key = key;
- keydata.data = dinit.desc;
+ keydata.idata = data;
+ keydata.idata_size = sizeof(data);
if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
@@ -172,27 +141,16 @@ test_ncr_key(int cfd)
return 1;
}
- /* now read data */
- memset(data, 0, sizeof(data));
-
- kdata.desc = dinit.desc;
- kdata.data = data;
- kdata.data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_GET, &kdata)) {
+ if (keydata.idata_size == 0 || (data[0] == 0 && data[1] == 0 && data[2] == 0 && data[4] == 0)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_GET)");
+ fprintf(stderr, "Generated key: %.2x.%.2x.%.2x.%.2x.%.2x.%.2x.%.2x.%.2x."
+ "%.2x.%.2x.%.2x.%.2x.%.2x.%.2x.%.2x.%.2x\n", data[0], data[1],
+ data[2], data[3], data[4], data[5], data[6], data[7], data[8],
+ data[9], data[10], data[11], data[12], data[13], data[14],
+ data[15]);
return 1;
}
-#if 0
- fprintf(stderr, "Generated key: %.2x.%.2x.%.2x.%.2x.%.2x.%.2x.%.2x.%.2x."
- "%.2x.%.2x.%.2x.%.2x.%.2x.%.2x.%.2x.%.2x\n", data[0], data[1],
- data[2], data[3], data[4], data[5], data[6], data[7], data[8],
- data[9], data[10], data[11], data[12], data[13], data[14],
- data[15]);
-#endif
-
if (ioctl(cfd, NCRIO_KEY_DEINIT, &key)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_DEINIT)");
@@ -219,24 +177,16 @@ test_ncr_key(int cfd)
return 1;
}
+ memset(data, 0, sizeof(data));
+
memset(&keydata, 0, sizeof(keydata));
keydata.key = key;
- keydata.data = dinit.desc;
-
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_KEY_EXPORT)");
- return 1;
- }
+ keydata.idata = data;
+ keydata.idata_size = sizeof(data);
/* try to get the output data - should fail */
- memset(data, 0, sizeof(data));
-
- kdata.desc = dinit.desc;
- kdata.data = data;
- kdata.data_size = sizeof(data);
- if (ioctl(cfd, NCRIO_DATA_GET, &kdata)==0) {
+ if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)==0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
fprintf(stderr, "Data were exported, but shouldn't be!\n");
return 1;
@@ -252,135 +202,14 @@ test_ncr_key(int cfd)
}
-static int test_ncr_data(int cfd)
-{
- struct ncr_data_init_st init;
- struct ncr_data_st kdata;
- uint8_t data[DATA_SIZE];
- uint8_t data_bak[DATA_SIZE];
- int i;
-
- fprintf(stdout, "Tests on Data:\n");
-
- randomize_data(data, sizeof(data));
- memcpy(data_bak, data, sizeof(data));
-
- init.max_object_size = DATA_SIZE;
- init.flags = NCR_DATA_FLAG_EXPORTABLE;
- init.initial_data = data;
- init.initial_data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &init)) {
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
- fprintf(stdout, "\tData Import...\n");
-
- memset(data, 0, sizeof(data));
-
- kdata.desc = init.desc;
- kdata.data = data;
- kdata.data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_GET, &kdata)) {
- perror("ioctl(NCRIO_DATA_GET)");
- return 1;
- }
-
- if (memcmp(data, data_bak, sizeof(data))!=0) {
- fprintf(stderr, "data returned but differ!\n");
- return 1;
- }
-
- fprintf(stdout, "\tData Export...\n");
-
- /* test set */
- memset(data, 0xf1, sizeof(data));
-
- kdata.desc = init.desc;
- kdata.data = data;
- kdata.data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_SET, &kdata)) {
- perror("ioctl(NCRIO_DATA_SET)");
- return 1;
- }
-
- /* test get after set */
- memset(data, 0, sizeof(data));
-
- kdata.desc = init.desc;
- kdata.data = data;
- kdata.data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_GET, &kdata)) {
- perror("ioctl(NCRIO_DATA_GET)");
- return 1;
- }
-
- for(i=0;i<kdata.data_size;i++) {
- if (((uint8_t*)kdata.data)[i] != 0xf1) {
- fprintf(stderr, "data returned but differ!\n");
- return 1;
- }
- }
- fprintf(stdout, "\t2nd Data Import/Export...\n");
-
- if (ioctl(cfd, NCRIO_DATA_DEINIT, &kdata.desc)) {
- perror("ioctl(NCRIO_DATA_DEINIT)");
- return 1;
- }
-
- fprintf(stdout, "\tProtection of non-exportable data...\n");
- randomize_data(data, sizeof(data));
-
- init.max_object_size = DATA_SIZE;
- init.flags = 0;
- init.initial_data = data;
- init.initial_data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &init)) {
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
- kdata.desc = init.desc;
- kdata.data = data;
- kdata.data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_GET, &kdata)==0) {
- fprintf(stderr, "Unexportable data were exported!?\n");
- return 1;
- }
-
- fprintf(stdout, "\tLimits on maximum allowed data...\n");
- for (i=0;i<256;i++ ) {
- init.max_object_size = DATA_SIZE;
- init.flags = 0;
- init.initial_data = data;
- init.initial_data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &init)) {
- //fprintf(stderr, "Reached maximum limit at: %d data items\n", i);
- break;
- }
- }
-
- /* shouldn't run any other tests after that */
-
- return 0;
-}
/* Key wrapping */
static int
test_ncr_wrap_key(int cfd)
{
int i;
- struct ncr_data_init_st dinit;
ncr_key_t key, key2;
struct ncr_key_data_st keydata;
- struct ncr_data_st kdata;
struct ncr_key_wrap_st kwrap;
uint8_t data[WRAPPED_KEY_DATA_SIZE];
int data_size;
@@ -393,17 +222,6 @@ test_ncr_wrap_key(int cfd)
fprintf(stdout, "\tKey Wrap test...\n");
- dinit.max_object_size = WRAPPED_KEY_DATA_SIZE;
- dinit.flags = NCR_DATA_FLAG_EXPORTABLE;
- dinit.initial_data = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
- dinit.initial_data_size = 16;
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &dinit)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
/* convert it to key */
if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
perror("ioctl(NCRIO_KEY_INIT)");
@@ -418,7 +236,8 @@ test_ncr_wrap_key(int cfd)
keydata.flags = NCR_KEY_FLAG_EXPORTABLE|NCR_KEY_FLAG_WRAPPABLE;
keydata.key = key;
- keydata.data = dinit.desc;
+ keydata.idata = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
+ keydata.idata_size = 16;
if (ioctl(cfd, NCRIO_KEY_IMPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
@@ -426,17 +245,6 @@ test_ncr_wrap_key(int cfd)
return 1;
}
-#define DKEY "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF"
- /* now key data */
- kdata.data = DKEY;
- kdata.data_size = 16;
- kdata.desc = dinit.desc;
-
- if (ioctl(cfd, NCRIO_DATA_SET, &kdata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_SET)");
- return 1;
- }
/* convert it to key */
if (ioctl(cfd, NCRIO_KEY_INIT, &key2)) {
@@ -452,7 +260,9 @@ test_ncr_wrap_key(int cfd)
keydata.flags = NCR_KEY_FLAG_EXPORTABLE|NCR_KEY_FLAG_WRAPPABLE;
keydata.key = key2;
- keydata.data = kdata.desc;
+#define DKEY "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF"
+ keydata.idata = DKEY;
+ keydata.idata_size = 16;
if (ioctl(cfd, NCRIO_KEY_IMPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
@@ -556,13 +366,10 @@ static int
test_ncr_store_wrap_key(int cfd)
{
int i;
- struct ncr_data_init_st dinit;
ncr_key_t key2;
struct ncr_key_data_st keydata;
- struct ncr_data_st kdata;
struct ncr_key_storage_wrap_st kwrap;
uint8_t data[DATA_SIZE];
- int dd;
int data_size;
fprintf(stdout, "Tests on Key storage:\n");
@@ -573,30 +380,6 @@ test_ncr_store_wrap_key(int cfd)
fprintf(stdout, "\tKey Storage wrap test...\n");
- memset(&dinit, 0, sizeof(dinit));
- dinit.max_object_size = DATA_SIZE;
- dinit.flags = NCR_DATA_FLAG_EXPORTABLE;
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &dinit)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
- dd = dinit.desc;
-
-#define DKEY "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF"
- /* now key data */
- kdata.data = DKEY;
- kdata.data_size = 16;
- kdata.desc = dd;
-
- if (ioctl(cfd, NCRIO_DATA_SET, &kdata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_SET)");
- return 1;
- }
-
/* convert it to key */
if (ioctl(cfd, NCRIO_KEY_INIT, &key2)) {
perror("ioctl(NCRIO_KEY_INIT)");
@@ -611,7 +394,9 @@ test_ncr_store_wrap_key(int cfd)
keydata.flags = NCR_KEY_FLAG_EXPORTABLE|NCR_KEY_FLAG_WRAPPABLE;
keydata.key = key2;
- keydata.data = dd;
+#define DKEY "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF"
+ keydata.idata = DKEY;
+ keydata.idata_size = 16;
if (ioctl(cfd, NCRIO_KEY_IMPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
@@ -662,25 +447,21 @@ test_ncr_store_wrap_key(int cfd)
/* now export the unwrapped */
memset(&keydata, 0, sizeof(keydata));
keydata.key = key2;
- keydata.data = dd;
+ keydata.idata = data;
+ keydata.idata_size = sizeof(data);
if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_IMPORT)");
return 1;
}
+
+ data_size = keydata.idata_size;
- kdata.data = data;
- if (ioctl(cfd, NCRIO_DATA_GET, &kdata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_GET)");
- return 1;
- }
-
- if (kdata.data_size != 16 || memcmp(kdata.data, DKEY, 16) != 0) {
+ if (data_size != 16 || memcmp(data, DKEY, 16) != 0) {
fprintf(stderr, "Unwrapped data do not match.\n");
- fprintf(stderr, "Data[%d]: ", (int) kdata.data_size);
- for(i=0;i<kdata.data_size;i++)
+ fprintf(stderr, "Data[%d]: ", (int) data_size);
+ for(i=0;i<data_size;i++)
fprintf(stderr, "%.2x:", data[i]);
fprintf(stderr, "\n");
return 1;
@@ -726,37 +507,13 @@ struct aes_vectors_st {
static int
test_ncr_aes(int cfd)
{
- struct ncr_data_init_st dinit;
ncr_key_t key;
struct ncr_key_data_st keydata;
- struct ncr_data_st kdata;
- ncr_data_t dd, dd2;
uint8_t data[KEY_DATA_SIZE];
int i, j;
struct ncr_session_once_op_st nop;
int data_size;
- dinit.max_object_size = KEY_DATA_SIZE;
- dinit.flags = NCR_DATA_FLAG_EXPORTABLE;
- dinit.initial_data = NULL;
- dinit.initial_data_size = 0;
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &dinit)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
- dd = dinit.desc;
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &dinit)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
- dd2 = dinit.desc;
-
/* convert it to key */
if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
perror("ioctl(NCRIO_KEY_INIT)");
@@ -774,19 +531,9 @@ test_ncr_aes(int cfd)
fprintf(stdout, "Tests on AES Encryption\n");
for (i=0;i<sizeof(aes_vectors)/sizeof(aes_vectors[0]);i++) {
- /* import key */
- kdata.data = (void*)aes_vectors[i].key;
- kdata.data_size = 16;
- kdata.desc = dd;
-
- if (ioctl(cfd, NCRIO_DATA_SET, &kdata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_SET)");
- return 1;
- }
-
keydata.key = key;
- keydata.data = dd;
+ keydata.idata = (void*)aes_vectors[i].key;
+ keydata.idata_size = 16;
if (ioctl(cfd, NCRIO_KEY_IMPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_IMPORT)");
@@ -832,19 +579,9 @@ test_ncr_aes(int cfd)
fprintf(stdout, "Tests on AES Decryption\n");
for (i=0;i<sizeof(aes_vectors)/sizeof(aes_vectors[0]);i++) {
- /* import key */
- kdata.data = (void*)aes_vectors[i].key;
- kdata.data_size = 16;
- kdata.desc = dd;
-
- if (ioctl(cfd, NCRIO_DATA_SET, &kdata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_SET)");
- return 1;
- }
-
keydata.key = key;
- keydata.data = dd;
+ keydata.idata = (void*)aes_vectors[i].key;
+ keydata.idata_size = 16;
if (ioctl(cfd, NCRIO_KEY_IMPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_IMPORT)");
@@ -979,36 +716,12 @@ struct hash_vectors_st {
static int
test_ncr_hash(int cfd)
{
- struct ncr_data_init_st dinit;
ncr_key_t key;
struct ncr_key_data_st keydata;
- struct ncr_data_st kdata;
- ncr_data_t dd, dd2;
uint8_t data[HASH_DATA_SIZE];
int i, j, data_size;
struct ncr_session_once_op_st nop;
- dinit.max_object_size = HASH_DATA_SIZE;
- dinit.flags = NCR_DATA_FLAG_EXPORTABLE;
- dinit.initial_data = NULL;
- dinit.initial_data_size = 0;
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &dinit)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
- dd = dinit.desc;
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &dinit)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
- dd2 = dinit.desc;
-
/* convert it to key */
if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
perror("ioctl(NCRIO_KEY_INIT)");
@@ -1029,18 +742,10 @@ test_ncr_hash(int cfd)
fprintf(stdout, "\t%s:\n", hash_vectors[i].name);
/* import key */
if (hash_vectors[i].key != NULL) {
- kdata.data = (void*)hash_vectors[i].key;
- kdata.data_size = hash_vectors[i].key_size;
- kdata.desc = dd;
-
- if (ioctl(cfd, NCRIO_DATA_SET, &kdata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_SET)");
- return 1;
- }
keydata.key = key;
- keydata.data = dd;
+ keydata.idata = (void*)hash_vectors[i].key;
+ keydata.idata_size = hash_vectors[i].key_size;
if (ioctl(cfd, NCRIO_KEY_IMPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_IMPORT)");
@@ -1105,24 +810,6 @@ main()
return 1;
}
- /* Run the test itself */
- if (test_ncr_data(fd))
- return 1;
-
- /* Close the original descriptor */
- if (close(fd)) {
- perror("close(fd)");
- return 1;
- }
-
- /* actually test if the initial close
- * will really delete all used lists */
-
- fd = open("/dev/crypto", O_RDWR, 0);
- if (fd < 0) {
- perror("open(/dev/crypto)");
- return 1;
- }
if (test_ncr_key(fd))
return 1;
diff --git a/examples/pk.c b/examples/pk.c
index a529e9a..1aa4c5a 100644
--- a/examples/pk.c
+++ b/examples/pk.c
@@ -310,7 +310,7 @@ static int rsa_key_encrypt(int cfd, ncr_key_t privkey, ncr_key_t pubkey, int oae
fflush(stdout);
memset(data, 0x3, sizeof(data));
- memset(vdata, 0x0, sizeof(vdata));
+ memcpy(vdata, data, sizeof(vdata));
/* do encryption */
memset(&nop, 0, sizeof(nop));
@@ -325,8 +325,8 @@ static int rsa_key_encrypt(int cfd, ncr_key_t privkey, ncr_key_t pubkey, int oae
nop.init.op = NCR_OP_ENCRYPT;
nop.op.data.udata.input = data;
nop.op.data.udata.input_size = RSA_ENCRYPT_SIZE;
- nop.op.data.udata.output = vdata;
- nop.op.data.udata.output_size = sizeof(vdata);
+ nop.op.data.udata.output = data;
+ nop.op.data.udata.output_size = sizeof(data);
nop.op.type = NCR_DIRECT_DATA;
if (ioctl(cfd, NCRIO_SESSION_ONCE, &nop)) {
@@ -348,10 +348,10 @@ static int rsa_key_encrypt(int cfd, ncr_key_t privkey, ncr_key_t pubkey, int oae
} else {
nop.init.params.params.rsa.type = RSA_PKCS1_V1_5;
}
- nop.op.data.udata.input = vdata;
+ nop.op.data.udata.input = data;
nop.op.data.udata.input_size = enc_size;
- nop.op.data.udata.output = vdata;
- nop.op.data.udata.output_size = sizeof(vdata);
+ nop.op.data.udata.output = data;
+ nop.op.data.udata.output_size = sizeof(data);
nop.op.type = NCR_DIRECT_DATA;
@@ -373,6 +373,8 @@ static int rsa_key_encrypt(int cfd, ncr_key_t privkey, ncr_key_t pubkey, int oae
}
+#define DATA_TO_SIGN 52
+
static int rsa_key_sign_verify(int cfd, ncr_key_t privkey, ncr_key_t pubkey, int pss)
{
struct ncr_session_once_op_st nop;
@@ -394,7 +396,7 @@ static int rsa_key_sign_verify(int cfd, ncr_key_t privkey, ncr_key_t pubkey, int
nop.init.op = NCR_OP_SIGN;
nop.op.data.udata.input = data;
- nop.op.data.udata.input_size = sizeof(data);
+ nop.op.data.udata.input_size = DATA_TO_SIGN;
nop.op.data.udata.output = sig;
nop.op.data.udata.output_size = sizeof(sig);
nop.op.type = NCR_DIRECT_DATA;
@@ -414,9 +416,11 @@ static int rsa_key_sign_verify(int cfd, ncr_key_t privkey, ncr_key_t pubkey, int
nop.init.params.params.rsa.type = (pss!=0)?RSA_PKCS1_PSS:RSA_PKCS1_V1_5;
nop.init.params.params.rsa.sign_hash = NCR_ALG_SHA1;
+ memset(data, 0x3, sizeof(data));
+
nop.init.op = NCR_OP_VERIFY;
nop.op.data.udata.input = data;
- nop.op.data.udata.input_size = sizeof(data);
+ nop.op.data.udata.input_size = DATA_TO_SIGN;
nop.op.data.udata.output = sig;
nop.op.data.udata.output_size = sig_size;
nop.op.type = NCR_DIRECT_DATA;
@@ -429,8 +433,10 @@ static int rsa_key_sign_verify(int cfd, ncr_key_t privkey, ncr_key_t pubkey, int
if (nop.op.err == NCR_SUCCESS)
fprintf(stdout, " Success\n");
- else
+ else {
fprintf(stdout, " Verification Failed!\n");
+ return 1;
+ }
return 0;
@@ -456,7 +462,7 @@ static int dsa_key_sign_verify(int cfd, ncr_key_t privkey, ncr_key_t pubkey)
nop.init.op = NCR_OP_SIGN;
nop.op.data.udata.input = data;
- nop.op.data.udata.input_size = sizeof(data);
+ nop.op.data.udata.input_size = DATA_TO_SIGN;
nop.op.data.udata.output = sig;
nop.op.data.udata.output_size = sizeof(sig);
nop.op.type = NCR_DIRECT_DATA;
@@ -477,7 +483,7 @@ static int dsa_key_sign_verify(int cfd, ncr_key_t privkey, ncr_key_t pubkey)
nop.init.op = NCR_OP_VERIFY;
nop.op.data.udata.input = data;
- nop.op.data.udata.input_size = sizeof(data);
+ nop.op.data.udata.input_size = DATA_TO_SIGN;
nop.op.data.udata.output = sig;
nop.op.data.udata.output_size = sizeof(sig);
nop.op.type = NCR_DIRECT_DATA;
@@ -490,8 +496,10 @@ static int dsa_key_sign_verify(int cfd, ncr_key_t privkey, ncr_key_t pubkey)
if (nop.op.err == NCR_SUCCESS)
fprintf(stdout, " Success\n");
- else
+ else {
fprintf(stdout, " Verification Failed!\n");
+ return 1;
+ }
return 0;
@@ -501,12 +509,11 @@ static int dsa_key_sign_verify(int cfd, ncr_key_t privkey, ncr_key_t pubkey)
static int test_ncr_rsa(int cfd)
{
int ret;
- struct ncr_data_init_st dinit;
struct ncr_key_generate_st kgen;
ncr_key_t pubkey, privkey;
struct ncr_key_data_st keydata;
- struct ncr_data_st kdata;
uint8_t data[DATA_SIZE];
+ int data_size;
fprintf(stdout, "Tests on RSA key generation:");
fflush(stdout);
@@ -538,41 +545,21 @@ static int test_ncr_rsa(int cfd)
}
/* export the private key */
- dinit.max_object_size = DATA_SIZE;
- dinit.flags = NCR_DATA_FLAG_EXPORTABLE;
- dinit.initial_data = NULL;
- dinit.initial_data_size = 0;
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &dinit)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
+ memset(data, 0, sizeof(data));
memset(&keydata, 0, sizeof(keydata));
keydata.key = privkey;
- keydata.data = dinit.desc;
+ keydata.idata = data;
+ keydata.idata_size = sizeof(data);
if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
+
+ data_size = keydata.idata_size;
- /* now read data */
- memset(data, 0, sizeof(data));
-
- kdata.desc = dinit.desc;
- kdata.data = data;
- kdata.data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_GET, &kdata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_GET)");
- return 1;
- }
-
- ret = privkey_info(kdata.data, kdata.data_size, 0);
+ ret = privkey_info(data, data_size, 0);
if (ret != 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
return 1;
@@ -580,30 +567,21 @@ static int test_ncr_rsa(int cfd)
/* export the public key */
+ memset(data, 0, sizeof(data));
memset(&keydata, 0, sizeof(keydata));
keydata.key = pubkey;
- keydata.data = dinit.desc;
+ keydata.idata = data;
+ keydata.idata_size = sizeof(data);
if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_IMPORT)");
return 1;
}
-
- /* now read data */
- memset(data, 0, sizeof(data));
-
- kdata.desc = dinit.desc;
- kdata.data = data;
- kdata.data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_GET, &kdata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_GET)");
- return 1;
- }
- ret = pubkey_info(kdata.data, kdata.data_size, 0);
+ data_size = keydata.idata_size;
+
+ ret = pubkey_info(data, data_size, 0);
if (ret != 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
return 1;
@@ -611,13 +589,13 @@ static int test_ncr_rsa(int cfd)
fprintf(stdout, " Success\n");
- ret = rsa_key_sign_verify(cfd, privkey, pubkey, 0);
+ ret = rsa_key_sign_verify(cfd, privkey, pubkey, 1);
if (ret != 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
return 1;
}
- ret = rsa_key_sign_verify(cfd, privkey, pubkey, 1);
+ ret = rsa_key_sign_verify(cfd, privkey, pubkey, 0);
if (ret != 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
return 1;
@@ -642,12 +620,11 @@ static int test_ncr_rsa(int cfd)
static int test_ncr_dsa(int cfd)
{
int ret;
- struct ncr_data_init_st dinit;
struct ncr_key_generate_st kgen;
ncr_key_t pubkey, privkey;
struct ncr_key_data_st keydata;
- struct ncr_data_st kdata;
uint8_t data[DATA_SIZE];
+ int data_size;
fprintf(stdout, "Tests on DSA key generation:");
fflush(stdout);
@@ -679,42 +656,20 @@ static int test_ncr_dsa(int cfd)
return 1;
}
- /* export the private key */
- dinit.max_object_size = DATA_SIZE;
- dinit.flags = NCR_DATA_FLAG_EXPORTABLE;
- dinit.initial_data = NULL;
- dinit.initial_data_size = 0;
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &dinit)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
memset(&keydata, 0, sizeof(keydata));
+ memset(data, 0, sizeof(data));
keydata.key = privkey;
- keydata.data = dinit.desc;
+ keydata.idata = data;
+ keydata.idata_size = sizeof(data);
if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
+ data_size = keydata.idata_size;
- /* now read data */
- memset(data, 0, sizeof(data));
-
- kdata.desc = dinit.desc;
- kdata.data = data;
- kdata.data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_GET, &kdata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_GET)");
- return 1;
- }
-
- ret = privkey_info(kdata.data, kdata.data_size, 0);
+ ret = privkey_info(data, data_size, 0);
if (ret != 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
return 1;
@@ -722,30 +677,21 @@ static int test_ncr_dsa(int cfd)
/* export the public key */
+ memset(data, 0, sizeof(data));
memset(&keydata, 0, sizeof(keydata));
keydata.key = pubkey;
- keydata.data = dinit.desc;
+ keydata.idata = data;
+ keydata.idata_size = sizeof(data);
if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_IMPORT)");
return 1;
}
-
- /* now read data */
- memset(data, 0, sizeof(data));
-
- kdata.desc = dinit.desc;
- kdata.data = data;
- kdata.data_size = sizeof(data);
-
- if (ioctl(cfd, NCRIO_DATA_GET, &kdata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_GET)");
- return 1;
- }
- ret = pubkey_info(kdata.data, kdata.data_size, 0);
+ data_size = keydata.idata_size;
+
+ ret = pubkey_info(data, data_size, 0);
if (ret != 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
return 1;
diff --git a/examples/speed.c b/examples/speed.c
index d49faa9..5898aaa 100644
--- a/examples/speed.c
+++ b/examples/speed.c
@@ -116,107 +116,6 @@ int encrypt_data(struct session_op *sess, int fdc, int chunksize)
return 0;
}
-int encrypt_data_ncr(int cfd, int algo, int chunksize)
-{
- char *buffer, iv[32];
- static int val = 23;
- struct timeval start, end;
- double total = 0;
- double secs, ddata, dspeed;
- char metric[16];
- ncr_key_t key;
- struct ncr_key_generate_st kgen;
- struct ncr_data_init_st dinit;
- struct ncr_data_st kdata;
- struct ncr_session_once_op_st nop;
- ncr_data_t dd;
-
- if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_KEY_INIT)");
- return 1;
- }
-
- kgen.desc = key;
- kgen.params.algorithm = NCR_ALG_AES_CBC;
- kgen.params.keyflags = NCR_KEY_FLAG_EXPORTABLE;
- kgen.params.params.secret.bits = 128; /* 16 bytes */
-
- if (ioctl(cfd, NCRIO_KEY_GENERATE, &kgen)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_KEY_IMPORT)");
- return 1;
- }
-
-
- buffer = malloc(chunksize);
- memset(iv, 0x23, 32);
-
- memset(&dinit, 0, sizeof(dinit));
- dinit.max_object_size = chunksize;
- dinit.flags = NCR_DATA_FLAG_EXPORTABLE;
- dinit.initial_data = buffer;
- dinit.initial_data_size = chunksize;
-
- if (ioctl(cfd, NCRIO_DATA_INIT, &dinit)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
- dd = dinit.desc;
-
- printf("\tEncrypting in chunks of %d bytes: ", chunksize);
- fflush(stdout);
-
- memset(buffer, val++, chunksize);
-
- must_finish = 0;
- alarm(5);
-
- gettimeofday(&start, NULL);
- do {
- kdata.data = buffer;
- kdata.data_size = chunksize;
- kdata.desc = dd;
-
- if (ioctl(cfd, NCRIO_DATA_SET, &kdata)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
- memset(&nop, 0, sizeof(nop));
- nop.init.algorithm = algo;
- nop.init.key = key;
- nop.init.op = NCR_OP_ENCRYPT;
- nop.op.data.ndata.input = dd;
- nop.op.data.ndata.output = dd;
- nop.op.type = NCR_DATA;
-
- if (ioctl(cfd, NCRIO_SESSION_ONCE, &nop)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_SESSION_ONCE)");
- return 1;
- }
-
- total+=chunksize;
- } while(must_finish==0);
- gettimeofday(&end, NULL);
-
- if (ioctl(cfd, NCRIO_DATA_DEINIT, &dd)) {
- fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_DATA_INIT)");
- return 1;
- }
-
- secs = udifftimeval(start, end)/ 1000000.0;
-
- value2human(total, secs, &ddata, &dspeed, metric);
- printf ("done. %.2f %s in %.2f secs: ", ddata, metric, secs);
- printf ("%.2f %s/sec\n", dspeed, metric);
-
- return 0;
-}
int encrypt_data_ncr_direct(int cfd, int algo, int chunksize)
{
@@ -322,12 +221,6 @@ int main(void)
break;
}
- fprintf(stderr, "\nTesting NCR with NULL cipher: \n");
- for (i = 256; i <= (64 * 1024); i *= 2) {
- if (encrypt_data_ncr(fdc, NCR_ALG_NULL, i))
- break;
- }
-
fprintf(stderr, "\nTesting NCR-DIRECT with NULL cipher: \n");
for (i = 256; i <= (64 * 1024); i *= 2) {
if (encrypt_data_ncr_direct(fdc, NCR_ALG_NULL, i))
@@ -351,12 +244,6 @@ int main(void)
break;
}
- fprintf(stderr, "\nTesting NCR with AES-128-CBC cipher: \n");
- for (i = 256; i <= (64 * 1024); i *= 2) {
- if (encrypt_data_ncr(fdc, NCR_ALG_AES_CBC, i))
- break;
- }
-
fprintf(stderr, "\nTesting NCR-DIRECT with AES-128-CBC cipher: \n");
for (i = 256; i <= (64 * 1024); i *= 2) {
if (encrypt_data_ncr_direct(fdc, NCR_ALG_AES_CBC, i))