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_generate_params.c | 98 +++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 userspace/ncrypto_generate_params.c (limited to 'userspace/ncrypto_generate_params.c') diff --git a/userspace/ncrypto_generate_params.c b/userspace/ncrypto_generate_params.c new file mode 100644 index 0000000..67171c3 --- /dev/null +++ b/userspace/ncrypto_generate_params.c @@ -0,0 +1,98 @@ + +#include +#include +#include +#include "../ncr.h" +#include "ncrypto.h" + +int +ncr_key_generate_params_init(ncr_key_generate_params_t *params) +{ + ncr_key_generate_params_t rv; + + if (!params) { + errno = EINVAL; + return -1; + } + + if (!(rv = calloc(1, sizeof(*rv)))) { + errno = ENOMEM; + return -1; + } + + rv->algorithm = NCR_ALG_NONE; + *params = rv; + + return 0; +} + +int +ncr_key_generate_params_deinit(ncr_key_generate_params_t params) +{ + if (params) + free(params); + + return 0; +} + +int +ncr_key_generate_params_set_algorithm(ncr_key_generate_params_t params, ncr_algorithm_t algorithm) +{ + if (!params) { + errno = EINVAL; + return -1; + } + + params->algorithm = algorithm; + + return 0; +} + +int +ncr_key_generate_params_set_keyflags(ncr_key_generate_params_t params, unsigned int keyflags) +{ + if (!params) { + errno = EINVAL; + return -1; + } + + params->keyflags = keyflags; + + return 0; +} + +int +ncr_key_generate_params_set_bits(ncr_key_generate_params_t params, unsigned int bits) +{ + if (!params) { + errno = EINVAL; + return -1; + } + params->params.secret.bits = bits; + + return 0; +} + +int +ncr_key_generate_params_set_rsa_e(ncr_key_generate_params_t params, void *e, size_t e_size) +{ + errno = ENOTSUP; + return -1; +} + +int +ncr_key_generate_params_set_dh(ncr_key_generate_params_t params, void *p, size_t p_size, void *g, size_t g_size) +{ + if (!params) { + errno = EINVAL; + return -1; + } + + params->params.dh.p = p; + params->params.dh.p_size = p_size; + params->params.dh.g = g; + params->params.dh.g_size = g_size; + + return 0; +} + -- cgit From 3bbecb0f648f3f831523e23f02a81e3e2cd5feac Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Fri, 6 Aug 2010 01:44:51 +0200 Subject: Implement missing algorithm-specific keygen params Rename ncr_key_generate_params_set_bits to ncr_key_generate_params_set_secret_bits in the process, an incompatible change. --- userspace/ncrypto_generate_params.c | 62 ++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) (limited to 'userspace/ncrypto_generate_params.c') diff --git a/userspace/ncrypto_generate_params.c b/userspace/ncrypto_generate_params.c index 67171c3..5772aaf 100644 --- a/userspace/ncrypto_generate_params.c +++ b/userspace/ncrypto_generate_params.c @@ -1,4 +1,4 @@ - +#include #include #include #include @@ -62,7 +62,7 @@ ncr_key_generate_params_set_keyflags(ncr_key_generate_params_t params, unsigned } int -ncr_key_generate_params_set_bits(ncr_key_generate_params_t params, unsigned int bits) +ncr_key_generate_params_set_secret_bits(ncr_key_generate_params_t params, unsigned int bits) { if (!params) { errno = EINVAL; @@ -73,11 +73,65 @@ ncr_key_generate_params_set_bits(ncr_key_generate_params_t params, unsigned int return 0; } +int +ncr_key_generate_params_set_rsa_bits(ncr_key_generate_params_t params, unsigned int bits) +{ + if (!params) { + errno = EINVAL; + return -1; + } + params->params.rsa.bits = bits; + + return 0; +} + int ncr_key_generate_params_set_rsa_e(ncr_key_generate_params_t params, void *e, size_t e_size) { - errno = ENOTSUP; - return -1; + unsigned long value; + const uint8_t *p; + + if (!params || !e) { + errno = EINVAL; + return -1; + } + value = 0; + for (p = e; p < (const uint8_t *)e + e_size; p++) { + if (value > (ULONG_MAX - *p) / 256) { + errno = EOVERFLOW; + return -1; + } + value = value * 256 + *p; + } + + params->params.rsa.e = value; + return 0; +} + +int +ncr_key_generate_params_set_dsa_p_bits(ncr_key_generate_params_t params, + unsigned int p_bits) +{ + if (!params) { + errno = EINVAL; + return -1; + } + params->params.dsa.p_bits = p_bits; + + return 0; +} + +int +ncr_key_generate_params_set_dsa_q_bits(ncr_key_generate_params_t params, + unsigned int q_bits) +{ + if (!params) { + errno = EINVAL; + return -1; + } + params->params.dsa.q_bits = q_bits; + + return 0; } int -- 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_generate_params.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'userspace/ncrypto_generate_params.c') diff --git a/userspace/ncrypto_generate_params.c b/userspace/ncrypto_generate_params.c index 5772aaf..9dd901d 100644 --- a/userspace/ncrypto_generate_params.c +++ b/userspace/ncrypto_generate_params.c @@ -2,7 +2,7 @@ #include #include #include -#include "../ncr.h" +#include #include "ncrypto.h" int -- cgit From aac00a3bf423f77344f62d129ef0050fea711756 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sun, 8 Aug 2010 02:16:07 +0200 Subject: Don't assume includes --- userspace/ncrypto_generate_params.c | 1 + 1 file changed, 1 insertion(+) (limited to 'userspace/ncrypto_generate_params.c') diff --git a/userspace/ncrypto_generate_params.c b/userspace/ncrypto_generate_params.c index 9dd901d..1034a9c 100644 --- a/userspace/ncrypto_generate_params.c +++ b/userspace/ncrypto_generate_params.c @@ -1,4 +1,5 @@ #include +#include #include #include #include -- 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_generate_params.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'userspace/ncrypto_generate_params.c') diff --git a/userspace/ncrypto_generate_params.c b/userspace/ncrypto_generate_params.c index 1034a9c..a993360 100644 --- a/userspace/ncrypto_generate_params.c +++ b/userspace/ncrypto_generate_params.c @@ -1,3 +1,32 @@ +/* + * 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 #include -- cgit