summaryrefslogtreecommitdiffstats
path: root/crypto/userspace/ncr-sessions.c
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2010-07-27 18:04:50 +0200
committerMiloslav Trmač <mitr@redhat.com>2010-07-27 18:04:50 +0200
commite6b93d8a7e1d3d4a3d76312fc84319ff6d596067 (patch)
treeeb79baf203de7e9574cc52ff0536478392c3dd4c /crypto/userspace/ncr-sessions.c
parent7cc28b8bafe112037edae18ea0e590e7c9d074fa (diff)
parentd5c2b894102e59efe499c231a32065afcf37e463 (diff)
downloadkernel-crypto-e6b93d8a7e1d3d4a3d76312fc84319ff6d596067.tar.gz
kernel-crypto-e6b93d8a7e1d3d4a3d76312fc84319ff6d596067.tar.xz
kernel-crypto-e6b93d8a7e1d3d4a3d76312fc84319ff6d596067.zip
Merge branch 'standalone-rename' into userspace-crypto
Conflicts: crypto/userspace/Makefile
Diffstat (limited to 'crypto/userspace/ncr-sessions.c')
-rw-r--r--crypto/userspace/ncr-sessions.c118
1 files changed, 60 insertions, 58 deletions
diff --git a/crypto/userspace/ncr-sessions.c b/crypto/userspace/ncr-sessions.c
index 42a352ca62b..ff19bad08fd 100644
--- a/crypto/userspace/ncr-sessions.c
+++ b/crypto/userspace/ncr-sessions.c
@@ -1,22 +1,26 @@
/*
* New driver for /dev/crypto device (aka CryptoDev)
- * Copyright (c) 2010 Nikos Mavrogiannopoulos <nmav@gnutls.org>
+ * Copyright (c) 2010 Katholieke Universiteit Leuven
+ * Portions Copyright (c) 2010 Phil Sutter
+ *
+ * Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
*
* This file is part of linux cryptodev.
*
- * cryptodev is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * cryptodev is distributed in the hope that it will be useful,
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <linux/crypto.h>
@@ -197,6 +201,8 @@ static const struct algo_properties_st algo_properties[] = {
.can_encrypt=1, .can_sign=1, .key_type = NCR_KEY_TYPE_PUBLIC },
{ .algo = NCR_ALG_DSA, .kstr = NULL, .is_pk = 1,
.can_sign=1, .key_type = NCR_KEY_TYPE_PUBLIC },
+ { .algo = NCR_ALG_DH, .kstr = NULL, .is_pk = 1,
+ .can_kx=1, .key_type = NCR_KEY_TYPE_PUBLIC },
{ .algo = NCR_ALG_NONE }
};
@@ -413,7 +419,7 @@ int ncr_session_init(struct ncr_lists* lists, void __user* arg)
return ret;
}
-int _ncr_session_encrypt(struct session_item_st* sess, const struct scatterlist* input, unsigned input_cnt,
+static int _ncr_session_encrypt(struct session_item_st* sess, const struct scatterlist* input, unsigned input_cnt,
size_t input_size, void *output, unsigned output_cnt, size_t *output_size)
{
int ret;
@@ -427,7 +433,7 @@ int ret;
return ret;
}
/* FIXME: handle ciphers that do not require that */
-
+ *output_size = input_size;
} else { /* public key */
ret = ncr_pk_cipher_encrypt(&sess->pk, input, input_cnt, input_size,
output, output_cnt, output_size);
@@ -441,7 +447,7 @@ int ret;
return 0;
}
-int _ncr_session_decrypt(struct session_item_st* sess, const struct scatterlist* input,
+static int _ncr_session_decrypt(struct session_item_st* sess, const struct scatterlist* input,
unsigned input_cnt, size_t input_size,
struct scatterlist *output, unsigned output_cnt, size_t *output_size)
{
@@ -456,7 +462,7 @@ int ret;
return ret;
}
/* FIXME: handle ciphers that do not require equality */
-
+ *output_size = input_size;
} else { /* public key */
ret = ncr_pk_cipher_decrypt(&sess->pk, input, input_cnt, input_size,
output, output_cnt, output_size);
@@ -470,7 +476,7 @@ int ret;
return 0;
}
-void _ncr_session_remove(struct list_sem_st* lst, ncr_session_t desc)
+static void _ncr_session_remove(struct list_sem_st* lst, ncr_session_t desc)
{
struct session_item_st * item, *tmp;
@@ -489,6 +495,36 @@ void _ncr_session_remove(struct list_sem_st* lst, ncr_session_t desc)
return;
}
+static int _ncr_session_grow_pages(struct session_item_st *ses, int pagecount)
+{
+ struct scatterlist *sg;
+ struct page **pages;
+ int array_size;
+
+ if (likely(pagecount < ses->array_size))
+ return 0;
+
+ for (array_size = ses->array_size; array_size < pagecount;
+ array_size *= 2)
+ ;
+
+ dprintk(2, KERN_DEBUG, "%s: reallocating to %d elements\n",
+ __func__, array_size);
+ pages = krealloc(ses->pages, array_size * sizeof(struct page *),
+ GFP_KERNEL);
+ if (unlikely(pages == NULL))
+ return -ENOMEM;
+ ses->pages = pages;
+ sg = krealloc(ses->sg, array_size * sizeof(struct scatterlist),
+ GFP_KERNEL);
+ if (unlikely(sg == NULL))
+ return -ENOMEM;
+ ses->sg = sg;
+
+ ses->array_size = array_size;
+ return 0;
+}
+
/* Only the output buffer is given as scatterlist */
static int get_userbuf1(struct session_item_st* ses,
void __user * udata, size_t udata_size, struct scatterlist **dst_sg, unsigned *dst_cnt)
@@ -500,28 +536,8 @@ static int get_userbuf1(struct session_item_st* ses,
return -EINVAL;
}
- if (unlikely(ses->sg == NULL || ses->pages == NULL)) {
- err();
- return -ENOMEM;
- }
-
pagecount = PAGECOUNT(udata, udata_size);
-
- if (pagecount > ses->array_size) {
- while (ses->array_size < pagecount)
- ses->array_size *= 2;
-
- dprintk(2, KERN_DEBUG, "%s: reallocating to %d elements\n",
- __func__, ses->array_size);
- ses->pages = krealloc(ses->pages, ses->array_size *
- sizeof(struct page *), GFP_KERNEL);
- ses->sg = krealloc(ses->sg, ses->array_size *
- sizeof(struct scatterlist), GFP_KERNEL);
-
- if (unlikely(ses->sg == NULL || ses->pages == NULL)) {
- return -ENOMEM;
- }
- }
+ _ncr_session_grow_pages(ses, pagecount);
if (__get_userbuf(udata, udata_size, 1,
pagecount, ses->pages, ses->sg)) {
@@ -549,11 +565,6 @@ static int get_userbuf2(struct session_item_st* ses,
return -EINVAL;
}
- if (unlikely(ses->sg == NULL || ses->pages == NULL)) {
- err();
- return -ENOMEM;
- }
-
src_pagecount = PAGECOUNT(op->data.udata.input, input_size);
if (op->data.udata.input != op->data.udata.output) { /* non-in-situ transformation */
@@ -570,22 +581,7 @@ static int get_userbuf2(struct session_item_st* ses,
}
pagecount = src_pagecount + dst_pagecount;
-
- if (pagecount > ses->array_size) {
- while (ses->array_size < pagecount)
- ses->array_size *= 2;
-
- dprintk(2, KERN_DEBUG, "%s: reallocating to %d elements\n",
- __func__, ses->array_size);
- ses->pages = krealloc(ses->pages, ses->array_size *
- sizeof(struct page *), GFP_KERNEL);
- ses->sg = krealloc(ses->sg, ses->array_size *
- sizeof(struct scatterlist), GFP_KERNEL);
-
- if (ses->sg == NULL || ses->pages == NULL) {
- return -ENOMEM;
- }
- }
+ _ncr_session_grow_pages(ses, pagecount);
if (__get_userbuf(op->data.udata.input, input_size, write_src,
src_pagecount, ses->pages, ses->sg)) {
@@ -622,7 +618,7 @@ static int get_userbuf2(struct session_item_st* ses,
}
/* Called when userspace buffers are used */
-int _ncr_session_update(struct ncr_lists* lists, struct ncr_session_op_st* op)
+static int _ncr_session_update(struct ncr_lists* lists, struct ncr_session_op_st* op)
{
int ret;
struct session_item_st* sess;
@@ -659,6 +655,12 @@ int _ncr_session_update(struct ncr_lists* lists, struct ncr_session_op_st* op)
goto fail;
}
+ if (osg_size < isg_size) {
+ err();
+ ret = -EINVAL;
+ goto fail;
+ }
+
ret = _ncr_session_encrypt(sess, isg, isg_cnt, isg_size,
osg, osg_cnt, &osg_size);
if (ret < 0) {
@@ -731,7 +733,7 @@ static int try_session_update(struct ncr_lists* lists, struct ncr_session_op_st*
return 0;
}
-int _ncr_session_final(struct ncr_lists* lists, struct ncr_session_op_st* op)
+static int _ncr_session_final(struct ncr_lists* lists, struct ncr_session_op_st* op)
{
int ret;
struct session_item_st* sess;