diff options
| author | markus <> | 2002-09-05 22:45:21 +0000 |
|---|---|---|
| committer | markus <> | 2002-09-05 22:45:21 +0000 |
| commit | 2a6851ef8adb0e84ff2515493d3704a13c6256b0 (patch) | |
| tree | 9df5b497548eaf51e9f234d27aaf988cd14882c2 /src/lib/libcrypto/engine/hw_cswift.c | |
| parent | 5514995a9d5ed91db089875adb509c7781357c0e (diff) | |
| download | openbsd-2a6851ef8adb0e84ff2515493d3704a13c6256b0.tar.gz openbsd-2a6851ef8adb0e84ff2515493d3704a13c6256b0.tar.bz2 openbsd-2a6851ef8adb0e84ff2515493d3704a13c6256b0.zip | |
import openssl-0.9.7-beta3
Diffstat (limited to 'src/lib/libcrypto/engine/hw_cswift.c')
| -rw-r--r-- | src/lib/libcrypto/engine/hw_cswift.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/lib/libcrypto/engine/hw_cswift.c b/src/lib/libcrypto/engine/hw_cswift.c index d8b380550f..f5c897bdbb 100644 --- a/src/lib/libcrypto/engine/hw_cswift.c +++ b/src/lib/libcrypto/engine/hw_cswift.c | |||
| @@ -280,8 +280,24 @@ t_swSimpleRequest *p_CSwift_SimpleRequest = NULL; | |||
| 280 | t_swReleaseAccContext *p_CSwift_ReleaseAccContext = NULL; | 280 | t_swReleaseAccContext *p_CSwift_ReleaseAccContext = NULL; |
| 281 | 281 | ||
| 282 | /* Used in the DSO operations. */ | 282 | /* Used in the DSO operations. */ |
| 283 | static const char def_CSWIFT_LIBNAME[] = "swift"; | 283 | static const char *CSWIFT_LIBNAME = NULL; |
| 284 | static const char *CSWIFT_LIBNAME = def_CSWIFT_LIBNAME; | 284 | static const char *get_CSWIFT_LIBNAME(void) |
| 285 | { | ||
| 286 | if(CSWIFT_LIBNAME) | ||
| 287 | return CSWIFT_LIBNAME; | ||
| 288 | return "swift"; | ||
| 289 | } | ||
| 290 | static void free_CSWIFT_LIBNAME(void) | ||
| 291 | { | ||
| 292 | if(CSWIFT_LIBNAME) | ||
| 293 | OPENSSL_free((void*)CSWIFT_LIBNAME); | ||
| 294 | CSWIFT_LIBNAME = NULL; | ||
| 295 | } | ||
| 296 | static long set_CSWIFT_LIBNAME(const char *name) | ||
| 297 | { | ||
| 298 | free_CSWIFT_LIBNAME(); | ||
| 299 | return (((CSWIFT_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0); | ||
| 300 | } | ||
| 285 | static const char *CSWIFT_F1 = "swAcquireAccContext"; | 301 | static const char *CSWIFT_F1 = "swAcquireAccContext"; |
| 286 | static const char *CSWIFT_F2 = "swAttachKeyParam"; | 302 | static const char *CSWIFT_F2 = "swAttachKeyParam"; |
| 287 | static const char *CSWIFT_F3 = "swSimpleRequest"; | 303 | static const char *CSWIFT_F3 = "swSimpleRequest"; |
| @@ -313,6 +329,7 @@ static void release_context(SW_CONTEXT_HANDLE hac) | |||
| 313 | /* Destructor (complements the "ENGINE_cswift()" constructor) */ | 329 | /* Destructor (complements the "ENGINE_cswift()" constructor) */ |
| 314 | static int cswift_destroy(ENGINE *e) | 330 | static int cswift_destroy(ENGINE *e) |
| 315 | { | 331 | { |
| 332 | free_CSWIFT_LIBNAME(); | ||
| 316 | ERR_unload_CSWIFT_strings(); | 333 | ERR_unload_CSWIFT_strings(); |
| 317 | return 1; | 334 | return 1; |
| 318 | } | 335 | } |
| @@ -332,7 +349,7 @@ static int cswift_init(ENGINE *e) | |||
| 332 | goto err; | 349 | goto err; |
| 333 | } | 350 | } |
| 334 | /* Attempt to load libswift.so/swift.dll/whatever. */ | 351 | /* Attempt to load libswift.so/swift.dll/whatever. */ |
| 335 | cswift_dso = DSO_load(NULL, CSWIFT_LIBNAME, NULL, 0); | 352 | cswift_dso = DSO_load(NULL, get_CSWIFT_LIBNAME(), NULL, 0); |
| 336 | if(cswift_dso == NULL) | 353 | if(cswift_dso == NULL) |
| 337 | { | 354 | { |
| 338 | CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_NOT_LOADED); | 355 | CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_NOT_LOADED); |
| @@ -377,6 +394,7 @@ err: | |||
| 377 | 394 | ||
| 378 | static int cswift_finish(ENGINE *e) | 395 | static int cswift_finish(ENGINE *e) |
| 379 | { | 396 | { |
| 397 | free_CSWIFT_LIBNAME(); | ||
| 380 | if(cswift_dso == NULL) | 398 | if(cswift_dso == NULL) |
| 381 | { | 399 | { |
| 382 | CSWIFTerr(CSWIFT_F_CSWIFT_FINISH,CSWIFT_R_NOT_LOADED); | 400 | CSWIFTerr(CSWIFT_F_CSWIFT_FINISH,CSWIFT_R_NOT_LOADED); |
| @@ -411,8 +429,7 @@ static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | |||
| 411 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,CSWIFT_R_ALREADY_LOADED); | 429 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,CSWIFT_R_ALREADY_LOADED); |
| 412 | return 0; | 430 | return 0; |
| 413 | } | 431 | } |
| 414 | CSWIFT_LIBNAME = (const char *)p; | 432 | return set_CSWIFT_LIBNAME((const char *)p); |
| 415 | return 1; | ||
| 416 | default: | 433 | default: |
| 417 | break; | 434 | break; |
| 418 | } | 435 | } |
| @@ -484,7 +501,7 @@ static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | |||
| 484 | goto err; | 501 | goto err; |
| 485 | default: | 502 | default: |
| 486 | { | 503 | { |
| 487 | char tmpbuf[20]; | 504 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; |
| 488 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_REQUEST_FAILED); | 505 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_REQUEST_FAILED); |
| 489 | sprintf(tmpbuf, "%ld", sw_status); | 506 | sprintf(tmpbuf, "%ld", sw_status); |
| 490 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | 507 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); |
| @@ -501,7 +518,7 @@ static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | |||
| 501 | if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP, &arg, 1, | 518 | if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP, &arg, 1, |
| 502 | &res, 1)) != SW_OK) | 519 | &res, 1)) != SW_OK) |
| 503 | { | 520 | { |
| 504 | char tmpbuf[20]; | 521 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; |
| 505 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_REQUEST_FAILED); | 522 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_REQUEST_FAILED); |
| 506 | sprintf(tmpbuf, "%ld", sw_status); | 523 | sprintf(tmpbuf, "%ld", sw_status); |
| 507 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | 524 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); |
| @@ -591,7 +608,7 @@ static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | |||
| 591 | goto err; | 608 | goto err; |
| 592 | default: | 609 | default: |
| 593 | { | 610 | { |
| 594 | char tmpbuf[20]; | 611 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; |
| 595 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_REQUEST_FAILED); | 612 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_REQUEST_FAILED); |
| 596 | sprintf(tmpbuf, "%ld", sw_status); | 613 | sprintf(tmpbuf, "%ld", sw_status); |
| 597 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | 614 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); |
| @@ -608,7 +625,7 @@ static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | |||
| 608 | if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP_CRT, &arg, 1, | 625 | if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP_CRT, &arg, 1, |
| 609 | &res, 1)) != SW_OK) | 626 | &res, 1)) != SW_OK) |
| 610 | { | 627 | { |
| 611 | char tmpbuf[20]; | 628 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; |
| 612 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_REQUEST_FAILED); | 629 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_REQUEST_FAILED); |
| 613 | sprintf(tmpbuf, "%ld", sw_status); | 630 | sprintf(tmpbuf, "%ld", sw_status); |
| 614 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | 631 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); |
| @@ -723,7 +740,7 @@ static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa) | |||
| 723 | goto err; | 740 | goto err; |
| 724 | default: | 741 | default: |
| 725 | { | 742 | { |
| 726 | char tmpbuf[20]; | 743 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; |
| 727 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_REQUEST_FAILED); | 744 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_REQUEST_FAILED); |
| 728 | sprintf(tmpbuf, "%ld", sw_status); | 745 | sprintf(tmpbuf, "%ld", sw_status); |
| 729 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | 746 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); |
| @@ -741,7 +758,7 @@ static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa) | |||
| 741 | &res, 1); | 758 | &res, 1); |
| 742 | if(sw_status != SW_OK) | 759 | if(sw_status != SW_OK) |
| 743 | { | 760 | { |
| 744 | char tmpbuf[20]; | 761 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; |
| 745 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_REQUEST_FAILED); | 762 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_REQUEST_FAILED); |
| 746 | sprintf(tmpbuf, "%ld", sw_status); | 763 | sprintf(tmpbuf, "%ld", sw_status); |
| 747 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | 764 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); |
| @@ -835,7 +852,7 @@ static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len, | |||
| 835 | goto err; | 852 | goto err; |
| 836 | default: | 853 | default: |
| 837 | { | 854 | { |
| 838 | char tmpbuf[20]; | 855 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; |
| 839 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED); | 856 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED); |
| 840 | sprintf(tmpbuf, "%ld", sw_status); | 857 | sprintf(tmpbuf, "%ld", sw_status); |
| 841 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | 858 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); |
| @@ -857,7 +874,7 @@ static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len, | |||
| 857 | &res, 1); | 874 | &res, 1); |
| 858 | if(sw_status != SW_OK) | 875 | if(sw_status != SW_OK) |
| 859 | { | 876 | { |
| 860 | char tmpbuf[20]; | 877 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; |
| 861 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED); | 878 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED); |
| 862 | sprintf(tmpbuf, "%ld", sw_status); | 879 | sprintf(tmpbuf, "%ld", sw_status); |
| 863 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | 880 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); |
