summaryrefslogtreecommitdiffstats
path: root/ncr-key-wrap.c
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2010-08-16 16:06:43 +0200
committerMiloslav Trmač <mitr@redhat.com>2010-08-24 23:43:46 +0200
commit3ab6fc7d0d19f62b48ecef310249014192289613 (patch)
tree108739dea2e11cb87bb3790eb785331e4cef2308 /ncr-key-wrap.c
parent9aa6874612bf258f0a9795371db9b3dc514376aa (diff)
downloadkernel-crypto-3ab6fc7d0d19f62b48ecef310249014192289613.tar.gz
kernel-crypto-3ab6fc7d0d19f62b48ecef310249014192289613.tar.xz
kernel-crypto-3ab6fc7d0d19f62b48ecef310249014192289613.zip
Convert *_KEY_WRAP
Diffstat (limited to 'ncr-key-wrap.c')
-rw-r--r--ncr-key-wrap.c55
1 files changed, 34 insertions, 21 deletions
diff --git a/ncr-key-wrap.c b/ncr-key-wrap.c
index c6f394eaac7..1cac811af23 100644
--- a/ncr-key-wrap.c
+++ b/ncr-key-wrap.c
@@ -29,6 +29,7 @@
#include <linux/random.h>
#include <linux/uaccess.h>
#include <linux/scatterlist.h>
+#include <net/netlink.h>
#include "ncr.h"
#include "ncr-int.h"
#include "cryptodev_int.h"
@@ -59,7 +60,7 @@ int i,j;
if (*output_size < (n+1)*8) {
err();
- return -EINVAL;
+ return -ERANGE;
}
memcpy(A, iv, 8);
@@ -502,21 +503,23 @@ int kek_level, wkey_level;
return 0;
}
-int ncr_key_wrap(struct ncr_lists *lst, void __user* arg)
+int ncr_key_wrap(struct ncr_lists *lst, const struct ncr_key_wrap *wrap,
+ struct nlattr *tb[])
{
-struct ncr_key_wrap_st wrap;
+const struct nlattr *nla;
struct key_item_st* wkey = NULL;
struct key_item_st* key = NULL;
void* data = NULL;
-size_t data_size;
+const void *iv;
+size_t data_size, iv_size;
int ret;
- if (unlikely(copy_from_user(&wrap, arg, sizeof(wrap)))) {
+ if (wrap->buffer_size < 0) {
err();
- return -EFAULT;
+ return -EINVAL;
}
- ret = ncr_key_item_get_read( &wkey, lst, wrap.keytowrap);
+ ret = ncr_key_item_get_read(&wkey, lst, wrap->source_key);
if (ret < 0) {
err();
return ret;
@@ -528,7 +531,7 @@ int ret;
goto fail;
}
- ret = ncr_key_item_get_read( &key, lst, wrap.key);
+ ret = ncr_key_item_get_read(&key, lst, wrap->wrapping_key);
if (ret < 0) {
err();
goto fail;
@@ -546,7 +549,7 @@ int ret;
goto fail;
}
- data_size = wrap.io_size;
+ data_size = wrap->buffer_size;
data = kmalloc(data_size, GFP_KERNEL);
if (data == NULL) {
err();
@@ -554,14 +557,29 @@ int ret;
goto fail;
}
- switch(wrap.algorithm) {
+ nla = tb[NCR_ATTR_IV];
+ if (nla != NULL) {
+ iv = nla_data(nla);
+ iv_size = nla_len(nla);
+ } else {
+ iv = NULL;
+ iv_size = 0;
+ }
+
+ nla = tb[NCR_ATTR_WRAPPING_ALGORITHM];
+ if (nla == NULL) {
+ err();
+ ret = -EINVAL;
+ goto fail;
+ }
+ switch (nla_get_u32(nla)) {
case NCR_WALG_AES_RFC3394:
- ret = wrap_aes(wkey, key, data, &data_size,
- wrap.params.params.cipher.iv, wrap.params.params.cipher.iv_size);
+ ret = wrap_aes(wkey, key, data, &data_size, iv,
+ iv_size);
break;
case NCR_WALG_AES_RFC5649:
- ret = wrap_aes_rfc5649(wkey, key, data, &data_size,
- wrap.params.params.cipher.iv, wrap.params.params.cipher.iv_size);
+ ret = wrap_aes_rfc5649(wkey, key, data, &data_size, iv,
+ iv_size);
break;
default:
err();
@@ -573,18 +591,13 @@ int ret;
goto fail;
}
- ret = copy_to_user(wrap.io, data, data_size);
+ ret = copy_to_user(wrap->buffer, data, data_size);
if (unlikely(ret)) {
ret = -EFAULT;
goto fail;
}
- wrap.io_size = data_size;
-
- ret = copy_to_user(arg, &wrap, sizeof(wrap));
- if (unlikely(ret)) {
- ret = -EFAULT;
- }
+ ret = data_size;
fail:
if (wkey != NULL) _ncr_key_item_put(wkey);