diff options
| author | markus <> | 2003-05-12 02:18:40 +0000 |
|---|---|---|
| committer | markus <> | 2003-05-12 02:18:40 +0000 |
| commit | d4fcd82bb7f6d603bd61e19a81ba97337b89dfca (patch) | |
| tree | d52e3a0f1f08f65ad283027e560e17ed0d720462 /src/lib/libcrypto/engine/hw_ncipher.c | |
| parent | 582bbd139cd2afd58d10dc051c5b0b989b441074 (diff) | |
| download | openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.tar.gz openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.tar.bz2 openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.zip | |
merge 0.9.7b with local changes; crank majors for libssl/libcrypto
Diffstat (limited to 'src/lib/libcrypto/engine/hw_ncipher.c')
| -rw-r--r-- | src/lib/libcrypto/engine/hw_ncipher.c | 68 |
1 files changed, 57 insertions, 11 deletions
diff --git a/src/lib/libcrypto/engine/hw_ncipher.c b/src/lib/libcrypto/engine/hw_ncipher.c index a43d4360f2..0d1c6b8df0 100644 --- a/src/lib/libcrypto/engine/hw_ncipher.c +++ b/src/lib/libcrypto/engine/hw_ncipher.c | |||
| @@ -91,11 +91,19 @@ static int hwcrhk_init(ENGINE *e); | |||
| 91 | static int hwcrhk_finish(ENGINE *e); | 91 | static int hwcrhk_finish(ENGINE *e); |
| 92 | static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | 92 | static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); |
| 93 | 93 | ||
| 94 | /* Functions to handle mutexes */ | 94 | /* Functions to handle mutexes if have dynamic locks */ |
| 95 | static int hwcrhk_mutex_init(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext*); | 95 | static int hwcrhk_mutex_init(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext*); |
| 96 | static int hwcrhk_mutex_lock(HWCryptoHook_Mutex*); | 96 | static int hwcrhk_mutex_lock(HWCryptoHook_Mutex*); |
| 97 | static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex*); | 97 | static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex*); |
| 98 | static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex*); | 98 | static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex*); |
| 99 | #if 1 /* This is a HACK which will disappear in 0.9.8 */ | ||
| 100 | /* Functions to handle mutexes if only have static locks */ | ||
| 101 | static int hwcrhk_static_mutex_init(HWCryptoHook_Mutex *m, | ||
| 102 | HWCryptoHook_CallerContext *c); | ||
| 103 | static int hwcrhk_static_mutex_lock(HWCryptoHook_Mutex *m); | ||
| 104 | static void hwcrhk_static_mutex_unlock(HWCryptoHook_Mutex *m); | ||
| 105 | static void hwcrhk_static_mutex_destroy(HWCryptoHook_Mutex *m); | ||
| 106 | #endif | ||
| 99 | 107 | ||
| 100 | /* BIGNUM stuff */ | 108 | /* BIGNUM stuff */ |
| 101 | static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 109 | static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| @@ -373,6 +381,7 @@ static int bind_helper(ENGINE *e) | |||
| 373 | return 1; | 381 | return 1; |
| 374 | } | 382 | } |
| 375 | 383 | ||
| 384 | #ifndef ENGINE_DYNAMIC_SUPPORT | ||
| 376 | static ENGINE *engine_ncipher(void) | 385 | static ENGINE *engine_ncipher(void) |
| 377 | { | 386 | { |
| 378 | ENGINE *ret = ENGINE_new(); | 387 | ENGINE *ret = ENGINE_new(); |
| @@ -395,6 +404,7 @@ void ENGINE_load_chil(void) | |||
| 395 | ENGINE_free(toadd); | 404 | ENGINE_free(toadd); |
| 396 | ERR_clear_error(); | 405 | ERR_clear_error(); |
| 397 | } | 406 | } |
| 407 | #endif | ||
| 398 | 408 | ||
| 399 | /* This is a process-global DSO handle used for loading and unloading | 409 | /* This is a process-global DSO handle used for loading and unloading |
| 400 | * the HWCryptoHook library. NB: This is only set (or unset) during an | 410 | * the HWCryptoHook library. NB: This is only set (or unset) during an |
| @@ -558,15 +568,31 @@ static int hwcrhk_init(ENGINE *e) | |||
| 558 | 568 | ||
| 559 | /* Check if the application decided to support dynamic locks, | 569 | /* Check if the application decided to support dynamic locks, |
| 560 | and if it does, use them. */ | 570 | and if it does, use them. */ |
| 561 | if (disable_mutex_callbacks == 0 && | 571 | if (disable_mutex_callbacks == 0) |
| 562 | CRYPTO_get_dynlock_create_callback() != NULL && | ||
| 563 | CRYPTO_get_dynlock_lock_callback() != NULL && | ||
| 564 | CRYPTO_get_dynlock_destroy_callback() != NULL) | ||
| 565 | { | 572 | { |
| 566 | hwcrhk_globals.mutex_init = hwcrhk_mutex_init; | 573 | if (CRYPTO_get_dynlock_create_callback() != NULL && |
| 567 | hwcrhk_globals.mutex_acquire = hwcrhk_mutex_lock; | 574 | CRYPTO_get_dynlock_lock_callback() != NULL && |
| 568 | hwcrhk_globals.mutex_release = hwcrhk_mutex_unlock; | 575 | CRYPTO_get_dynlock_destroy_callback() != NULL) |
| 569 | hwcrhk_globals.mutex_destroy = hwcrhk_mutex_destroy; | 576 | { |
| 577 | hwcrhk_globals.mutex_init = hwcrhk_mutex_init; | ||
| 578 | hwcrhk_globals.mutex_acquire = hwcrhk_mutex_lock; | ||
| 579 | hwcrhk_globals.mutex_release = hwcrhk_mutex_unlock; | ||
| 580 | hwcrhk_globals.mutex_destroy = hwcrhk_mutex_destroy; | ||
| 581 | } | ||
| 582 | else if (CRYPTO_get_locking_callback() != NULL) | ||
| 583 | { | ||
| 584 | HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DYNAMIC_LOCKING_MISSING); | ||
| 585 | ERR_add_error_data(1,"You HAVE to add dynamic locking callbacks via CRYPTO_set_dynlock_{create,lock,destroy}_callback()"); | ||
| 586 | #if 1 /* This is a HACK which will disappear in 0.9.8 */ | ||
| 587 | hwcrhk_globals.maxmutexes = 1; /* Only have one lock */ | ||
| 588 | hwcrhk_globals.mutex_init = hwcrhk_static_mutex_init; | ||
| 589 | hwcrhk_globals.mutex_acquire = hwcrhk_static_mutex_lock; | ||
| 590 | hwcrhk_globals.mutex_release = hwcrhk_static_mutex_unlock; | ||
| 591 | hwcrhk_globals.mutex_destroy = hwcrhk_static_mutex_destroy; | ||
| 592 | #else | ||
| 593 | goto err; | ||
| 594 | #endif | ||
| 595 | } | ||
| 570 | } | 596 | } |
| 571 | 597 | ||
| 572 | /* Try and get a context - if not, we may have a DSO but no | 598 | /* Try and get a context - if not, we may have a DSO but no |
| @@ -1020,7 +1046,7 @@ static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa) | |||
| 1020 | 1046 | ||
| 1021 | /* Perform the operation */ | 1047 | /* Perform the operation */ |
| 1022 | ret = p_hwcrhk_ModExpCRT(hwcrhk_context, m_a, m_p, m_q, | 1048 | ret = p_hwcrhk_ModExpCRT(hwcrhk_context, m_a, m_p, m_q, |
| 1023 | m_dmp1, m_dmq1, m_iqmp, &m_r, NULL); | 1049 | m_dmp1, m_dmq1, m_iqmp, &m_r, &rmsg); |
| 1024 | 1050 | ||
| 1025 | /* Convert the response */ | 1051 | /* Convert the response */ |
| 1026 | r->top = m_r.size / sizeof(BN_ULONG); | 1052 | r->top = m_r.size / sizeof(BN_ULONG); |
| @@ -1171,6 +1197,26 @@ static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex *mt) | |||
| 1171 | CRYPTO_destroy_dynlockid(mt->lockid); | 1197 | CRYPTO_destroy_dynlockid(mt->lockid); |
| 1172 | } | 1198 | } |
| 1173 | 1199 | ||
| 1200 | /* Mutex upcalls to use if the application does not support dynamic locks */ | ||
| 1201 | |||
| 1202 | static int hwcrhk_static_mutex_init(HWCryptoHook_Mutex *m, | ||
| 1203 | HWCryptoHook_CallerContext *c) | ||
| 1204 | { | ||
| 1205 | return 0; | ||
| 1206 | } | ||
| 1207 | static int hwcrhk_static_mutex_lock(HWCryptoHook_Mutex *m) | ||
| 1208 | { | ||
| 1209 | CRYPTO_w_lock(CRYPTO_LOCK_HWCRHK); | ||
| 1210 | return 0; | ||
| 1211 | } | ||
| 1212 | static void hwcrhk_static_mutex_unlock(HWCryptoHook_Mutex *m) | ||
| 1213 | { | ||
| 1214 | CRYPTO_w_unlock(CRYPTO_LOCK_HWCRHK); | ||
| 1215 | } | ||
| 1216 | static void hwcrhk_static_mutex_destroy(HWCryptoHook_Mutex *m) | ||
| 1217 | { | ||
| 1218 | } | ||
| 1219 | |||
| 1174 | static int hwcrhk_get_pass(const char *prompt_info, | 1220 | static int hwcrhk_get_pass(const char *prompt_info, |
| 1175 | int *len_io, char *buf, | 1221 | int *len_io, char *buf, |
| 1176 | HWCryptoHook_PassphraseContext *ppctx, | 1222 | HWCryptoHook_PassphraseContext *ppctx, |
| @@ -1318,7 +1364,7 @@ static void hwcrhk_log_message(void *logstr, const char *message) | |||
| 1318 | lstream=*(BIO **)logstr; | 1364 | lstream=*(BIO **)logstr; |
| 1319 | if (lstream) | 1365 | if (lstream) |
| 1320 | { | 1366 | { |
| 1321 | BIO_write(lstream, message, strlen(message)); | 1367 | BIO_printf(lstream, "%s\n", message); |
| 1322 | } | 1368 | } |
| 1323 | CRYPTO_w_unlock(CRYPTO_LOCK_BIO); | 1369 | CRYPTO_w_unlock(CRYPTO_LOCK_BIO); |
| 1324 | } | 1370 | } |
