summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/engine/hw_ncipher.c
diff options
context:
space:
mode:
authormarkus <>2002-09-05 22:45:21 +0000
committermarkus <>2002-09-05 22:45:21 +0000
commit2a6851ef8adb0e84ff2515493d3704a13c6256b0 (patch)
tree9df5b497548eaf51e9f234d27aaf988cd14882c2 /src/lib/libcrypto/engine/hw_ncipher.c
parent5514995a9d5ed91db089875adb509c7781357c0e (diff)
downloadopenbsd-2a6851ef8adb0e84ff2515493d3704a13c6256b0.tar.gz
openbsd-2a6851ef8adb0e84ff2515493d3704a13c6256b0.tar.bz2
openbsd-2a6851ef8adb0e84ff2515493d3704a13c6256b0.zip
import openssl-0.9.7-beta3
Diffstat (limited to 'src/lib/libcrypto/engine/hw_ncipher.c')
-rw-r--r--src/lib/libcrypto/engine/hw_ncipher.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/lib/libcrypto/engine/hw_ncipher.c b/src/lib/libcrypto/engine/hw_ncipher.c
index 4762a54e3d..a43d4360f2 100644
--- a/src/lib/libcrypto/engine/hw_ncipher.c
+++ b/src/lib/libcrypto/engine/hw_ncipher.c
@@ -59,9 +59,9 @@
59 59
60#include <stdio.h> 60#include <stdio.h>
61#include <string.h> 61#include <string.h>
62#include "cryptlib.h"
62#include <openssl/crypto.h> 63#include <openssl/crypto.h>
63#include <openssl/pem.h> 64#include <openssl/pem.h>
64#include "cryptlib.h"
65#include <openssl/dso.h> 65#include <openssl/dso.h>
66#include <openssl/engine.h> 66#include <openssl/engine.h>
67#include <openssl/ui.h> 67#include <openssl/ui.h>
@@ -109,11 +109,13 @@ static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa);
109static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 109static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
110 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); 110 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
111 111
112#ifndef OPENSSL_NO_DH
112/* DH stuff */ 113/* DH stuff */
113/* This function is alised to mod_exp (with the DH and mont dropped). */ 114/* This function is alised to mod_exp (with the DH and mont dropped). */
114static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r, 115static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r,
115 const BIGNUM *a, const BIGNUM *p, 116 const BIGNUM *a, const BIGNUM *p,
116 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); 117 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
118#endif
117 119
118/* RAND stuff */ 120/* RAND stuff */
119static int hwcrhk_rand_bytes(unsigned char *buf, int num); 121static int hwcrhk_rand_bytes(unsigned char *buf, int num);
@@ -422,8 +424,24 @@ static HWCryptoHook_RSAUnloadKey_t *p_hwcrhk_RSAUnloadKey = NULL;
422static HWCryptoHook_ModExpCRT_t *p_hwcrhk_ModExpCRT = NULL; 424static HWCryptoHook_ModExpCRT_t *p_hwcrhk_ModExpCRT = NULL;
423 425
424/* Used in the DSO operations. */ 426/* Used in the DSO operations. */
425static const char def_HWCRHK_LIBNAME[] = "nfhwcrhk"; 427static const char *HWCRHK_LIBNAME = NULL;
426static const char *HWCRHK_LIBNAME = def_HWCRHK_LIBNAME; 428static void free_HWCRHK_LIBNAME(void)
429 {
430 if(HWCRHK_LIBNAME)
431 OPENSSL_free((void*)HWCRHK_LIBNAME);
432 HWCRHK_LIBNAME = NULL;
433 }
434static const char *get_HWCRHK_LIBNAME(void)
435 {
436 if(HWCRHK_LIBNAME)
437 return HWCRHK_LIBNAME;
438 return "nfhwcrhk";
439 }
440static long set_HWCRHK_LIBNAME(const char *name)
441 {
442 free_HWCRHK_LIBNAME();
443 return (((HWCRHK_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
444 }
427static const char *n_hwcrhk_Init = "HWCryptoHook_Init"; 445static const char *n_hwcrhk_Init = "HWCryptoHook_Init";
428static const char *n_hwcrhk_Finish = "HWCryptoHook_Finish"; 446static const char *n_hwcrhk_Finish = "HWCryptoHook_Finish";
429static const char *n_hwcrhk_ModExp = "HWCryptoHook_ModExp"; 447static const char *n_hwcrhk_ModExp = "HWCryptoHook_ModExp";
@@ -469,6 +487,7 @@ static void release_context(HWCryptoHook_ContextHandle hac)
469/* Destructor (complements the "ENGINE_ncipher()" constructor) */ 487/* Destructor (complements the "ENGINE_ncipher()" constructor) */
470static int hwcrhk_destroy(ENGINE *e) 488static int hwcrhk_destroy(ENGINE *e)
471 { 489 {
490 free_HWCRHK_LIBNAME();
472 ERR_unload_HWCRHK_strings(); 491 ERR_unload_HWCRHK_strings();
473 return 1; 492 return 1;
474 } 493 }
@@ -494,7 +513,7 @@ static int hwcrhk_init(ENGINE *e)
494 goto err; 513 goto err;
495 } 514 }
496 /* Attempt to load libnfhwcrhk.so/nfhwcrhk.dll/whatever. */ 515 /* Attempt to load libnfhwcrhk.so/nfhwcrhk.dll/whatever. */
497 hwcrhk_dso = DSO_load(NULL, HWCRHK_LIBNAME, NULL, 0); 516 hwcrhk_dso = DSO_load(NULL, get_HWCRHK_LIBNAME(), NULL, 0);
498 if(hwcrhk_dso == NULL) 517 if(hwcrhk_dso == NULL)
499 { 518 {
500 HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DSO_FAILURE); 519 HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DSO_FAILURE);
@@ -586,6 +605,7 @@ err:
586static int hwcrhk_finish(ENGINE *e) 605static int hwcrhk_finish(ENGINE *e)
587 { 606 {
588 int to_return = 1; 607 int to_return = 1;
608 free_HWCRHK_LIBNAME();
589 if(hwcrhk_dso == NULL) 609 if(hwcrhk_dso == NULL)
590 { 610 {
591 HWCRHKerr(HWCRHK_F_HWCRHK_FINISH,HWCRHK_R_NOT_LOADED); 611 HWCRHKerr(HWCRHK_F_HWCRHK_FINISH,HWCRHK_R_NOT_LOADED);
@@ -634,8 +654,7 @@ static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
634 HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,ERR_R_PASSED_NULL_PARAMETER); 654 HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,ERR_R_PASSED_NULL_PARAMETER);
635 return 0; 655 return 0;
636 } 656 }
637 HWCRHK_LIBNAME = (const char *)p; 657 return set_HWCRHK_LIBNAME((const char *)p);
638 return 1;
639 case ENGINE_CTRL_SET_LOGSTREAM: 658 case ENGINE_CTRL_SET_LOGSTREAM:
640 { 659 {
641 BIO *bio = (BIO *)p; 660 BIO *bio = (BIO *)p;
@@ -1040,6 +1059,7 @@ static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
1040 return hwcrhk_mod_exp(r, a, p, m, ctx); 1059 return hwcrhk_mod_exp(r, a, p, m, ctx);
1041 } 1060 }
1042 1061
1062#ifndef OPENSSL_NO_DH
1043/* This function is aliased to mod_exp (with the dh and mont dropped). */ 1063/* This function is aliased to mod_exp (with the dh and mont dropped). */
1044static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r, 1064static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r,
1045 const BIGNUM *a, const BIGNUM *p, 1065 const BIGNUM *a, const BIGNUM *p,
@@ -1047,6 +1067,7 @@ static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r,
1047 { 1067 {
1048 return hwcrhk_mod_exp(r, a, p, m, ctx); 1068 return hwcrhk_mod_exp(r, a, p, m, ctx);
1049 } 1069 }
1070#endif
1050 1071
1051/* Random bytes are good */ 1072/* Random bytes are good */
1052static int hwcrhk_rand_bytes(unsigned char *buf, int num) 1073static int hwcrhk_rand_bytes(unsigned char *buf, int num)