summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ncr-pk.c24
-rw-r--r--ncr-sessions.c13
-rw-r--r--ncr_int.h2
3 files changed, 20 insertions, 19 deletions
diff --git a/ncr-pk.c b/ncr-pk.c
index 9ab5732..09dd242 100644
--- a/ncr-pk.c
+++ b/ncr-pk.c
@@ -305,16 +305,21 @@ void ncr_pk_queue_deinit(void)
destroy_workqueue(pk_wq);
}
-int ncr_key_params_get_sign_hash(ncr_algorithm_t algo, struct ncr_key_params_st * params)
+const struct algo_properties_st *ncr_key_params_get_sign_hash(const struct algo_properties_st *algo, struct ncr_key_params_st * params)
{
- switch(algo) {
+ ncr_algorithm_t id;
+
+ switch(algo->algo) {
case NCR_ALG_RSA:
- return params->params.rsa.sign_hash;
+ id = params->params.rsa.sign_hash;
+ break;
case NCR_ALG_DSA:
- return params->params.dsa.sign_hash;
+ id = params->params.dsa.sign_hash;
+ break;
default:
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
+ return _ncr_algo_to_properties(id);
}
/* Encryption/Decryption
@@ -332,8 +337,6 @@ int ncr_pk_cipher_init(const struct algo_properties_st *algo,
struct ncr_pk_ctx* ctx, struct ncr_key_params_st* params,
struct key_item_st *key)
{
-int ret;
-
memset(ctx, 0, sizeof(*ctx));
if (key->algorithm != algo) {
@@ -343,12 +346,11 @@ int ret;
ctx->algorithm = algo;
ctx->key = key;
- ret = ncr_key_params_get_sign_hash(algo->algo, params);
- if (ret < 0) {
+ ctx->sign_hash = ncr_key_params_get_sign_hash(algo, params);
+ if (IS_ERR(ctx->sign_hash)) {
err();
- return ret;
+ return PTR_ERR(ctx->sign_hash);
}
- ctx->sign_hash = _ncr_algo_to_properties(ret);
switch(algo->algo) {
case NCR_ALG_RSA:
diff --git a/ncr-sessions.c b/ncr-sessions.c
index 6f26e43..dfc8976 100644
--- a/ncr-sessions.c
+++ b/ncr-sessions.c
@@ -286,7 +286,7 @@ static int _ncr_session_init(struct ncr_lists* lists, struct ncr_session_st* ses
{
struct session_item_st* ns = NULL;
int ret;
- ncr_algorithm_t sign_hash;
+ const struct algo_properties_st *sign_hash;
const char* str = NULL;
ns = ncr_session_new(&lists->sessions);
@@ -388,19 +388,18 @@ static int _ncr_session_init(struct ncr_lists* lists, struct ncr_session_st* ses
}
} else if (ns->key->type == NCR_KEY_TYPE_PRIVATE || ns->key->type == NCR_KEY_TYPE_PUBLIC) {
- ret = ncr_key_params_get_sign_hash(ns->key->algorithm->algo, &session->params);
- if (ret < 0) {
+ sign_hash = ncr_key_params_get_sign_hash(ns->key->algorithm, &session->params);
+ if (IS_ERR(sign_hash)) {
err();
- return ret;
+ return PTR_ERR(sign_hash);
}
- sign_hash = ret;
- if (algo_can_digest(sign_hash) == 0) {
+ if (algo_can_digest(sign_hash->algo) == 0) {
err();
ret = -EINVAL;
goto fail;
}
- str = _ncr_algo_to_str(sign_hash);
+ str = _ncr_algo_to_str(sign_hash->algo);
if (str == NULL) {
err();
ret = -EINVAL;
diff --git a/ncr_int.h b/ncr_int.h
index 720fd52..fc6e0c6 100644
--- a/ncr_int.h
+++ b/ncr_int.h
@@ -208,6 +208,6 @@ inline static unsigned int data_flags_to_key(unsigned int data_flags)
const struct algo_properties_st *_ncr_algo_to_properties(ncr_algorithm_t algo);
const char* _ncr_algo_to_str(ncr_algorithm_t algo);
int _ncr_algo_digest_size(ncr_algorithm_t algo);
-int ncr_key_params_get_sign_hash(ncr_algorithm_t algo, struct ncr_key_params_st * params);
+const struct algo_properties_st *ncr_key_params_get_sign_hash(const struct algo_properties_st *algo, struct ncr_key_params_st * params);
#endif