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_cswift.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_cswift.c')
| -rw-r--r-- | src/lib/libcrypto/engine/hw_cswift.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/lib/libcrypto/engine/hw_cswift.c b/src/lib/libcrypto/engine/hw_cswift.c index f5c897bdbb..f128ee5a68 100644 --- a/src/lib/libcrypto/engine/hw_cswift.c +++ b/src/lib/libcrypto/engine/hw_cswift.c | |||
| @@ -121,6 +121,10 @@ static int cswift_mod_exp_dh(const DH *dh, BIGNUM *r, | |||
| 121 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | 121 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); |
| 122 | #endif | 122 | #endif |
| 123 | 123 | ||
| 124 | /* RAND stuff */ | ||
| 125 | static int cswift_rand_bytes(unsigned char *buf, int num); | ||
| 126 | static int cswift_rand_status(void); | ||
| 127 | |||
| 124 | /* The definitions for control commands specific to this engine */ | 128 | /* The definitions for control commands specific to this engine */ |
| 125 | #define CSWIFT_CMD_SO_PATH ENGINE_CMD_BASE | 129 | #define CSWIFT_CMD_SO_PATH ENGINE_CMD_BASE |
| 126 | static const ENGINE_CMD_DEFN cswift_cmd_defns[] = { | 130 | static const ENGINE_CMD_DEFN cswift_cmd_defns[] = { |
| @@ -183,6 +187,18 @@ static DH_METHOD cswift_dh = | |||
| 183 | }; | 187 | }; |
| 184 | #endif | 188 | #endif |
| 185 | 189 | ||
| 190 | static RAND_METHOD cswift_random = | ||
| 191 | { | ||
| 192 | /* "CryptoSwift RAND method", */ | ||
| 193 | NULL, | ||
| 194 | cswift_rand_bytes, | ||
| 195 | NULL, | ||
| 196 | NULL, | ||
| 197 | cswift_rand_bytes, | ||
| 198 | cswift_rand_status, | ||
| 199 | }; | ||
| 200 | |||
| 201 | |||
| 186 | /* Constants used when creating the ENGINE */ | 202 | /* Constants used when creating the ENGINE */ |
| 187 | static const char *engine_cswift_id = "cswift"; | 203 | static const char *engine_cswift_id = "cswift"; |
| 188 | static const char *engine_cswift_name = "CryptoSwift hardware engine support"; | 204 | static const char *engine_cswift_name = "CryptoSwift hardware engine support"; |
| @@ -208,6 +224,7 @@ static int bind_helper(ENGINE *e) | |||
| 208 | #ifndef OPENSSL_NO_DH | 224 | #ifndef OPENSSL_NO_DH |
| 209 | !ENGINE_set_DH(e, &cswift_dh) || | 225 | !ENGINE_set_DH(e, &cswift_dh) || |
| 210 | #endif | 226 | #endif |
| 227 | !ENGINE_set_RAND(e, &cswift_random) || | ||
| 211 | !ENGINE_set_destroy_function(e, cswift_destroy) || | 228 | !ENGINE_set_destroy_function(e, cswift_destroy) || |
| 212 | !ENGINE_set_init_function(e, cswift_init) || | 229 | !ENGINE_set_init_function(e, cswift_init) || |
| 213 | !ENGINE_set_finish_function(e, cswift_finish) || | 230 | !ENGINE_set_finish_function(e, cswift_finish) || |
| @@ -242,6 +259,7 @@ static int bind_helper(ENGINE *e) | |||
| 242 | return 1; | 259 | return 1; |
| 243 | } | 260 | } |
| 244 | 261 | ||
| 262 | #ifndef ENGINE_DYNAMIC_SUPPORT | ||
| 245 | static ENGINE *engine_cswift(void) | 263 | static ENGINE *engine_cswift(void) |
| 246 | { | 264 | { |
| 247 | ENGINE *ret = ENGINE_new(); | 265 | ENGINE *ret = ENGINE_new(); |
| @@ -264,6 +282,7 @@ void ENGINE_load_cswift(void) | |||
| 264 | ENGINE_free(toadd); | 282 | ENGINE_free(toadd); |
| 265 | ERR_clear_error(); | 283 | ERR_clear_error(); |
| 266 | } | 284 | } |
| 285 | #endif | ||
| 267 | 286 | ||
| 268 | /* This is a process-global DSO handle used for loading and unloading | 287 | /* This is a process-global DSO handle used for loading and unloading |
| 269 | * the CryptoSwift library. NB: This is only set (or unset) during an | 288 | * the CryptoSwift library. NB: This is only set (or unset) during an |
| @@ -905,6 +924,60 @@ static int cswift_mod_exp_dh(const DH *dh, BIGNUM *r, | |||
| 905 | } | 924 | } |
| 906 | #endif | 925 | #endif |
| 907 | 926 | ||
| 927 | /* Random bytes are good */ | ||
| 928 | static int cswift_rand_bytes(unsigned char *buf, int num) | ||
| 929 | { | ||
| 930 | SW_CONTEXT_HANDLE hac; | ||
| 931 | SW_STATUS swrc; | ||
| 932 | SW_LARGENUMBER largenum; | ||
| 933 | size_t nbytes = 0; | ||
| 934 | int acquired = 0; | ||
| 935 | int to_return = 0; /* assume failure */ | ||
| 936 | |||
| 937 | if (!get_context(&hac)) | ||
| 938 | { | ||
| 939 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_UNIT_FAILURE); | ||
| 940 | goto err; | ||
| 941 | } | ||
| 942 | acquired = 1; | ||
| 943 | |||
| 944 | while (nbytes < (size_t)num) | ||
| 945 | { | ||
| 946 | /* tell CryptoSwift how many bytes we want and where we want it. | ||
| 947 | * Note: - CryptoSwift cannot do more than 4096 bytes at a time. | ||
| 948 | * - CryptoSwift can only do multiple of 32-bits. */ | ||
| 949 | largenum.value = (SW_BYTE *) buf + nbytes; | ||
| 950 | if (4096 > num - nbytes) | ||
| 951 | largenum.nbytes = num - nbytes; | ||
| 952 | else | ||
| 953 | largenum.nbytes = 4096; | ||
| 954 | |||
| 955 | swrc = p_CSwift_SimpleRequest(hac, SW_CMD_RAND, NULL, 0, &largenum, 1); | ||
| 956 | if (swrc != SW_OK) | ||
| 957 | { | ||
| 958 | char tmpbuf[20]; | ||
| 959 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_REQUEST_FAILED); | ||
| 960 | sprintf(tmpbuf, "%ld", swrc); | ||
| 961 | ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf); | ||
| 962 | goto err; | ||
| 963 | } | ||
| 964 | |||
| 965 | nbytes += largenum.nbytes; | ||
| 966 | } | ||
| 967 | to_return = 1; /* success */ | ||
| 968 | |||
| 969 | err: | ||
| 970 | if (acquired) | ||
| 971 | release_context(hac); | ||
| 972 | return to_return; | ||
| 973 | } | ||
| 974 | |||
| 975 | static int cswift_rand_status(void) | ||
| 976 | { | ||
| 977 | return 1; | ||
| 978 | } | ||
| 979 | |||
| 980 | |||
| 908 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | 981 | /* This stuff is needed if this ENGINE is being compiled into a self-contained |
| 909 | * shared-library. */ | 982 | * shared-library. */ |
| 910 | #ifdef ENGINE_DYNAMIC_SUPPORT | 983 | #ifdef ENGINE_DYNAMIC_SUPPORT |
