summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/ncr.c33
-rw-r--r--examples/pk.c30
-rw-r--r--examples/speed.c3
-rw-r--r--ncr-int.h2
-rw-r--r--ncr-key.c9
-rw-r--r--ncr.c6
-rw-r--r--ncr.h2
7 files changed, 52 insertions, 33 deletions
diff --git a/examples/ncr.c b/examples/ncr.c
index 5169a149e31..8b3320662ea 100644
--- a/examples/ncr.c
+++ b/examples/ncr.c
@@ -51,7 +51,8 @@ test_ncr_key(int cfd)
memcpy(data_bak, data, sizeof(data));
/* convert it to key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
+ key = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key == -1) {
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
@@ -112,7 +113,8 @@ test_ncr_key(int cfd)
fprintf(stdout, "\tKey import...\n");
/* convert it to key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
+ key = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
@@ -162,7 +164,8 @@ test_ncr_key(int cfd)
* try to export it.
*/
fprintf(stdout, "\tKey protection of non-exportable keys...\n");
- if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
+ key = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
@@ -224,7 +227,8 @@ test_ncr_wrap_key(int cfd)
fprintf(stdout, "\tKey Wrap test...\n");
/* convert it to key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
+ key = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key == -1) {
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
@@ -248,7 +252,8 @@ test_ncr_wrap_key(int cfd)
/* convert it to key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &key2)) {
+ key2 = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key2 == -1) {
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
@@ -315,7 +320,8 @@ test_ncr_wrap_key(int cfd)
return 1;
}
- if (ioctl(cfd, NCRIO_KEY_INIT, &key2)) {
+ key2 = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key2 == -1) {
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
@@ -474,7 +480,8 @@ test_ncr_store_wrap_key(int cfd)
fprintf(stdout, "\tKey Storage wrap test...\n");
/* convert it to key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &key2)) {
+ key2 = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key2 == -1) {
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
@@ -520,7 +527,8 @@ test_ncr_store_wrap_key(int cfd)
return 1;
}
- if (ioctl(cfd, NCRIO_KEY_INIT, &key2)) {
+ key2 = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key2 == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
@@ -608,7 +616,8 @@ test_ncr_aes(int cfd)
int data_size;
/* convert it to key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
+ key = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key == -1) {
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
@@ -816,7 +825,8 @@ test_ncr_hash(int cfd)
struct ncr_session_once_op_st nop;
/* convert it to key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
+ key = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key == -1) {
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
@@ -902,7 +912,8 @@ test_ncr_hash_key(int cfd)
const uint8_t *output = (void*)"\xe2\xd7\x2c\x2e\x14\xad\x97\xc8\xd2\xdb\xce\xd8\xb3\x52\x9f\x1c\xb3\x2c\x5c\xec";
/* convert it to key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
+ key = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key == -1) {
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
diff --git a/examples/pk.c b/examples/pk.c
index 032ae9864d9..d2e74a92444 100644
--- a/examples/pk.c
+++ b/examples/pk.c
@@ -346,13 +346,15 @@ struct ncr_key_derivation_params_st kderive;
}
/* generate a DH key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &private1)) {
+ private1 = ioctl(cfd, NCRIO_KEY_INIT);
+ if (private1 == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
- if (ioctl(cfd, NCRIO_KEY_INIT, &public1)) {
+ public1 = ioctl(cfd, NCRIO_KEY_INIT);
+ if (public1 == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
@@ -375,13 +377,15 @@ struct ncr_key_derivation_params_st kderive;
}
/* generate another DH key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &private2)) {
+ private2 = ioctl(cfd, NCRIO_KEY_INIT);
+ if (private2 == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
- if (ioctl(cfd, NCRIO_KEY_INIT, &public2)) {
+ public2 = ioctl(cfd, NCRIO_KEY_INIT);
+ if (public2 == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
@@ -432,7 +436,8 @@ struct ncr_key_derivation_params_st kderive;
y2_size = keydata.idata_size;
/* z1=y1^x2 */
- if (ioctl(cfd, NCRIO_KEY_INIT, &z1)) {
+ z1 = ioctl(cfd, NCRIO_KEY_INIT);
+ if (z1 == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
@@ -453,7 +458,8 @@ struct ncr_key_derivation_params_st kderive;
}
/* z2=y2^x1 */
- if (ioctl(cfd, NCRIO_KEY_INIT, &z2)) {
+ z2 = ioctl(cfd, NCRIO_KEY_INIT);
+ if (z2 == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
@@ -889,13 +895,15 @@ static int test_ncr_rsa(int cfd)
fflush(stdout);
/* convert it to key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &privkey)) {
+ privkey = ioctl(cfd, NCRIO_KEY_INIT);
+ if (privkey == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
- if (ioctl(cfd, NCRIO_KEY_INIT, &pubkey)) {
+ pubkey = ioctl(cfd, NCRIO_KEY_INIT);
+ if (pubkey == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
@@ -1000,13 +1008,15 @@ static int test_ncr_dsa(int cfd)
fflush(stdout);
/* convert it to key */
- if (ioctl(cfd, NCRIO_KEY_INIT, &privkey)) {
+ privkey = ioctl(cfd, NCRIO_KEY_INIT);
+ if (privkey == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
}
- if (ioctl(cfd, NCRIO_KEY_INIT, &pubkey)) {
+ pubkey = ioctl(cfd, NCRIO_KEY_INIT);
+ if (pubkey == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
diff --git a/examples/speed.c b/examples/speed.c
index a46cedbc146..6227cad4b40 100644
--- a/examples/speed.c
+++ b/examples/speed.c
@@ -79,7 +79,8 @@ int encrypt_data_ncr_direct(int cfd, int algo, int chunksize)
struct ncr_key_generate_st kgen;
struct ncr_session_once_op_st nop;
- if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
+ key = ioctl(cfd, NCRIO_KEY_INIT);
+ if (key == -1) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
perror("ioctl(NCRIO_KEY_INIT)");
return 1;
diff --git a/ncr-int.h b/ncr-int.h
index 2a459071a33..06ed48364cb 100644
--- a/ncr-int.h
+++ b/ncr-int.h
@@ -117,7 +117,7 @@ void ncr_key_clear(struct key_item_st* item);
void ncr_key_assign_flags(struct key_item_st* item, unsigned int flags);
/* key handling */
-int ncr_key_init(struct ncr_lists *lst, void __user* arg);
+int ncr_key_init(struct ncr_lists *lst);
int ncr_key_deinit(struct ncr_lists *lst, void __user* arg);
int ncr_key_export(struct ncr_lists *lst, void __user* arg);
int ncr_key_import(struct ncr_lists *lst, void __user* arg);
diff --git a/ncr-key.c b/ncr-key.c
index 95228f22859..f54ef334efb 100644
--- a/ncr-key.c
+++ b/ncr-key.c
@@ -148,7 +148,7 @@ static void _ncr_key_remove(struct ncr_lists *lst, ncr_key_t desc)
_ncr_key_item_put(item);
}
-int ncr_key_init(struct ncr_lists *lst, void __user* arg)
+int ncr_key_init(struct ncr_lists *lst)
{
ncr_key_t desc;
struct key_item_st* key;
@@ -187,12 +187,7 @@ int ncr_key_init(struct ncr_lists *lst, void __user* arg)
desc = key->desc;
mutex_unlock(&lst->key_idr_mutex);
- ret = copy_to_user(arg, &desc, sizeof(desc));
- if (unlikely(ret)) {
- _ncr_key_remove(lst, desc);
- return -EFAULT;
- }
- return ret;
+ return desc;
err_limits:
ncr_limits_remove(current_euid(), task_pid_nr(current), LIMIT_TYPE_KEY);
diff --git a/ncr.c b/ncr.c
index 9549b93a697..ec00b7d9750 100644
--- a/ncr.c
+++ b/ncr.c
@@ -125,8 +125,8 @@ ncr_ioctl(struct ncr_lists *lst, unsigned int cmd, unsigned long arg_)
BUG();
switch (cmd) {
- case NCRIO_KEY_INIT:
- return ncr_key_init(lst, arg);
+ case NCRIO_KEY_INIT:
+ return ncr_key_init(lst);
case NCRIO_KEY_DEINIT:
return ncr_key_deinit(lst, arg);
case NCRIO_KEY_GENERATE:
@@ -173,6 +173,8 @@ ncr_compat_ioctl(struct ncr_lists *lst, unsigned int cmd, unsigned long arg_)
BUG();
switch (cmd) {
+ case NCRIO_KEY_INIT:
+ return ncr_ioctl(lst, cmd, arg_);
default:
return -EINVAL;
}
diff --git a/ncr.h b/ncr.h
index 5819168620c..691a4dab22c 100644
--- a/ncr.h
+++ b/ncr.h
@@ -222,7 +222,7 @@ struct ncr_key_data_st {
ncr_algorithm_t algorithm; /* valid for public/private keys */
};
-#define NCRIO_KEY_INIT _IOW ('c', 204, ncr_key_t)
+#define NCRIO_KEY_INIT _IO('c', 204)
/* generate a secret key */
#define NCRIO_KEY_GENERATE _IOR ('c', 205, struct ncr_key_generate_st)
/* generate a public key pair */