From 9188480827a4f4a56daf9e3b0ab72c57fb4c5b3c Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Fri, 7 Jul 2000 17:04:44 +0000 Subject: [PATCH] Handle the hwcrhk private key with a bit more consistency. Also, for the random numbers generator, always return status 1 since the entropy is already presumably there... --- crypto/engine/hw_ncipher.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crypto/engine/hw_ncipher.c b/crypto/engine/hw_ncipher.c index b4d2502ce9..9021c2c453 100644 --- a/crypto/engine/hw_ncipher.c +++ b/crypto/engine/hw_ncipher.c @@ -105,6 +105,7 @@ static int hwcrhk_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p, /* RAND stuff */ static int hwcrhk_rand_bytes(unsigned char *buf, int num); +static int hwcrhk_rand_status(void); /* KM stuff */ static EVP_PKEY *hwcrhk_load_privkey(const char *key_id, @@ -160,7 +161,7 @@ static RAND_METHOD hwcrhk_rand = NULL, NULL, hwcrhk_rand_bytes, - NULL + hwcrhk_rand_status, }; /* Our ENGINE structure. */ @@ -543,7 +544,7 @@ static EVP_PKEY *hwcrhk_load_privkey(const char *key_id, RSA *rtmp = NULL; EVP_PKEY *res = NULL; HWCryptoHook_MPI e, n; - HWCryptoHook_RSAKeyHandle hptr; + HWCryptoHook_RSAKeyHandle *hptr; HWCryptoHook_ErrMsgBuf rmsg; if(!hwcrhk_context) @@ -552,7 +553,8 @@ static EVP_PKEY *hwcrhk_load_privkey(const char *key_id, ENGINE_R_NOT_INITIALISED); goto err; } - if (p_hwcrhk_RSALoadKey(hwcrhk_context, key_id, &hptr, + hptr = OPENSSL_malloc(sizeof(HWCryptoHook_RSAKeyHandle)); + if (p_hwcrhk_RSALoadKey(hwcrhk_context, key_id, hptr, &rmsg, NULL)) { ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY, @@ -560,7 +562,7 @@ static EVP_PKEY *hwcrhk_load_privkey(const char *key_id, ERR_add_error_data(1,rmsg.buf); goto err; } - if (!hptr) + if (!*hptr) { ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY, ENGINE_R_NO_KEY); @@ -573,7 +575,7 @@ static EVP_PKEY *hwcrhk_load_privkey(const char *key_id, rtmp->flags |= RSA_FLAG_EXT_PKEY; MPI2BN(rtmp->e, e); MPI2BN(rtmp->n, n); - if (p_hwcrhk_RSAGetPublicKey(hptr, &n, &e, &rmsg) + if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg) != HWCRYPTOHOOK_ERROR_MPISIZE) { ENGINEerr(ENGINE_F_HWCRHK_LOAD_PUBKEY,ENGINE_R_CHIL_ERROR); @@ -586,7 +588,7 @@ static EVP_PKEY *hwcrhk_load_privkey(const char *key_id, MPI2BN(rtmp->e, e); MPI2BN(rtmp->n, n); - if (p_hwcrhk_RSAGetPublicKey(hptr, &n, &e, &rmsg)) + if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg)) { ENGINEerr(ENGINE_F_HWCRHK_LOAD_PUBKEY, ENGINE_R_CHIL_ERROR); @@ -865,6 +867,11 @@ static int hwcrhk_rand_bytes(unsigned char *buf, int num) return to_return; } +static int hwcrhk_rand_status(void) + { + return 1; + } + /* This cleans up an RSA KM key, called when ex_data is freed */ static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,