summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2010-08-13 19:17:16 +0200
committerMiloslav Trmač <mitr@redhat.com>2010-08-24 22:59:22 +0200
commit827e65e77c32da30ce675e8e7c05de73d9aeab5a (patch)
treefd0eeb20b7eecb859756abdc4941fab3cb0ca4ae /examples
parent7c70b1f992d02daa3c5d435355ac7875a6b1b95b (diff)
downloadcryptodev-linux-827e65e77c32da30ce675e8e7c05de73d9aeab5a.tar.gz
cryptodev-linux-827e65e77c32da30ce675e8e7c05de73d9aeab5a.tar.xz
cryptodev-linux-827e65e77c32da30ce675e8e7c05de73d9aeab5a.zip
Convert *_KEY_EXPORT
Diffstat (limited to 'examples')
-rw-r--r--examples/ncr.c61
-rw-r--r--examples/pk.c113
2 files changed, 82 insertions, 92 deletions
diff --git a/examples/ncr.c b/examples/ncr.c
index b999003..2c2ca7c 100644
--- a/examples/ncr.c
+++ b/examples/ncr.c
@@ -58,6 +58,7 @@ test_ncr_key(int cfd)
struct nlattr *nla;
ncr_key_t key;
struct ncr_key_data_st keydata;
+ struct ncr_key_export kexport;
uint8_t data[KEY_DATA_SIZE];
uint8_t data_bak[KEY_DATA_SIZE];
uint16_t *attr_p;
@@ -101,20 +102,14 @@ test_ncr_key(int cfd)
/* now try to read it */
fprintf(stdout, "\tKey export...\n");
- memset(&keydata, 0, sizeof(keydata));
- keydata.key = key;
- keydata.idata = data;
- keydata.idata_size = sizeof(data);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = key;
+ kexport.buffer = data;
+ kexport.buffer_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;
- }
-
- if (keydata.idata_size != sizeof(data)) {
+ if (ioctl(cfd, NCRIO_KEY_EXPORT, &kexport) != sizeof(data)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- fprintf(stderr, "data returned but differ!\n");
+ perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
@@ -165,18 +160,18 @@ test_ncr_key(int cfd)
memset(data, 0, sizeof(data));
- memset(&keydata, 0, sizeof(keydata));
- keydata.key = key;
- keydata.idata = data;
- keydata.idata_size = sizeof(data);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = key;
+ kexport.buffer = data;
+ kexport.buffer_size = sizeof(data);
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
+ if (ioctl(cfd, NCRIO_KEY_EXPORT, &kexport) != sizeof(data)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_KEY_IMPORT)");
+ perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
- if (keydata.idata_size == 0 || (data[0] == 0 && data[1] == 0 && data[2] == 0 && data[4] == 0)) {
+ if (data[0] == 0 && data[1] == 0 && data[2] == 0 && data[4] == 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
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],
@@ -296,14 +291,14 @@ test_ncr_key(int cfd)
memset(data, 0, sizeof(data));
- memset(&keydata, 0, sizeof(keydata));
- keydata.key = key;
- keydata.idata = data;
- keydata.idata_size = sizeof(data);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = key;
+ kexport.buffer = data;
+ kexport.buffer_size = sizeof(data);
/* try to get the output data - should fail */
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)==0) {
+ if (ioctl(cfd, NCRIO_KEY_EXPORT, &kexport) >= 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
fprintf(stderr, "Data were exported, but shouldn't be!\n");
return 1;
@@ -580,6 +575,7 @@ test_ncr_store_wrap_key(int cfd)
int i;
ncr_key_t key2;
struct ncr_key_data_st keydata;
+ struct ncr_key_export kexport;
struct ncr_key_storage_wrap_st kwrap;
uint8_t data[DATA_SIZE];
int data_size;
@@ -659,20 +655,19 @@ test_ncr_store_wrap_key(int cfd)
}
/* now export the unwrapped */
- memset(&keydata, 0, sizeof(keydata));
- keydata.key = key2;
- keydata.idata = data;
- keydata.idata_size = sizeof(data);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = key2;
+ kexport.buffer = data;
+ kexport.buffer_size = sizeof(data);
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
+ data_size = ioctl(cfd, NCRIO_KEY_EXPORT, &kexport);
+ if (data_size != 16) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_KEY_IMPORT)");
+ perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
-
- data_size = keydata.idata_size;
- if (data_size != 16 || memcmp(data, DKEY, 16) != 0) {
+ if (memcmp(data, DKEY, 16) != 0) {
fprintf(stderr, "Unwrapped data do not match.\n");
fprintf(stderr, "Data[%d]: ", (int) data_size);
for(i=0;i<data_size;i++)
diff --git a/examples/pk.c b/examples/pk.c
index 8437322..862eb8c 100644
--- a/examples/pk.c
+++ b/examples/pk.c
@@ -327,8 +327,8 @@ int ret;
gnutls_datum g, p, params;
gnutls_dh_params_t dhp;
unsigned char y1[1024], y2[1024];
-size_t y1_size, y2_size;
-struct ncr_key_data_st keydata;
+ssize_t y1_size, y2_size;
+struct ncr_key_export kexport;
struct __attribute__((packed)) {
struct ncr_key_derive f;
struct nlattr algo_head ALIGN_NL;
@@ -451,33 +451,31 @@ struct __attribute__((packed)) {
}
/* export y1=g^x1 */
- memset(&keydata, 0, sizeof(keydata));
- keydata.key = public1;
- keydata.idata = y1;
- keydata.idata_size = sizeof(y1);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = public1;
+ kexport.buffer = y1;
+ kexport.buffer_size = sizeof(y1);
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
+ y1_size = ioctl(cfd, NCRIO_KEY_EXPORT, &kexport);
+ if (y1_size < 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
-
- y1_size = keydata.idata_size;
/* export y2=g^x2 */
- memset(&keydata, 0, sizeof(keydata));
- keydata.key = public2;
- keydata.idata = y2;
- keydata.idata_size = sizeof(y2);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = public2;
+ kexport.buffer = y2;
+ kexport.buffer_size = sizeof(y2);
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
+ y2_size = ioctl(cfd, NCRIO_KEY_EXPORT, &kexport);
+ if (y2_size < 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
- y2_size = keydata.idata_size;
-
/* z1=y1^x2 */
z1 = ioctl(cfd, NCRIO_KEY_INIT);
if (z1 == -1) {
@@ -541,29 +539,29 @@ struct __attribute__((packed)) {
}
/* z1==z2 */
- memset(&keydata, 0, sizeof(keydata));
- keydata.key = z1;
- keydata.idata = y1;
- keydata.idata_size = sizeof(y1);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = z1;
+ kexport.buffer = y1;
+ kexport.buffer_size = sizeof(y1);
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
+ y1_size = ioctl(cfd, NCRIO_KEY_EXPORT, &kexport);
+ if (y1_size < 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
- y1_size = keydata.idata_size;
- memset(&keydata, 0, sizeof(keydata));
- keydata.key = z2;
- keydata.idata = y2;
- keydata.idata_size = sizeof(y2);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = z2;
+ kexport.buffer = y2;
+ kexport.buffer_size = sizeof(y2);
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
+ y2_size = ioctl(cfd, NCRIO_KEY_EXPORT, &kexport);
+ if (y2_size < 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
- y2_size = keydata.idata_size;
if (y1_size == 0 || y1_size != y2_size || memcmp(y1, y2, y1_size) != 0) {
int i;
@@ -971,7 +969,7 @@ static int test_ncr_rsa(int cfd)
uint32_t bits ALIGN_NL;
} kgen;
ncr_key_t pubkey, privkey;
- struct ncr_key_data_st keydata;
+ struct ncr_key_export kexport;
uint8_t data[DATA_SIZE];
int data_size;
@@ -1015,18 +1013,17 @@ static int test_ncr_rsa(int cfd)
/* export the private key */
memset(data, 0, sizeof(data));
- memset(&keydata, 0, sizeof(keydata));
- keydata.key = privkey;
- keydata.idata = data;
- keydata.idata_size = sizeof(data);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = privkey;
+ kexport.buffer = data;
+ kexport.buffer_size = sizeof(data);
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
+ data_size = ioctl(cfd, NCRIO_KEY_EXPORT, &kexport);
+ if (data_size < 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
-
- data_size = keydata.idata_size;
ret = privkey_info(data, data_size, 0);
if (ret != 0) {
@@ -1037,18 +1034,17 @@ 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.idata = data;
- keydata.idata_size = sizeof(data);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = pubkey;
+ kexport.buffer = data;
+ kexport.buffer_size = sizeof(data);
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
+ data_size = ioctl(cfd, NCRIO_KEY_EXPORT, &kexport);
+ if (data_size < 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_KEY_IMPORT)");
+ perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
-
- data_size = keydata.idata_size;
ret = pubkey_info(data, data_size, 0);
if (ret != 0) {
@@ -1101,7 +1097,7 @@ static int test_ncr_dsa(int cfd)
uint32_t p_bits ALIGN_NL;
} kgen;
ncr_key_t pubkey, privkey;
- struct ncr_key_data_st keydata;
+ struct ncr_key_export kexport;
uint8_t data[DATA_SIZE];
int data_size;
@@ -1146,18 +1142,18 @@ static int test_ncr_dsa(int cfd)
return 1;
}
- memset(&keydata, 0, sizeof(keydata));
memset(data, 0, sizeof(data));
- keydata.key = privkey;
- keydata.idata = data;
- keydata.idata_size = sizeof(data);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = privkey;
+ kexport.buffer = data;
+ kexport.buffer_size = sizeof(data);
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
+ data_size = ioctl(cfd, NCRIO_KEY_EXPORT, &kexport);
+ if (data_size < 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
- data_size = keydata.idata_size;
ret = privkey_info(data, data_size, 0);
if (ret != 0) {
@@ -1168,18 +1164,17 @@ 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.idata = data;
- keydata.idata_size = sizeof(data);
+ memset(&kexport, 0, sizeof(kexport));
+ kexport.key = pubkey;
+ kexport.buffer = data;
+ kexport.buffer_size = sizeof(data);
- if (ioctl(cfd, NCRIO_KEY_EXPORT, &keydata)) {
+ data_size = ioctl(cfd, NCRIO_KEY_EXPORT, &kexport);
+ if (data_size < 0) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_KEY_IMPORT)");
+ perror("ioctl(NCRIO_KEY_EXPORT)");
return 1;
}
-
- data_size = keydata.idata_size;
ret = pubkey_info(data, data_size, 0);
if (ret != 0) {