From 60e1158295f152cbe0d7d983dfd98d94b73314c1 Mon Sep 17 00:00:00 2001 From: Jan Chadima Date: Mon, 2 Aug 2010 10:56:34 +0200 Subject: Initial userspace library version --- userspace/ncrypto_params.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 userspace/ncrypto_params.c (limited to 'userspace/ncrypto_params.c') diff --git a/userspace/ncrypto_params.c b/userspace/ncrypto_params.c new file mode 100644 index 0000000..c6b9002 --- /dev/null +++ b/userspace/ncrypto_params.c @@ -0,0 +1,50 @@ + +#include +#include +#include +#include +#include "../ncr.h" +#include "ncrypto.h" + +int +ncr_key_params_init(ncr_key_params_t *params) +{ + ncr_key_params_t rv; + + if (!params) { + errno = EINVAL; + return -1; + } + if (!(rv = calloc(1, sizeof(*rv)))) { + errno = ENOMEM; + return -1; + } + *params = rv; + return 0; +} + +void +ncr_key_params_deinit(ncr_key_params_t params) +{ + if (params) + free(params); +} + +int +ncr_key_params_set_cipher_iv(ncr_key_params_t params, void* iv, unsigned int iv_size) +{ + if (!params || (iv_size > NCR_CIPHER_MAX_BLOCK_LEN)) { + errno = EINVAL; + return -1; + } + memmove(params->params.cipher.iv, iv, iv_size); + params->params.cipher.iv_size = iv_size; + return 0; +} + +int +ncr_key_params_set_dh_key(ncr_key_params_t params, ncr_key_t dh_priv) +{ + errno = EINVAL; +} + -- cgit From 377e8e5dca01fa1a572ca1a84aee817279a86f9c Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Mon, 2 Aug 2010 11:00:22 +0200 Subject: Add missing "return"; --- userspace/ncrypto_params.c | 1 + 1 file changed, 1 insertion(+) (limited to 'userspace/ncrypto_params.c') diff --git a/userspace/ncrypto_params.c b/userspace/ncrypto_params.c index c6b9002..0bbe0df 100644 --- a/userspace/ncrypto_params.c +++ b/userspace/ncrypto_params.c @@ -46,5 +46,6 @@ int ncr_key_params_set_dh_key(ncr_key_params_t params, ncr_key_t dh_priv) { errno = EINVAL; + return -1; } -- cgit From 7f0366558145a1bcdd5e877d7e5e25e246e01a37 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Fri, 6 Aug 2010 01:25:17 +0200 Subject: Use EOVERFLOW if input data is too large --- userspace/ncrypto_params.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'userspace/ncrypto_params.c') diff --git a/userspace/ncrypto_params.c b/userspace/ncrypto_params.c index 0bbe0df..d365432 100644 --- a/userspace/ncrypto_params.c +++ b/userspace/ncrypto_params.c @@ -33,10 +33,14 @@ ncr_key_params_deinit(ncr_key_params_t params) int ncr_key_params_set_cipher_iv(ncr_key_params_t params, void* iv, unsigned int iv_size) { - if (!params || (iv_size > NCR_CIPHER_MAX_BLOCK_LEN)) { + if (!params) { errno = EINVAL; return -1; } + if (iv_size > NCR_CIPHER_MAX_BLOCK_LEN) { + errno = EOVERFLOW; + return -1; + } memmove(params->params.cipher.iv, iv, iv_size); params->params.cipher.iv_size = iv_size; return 0; -- cgit From 8776b83f4f8301b944fd2d511ca7ee4c09d318ab Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Fri, 6 Aug 2010 01:55:25 +0200 Subject: Implement DH key params New function ncr_key_params_set_dh_pub(), replacing ncr_key_params_set_dh_key(). --- userspace/ncrypto_params.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'userspace/ncrypto_params.c') diff --git a/userspace/ncrypto_params.c b/userspace/ncrypto_params.c index d365432..253664b 100644 --- a/userspace/ncrypto_params.c +++ b/userspace/ncrypto_params.c @@ -47,9 +47,14 @@ ncr_key_params_set_cipher_iv(ncr_key_params_t params, void* iv, unsigned int iv_ } int -ncr_key_params_set_dh_key(ncr_key_params_t params, ncr_key_t dh_priv) +ncr_key_params_set_dh_pub(ncr_key_params_t params, void *pub, size_t pub_size) { - errno = EINVAL; - return -1; + if (!params || !pub || !pub_size) { + errno = EINVAL; + return -1; + } + params->params.dh.pub = pub; + params->params.dh.pub_size = pub_size; + return 0; } -- cgit From 18e1c9aa347e5cf8f6d28820d27c7e3083a24e38 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Fri, 6 Aug 2010 02:21:53 +0200 Subject: Add remaining accessors for ncr_key_params_t --- userspace/ncrypto_params.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'userspace/ncrypto_params.c') diff --git a/userspace/ncrypto_params.c b/userspace/ncrypto_params.c index 253664b..f5385f4 100644 --- a/userspace/ncrypto_params.c +++ b/userspace/ncrypto_params.c @@ -58,3 +58,61 @@ ncr_key_params_set_dh_pub(ncr_key_params_t params, void *pub, size_t pub_size) return 0; } +int +ncr_key_params_set_rsa_type(ncr_key_params_t params, ncr_rsa_type_t type) +{ + if (!params) { + errno = EINVAL; + return -1; + } + params->params.rsa.type = type; + return 0; +} + +int +ncr_key_params_set_rsa_oaep_hash(ncr_key_params_t params, + ncr_algorithm_t oaep_hash) +{ + if (!params) { + errno = EINVAL; + return -1; + } + params->params.rsa.oaep_hash = oaep_hash; + return 0; +} + +int +ncr_key_params_set_rsa_sign_hash(ncr_key_params_t params, + ncr_algorithm_t sign_hash) +{ + if (!params) { + errno = EINVAL; + return -1; + } + params->params.rsa.sign_hash = sign_hash; + return 0; +} + +int +ncr_key_params_set_rsa_pss_salt(ncr_key_params_t params, unsigned int pss_salt) +{ + if (!params) { + errno = EINVAL; + return -1; + } + params->params.rsa.pss_salt = pss_salt; + return 0; +} + +int +ncr_key_params_set_dsa_sign_hash(ncr_key_params_t params, + ncr_algorithm_t sign_hash) +{ + if (!params) { + errno = EINVAL; + return -1; + } + params->params.dsa.sign_hash = sign_hash; + return 0; +} + -- cgit From 6e6fafa6663724240e202ee95908b476e7443075 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 7 Aug 2010 07:14:40 +0200 Subject: Abstract from users Let users #include this header file alone, without caring about . To do so, set up a temporary copy of ncr.h so that the #include works at build time as well. --- userspace/ncrypto_params.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'userspace/ncrypto_params.c') diff --git a/userspace/ncrypto_params.c b/userspace/ncrypto_params.c index f5385f4..6fb49f2 100644 --- a/userspace/ncrypto_params.c +++ b/userspace/ncrypto_params.c @@ -3,7 +3,7 @@ #include #include #include -#include "../ncr.h" +#include #include "ncrypto.h" int -- cgit From bd0b751d6e7ce55369327740c0663b698cdbbe90 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 21 Aug 2010 10:41:05 +0200 Subject: Add Red Hat copyright notices to libcryptodev --- userspace/ncrypto_params.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'userspace/ncrypto_params.c') diff --git a/userspace/ncrypto_params.c b/userspace/ncrypto_params.c index 6fb49f2..7a4936d 100644 --- a/userspace/ncrypto_params.c +++ b/userspace/ncrypto_params.c @@ -1,3 +1,31 @@ +/* + * Copyright 2010 Red Hat, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY RED HAT, INC. AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL RED HAT, INC. OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * Red Hat authors: Jan Chadima + * Miloslav Trmač #include -- cgit