From d750b60952619af570ac4d91cd650ffa6bbe311d Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 24 Jul 2010 04:30:14 +0200 Subject: Only look up the sign_hash algorithm once --- ncr-pk.c | 8 ++------ ncr-pk.h | 2 +- ncr-sessions.c | 4 ++-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/ncr-pk.c b/ncr-pk.c index 0837d4c..bfe575d 100644 --- a/ncr-pk.c +++ b/ncr-pk.c @@ -335,7 +335,7 @@ void ncr_pk_cipher_deinit(struct ncr_pk_ctx* ctx) 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) + struct key_item_st *key, const struct algo_properties_st *sign_hash) { memset(ctx, 0, sizeof(*ctx)); @@ -346,11 +346,7 @@ int ncr_pk_cipher_init(const struct algo_properties_st *algo, ctx->algorithm = algo; ctx->key = key; - ctx->sign_hash = ncr_key_params_get_sign_hash(algo, params); - if (IS_ERR(ctx->sign_hash)) { - err(); - return PTR_ERR(ctx->sign_hash); - } + ctx->sign_hash = sign_hash; switch(algo->algo) { case NCR_ALG_RSA: diff --git a/ncr-pk.h b/ncr-pk.h index 76b8d36..873ee83 100644 --- a/ncr-pk.h +++ b/ncr-pk.h @@ -32,7 +32,7 @@ void ncr_pk_queue_deinit(void); /* encryption/decryption */ 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); + struct key_item_st *key, const struct algo_properties_st *sign_hash); void ncr_pk_cipher_deinit(struct ncr_pk_ctx* ctx); int ncr_pk_cipher_encrypt(const struct ncr_pk_ctx* ctx, const void* input, size_t input_size, void* output, size_t *output_size); diff --git a/ncr-sessions.c b/ncr-sessions.c index 6ecafb9..f768cb3 100644 --- a/ncr-sessions.c +++ b/ncr-sessions.c @@ -259,7 +259,7 @@ 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_pk_cipher_init(ns->algorithm, &ns->pk, - &session->params, ns->key); + &session->params, ns->key, NULL); if (ret < 0) { err(); goto fail; @@ -318,7 +318,7 @@ static int _ncr_session_init(struct ncr_lists* lists, struct ncr_session_st* ses } ret = ncr_pk_cipher_init(ns->algorithm, &ns->pk, - &session->params, ns->key); + &session->params, ns->key, sign_hash); if (ret < 0) { err(); goto fail; -- cgit