Deleted Added
full compact
1/* crypto/engine/e_chil.c -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org), Geoff Thorpe
3 * (geoff@geoffthorpe.net) and Dr Stephen N Henson (steve@openssl.org)
4 * for the OpenSSL project 2000.
5 */
6/* ====================================================================
7 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
8 *

--- 97 unchanged lines hidden (view full) ---

106
107/* BIGNUM stuff */
108static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
109 const BIGNUM *m, BN_CTX *ctx);
110
111#ifndef OPENSSL_NO_RSA
112/* RSA stuff */
113static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
114#endif
115#ifndef OPENSSL_NO_RSA
114/* This function is aliased to mod_exp (with the mont stuff dropped). */
115static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
116 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
117static int hwcrhk_rsa_finish(RSA *rsa);
118#endif
119
120#ifndef OPENSSL_NO_DH
121/* DH stuff */
122/* This function is alised to mod_exp (with the DH and mont dropped). */
123static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r,
124 const BIGNUM *a, const BIGNUM *p,
125 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
126#endif
127
128/* RAND stuff */
129static int hwcrhk_rand_bytes(unsigned char *buf, int num);
130static int hwcrhk_rand_status(void);
131
132/* KM stuff */
133static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,
134 UI_METHOD *ui_method, void *callback_data);
135static EVP_PKEY *hwcrhk_load_pubkey(ENGINE *eng, const char *key_id,
136 UI_METHOD *ui_method, void *callback_data);
138#ifndef OPENSSL_NO_RSA
139static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
140 int ind,long argl, void *argp);
141#endif
137
138/* Interaction stuff */
139static int hwcrhk_insert_card(const char *prompt_info,
140 const char *wrong_info,
141 HWCryptoHook_PassphraseContext *ppctx,
142 HWCryptoHook_CallerContext *cactx);
143static int hwcrhk_get_pass(const char *prompt_info,
144 int *len_io, char *buf,

--- 38 unchanged lines hidden (view full) ---

183 "CHIL RSA method",
184 NULL,
185 NULL,
186 NULL,
187 NULL,
188 hwcrhk_rsa_mod_exp,
189 hwcrhk_mod_exp_mont,
190 NULL,
196 NULL,
191 hwcrhk_rsa_finish,
192 0,
193 NULL,
194 NULL,
195 NULL,
196 NULL
197 };
198#endif
199

--- 393 unchanged lines hidden (view full) ---

593 HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_UNIT_FAILURE);
594 goto err;
595 }
596 /* Everything's fine. */
597#ifndef OPENSSL_NO_RSA
598 if (hndidx_rsa == -1)
599 hndidx_rsa = RSA_get_ex_new_index(0,
600 "nFast HWCryptoHook RSA key handle",
606 NULL, NULL, hwcrhk_ex_free);
601 NULL, NULL, NULL);
602#endif
603 return 1;
604err:
605 if(hwcrhk_dso)
606 DSO_free(hwcrhk_dso);
607 hwcrhk_dso = NULL;
608 p_hwcrhk_Init = NULL;
609 p_hwcrhk_Finish = NULL;

--- 461 unchanged lines hidden (view full) ---

1071
1072#ifndef OPENSSL_NO_RSA
1073/* This function is aliased to mod_exp (with the mont stuff dropped). */
1074static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
1075 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
1076 {
1077 return hwcrhk_mod_exp(r, a, p, m, ctx);
1078 }
1079
1080static int hwcrhk_rsa_finish(RSA *rsa)
1081 {
1082 HWCryptoHook_RSAKeyHandle *hptr;
1083
1084 hptr = RSA_get_ex_data(rsa, hndidx_rsa);
1085 if (hptr)
1086 {
1087 p_hwcrhk_RSAUnloadKey(*hptr, NULL);
1088 OPENSSL_free(hptr);
1089 RSA_set_ex_data(rsa, hndidx_rsa, NULL);
1090 }
1091 return 1;
1092 }
1093
1094#endif
1095
1096#ifndef OPENSSL_NO_DH
1097/* This function is aliased to mod_exp (with the dh and mont dropped). */
1098static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r,
1099 const BIGNUM *a, const BIGNUM *p,
1100 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
1101 {

--- 42 unchanged lines hidden (view full) ---

1144 return to_return;
1145 }
1146
1147static int hwcrhk_rand_status(void)
1148 {
1149 return 1;
1150 }
1151
1142/* This cleans up an RSA KM key, called when ex_data is freed */
1143#ifndef OPENSSL_NO_RSA
1144static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
1145 int ind,long argl, void *argp)
1146{
1147 char tempbuf[1024];
1148 HWCryptoHook_ErrMsgBuf rmsg;
1149#ifndef OPENSSL_NO_RSA
1150 HWCryptoHook_RSAKeyHandle *hptr;
1151#endif
1152#if !defined(OPENSSL_NO_RSA)
1153 int ret;
1154#endif
1155
1156 rmsg.buf = tempbuf;
1157 rmsg.size = sizeof(tempbuf);
1158
1159#ifndef OPENSSL_NO_RSA
1160 hptr = (HWCryptoHook_RSAKeyHandle *) item;
1161 if(hptr)
1162 {
1163 ret = p_hwcrhk_RSAUnloadKey(*hptr, NULL);
1164 OPENSSL_free(hptr);
1165 }
1166#endif
1167}
1168#endif
1169
1152/* Mutex calls: since the HWCryptoHook model closely follows the POSIX model
1153 * these just wrap the POSIX functions and add some logging.
1154 */
1155
1156static int hwcrhk_mutex_init(HWCryptoHook_Mutex* mt,
1157 HWCryptoHook_CallerContext *cactx)
1158 {
1159 mt->lockid = CRYPTO_get_new_dynlockid();

--- 133 unchanged lines hidden (view full) ---

1293 char answer;
1294 char buf[BUFSIZ];
1295 /* Despite what the documentation says wrong_info can be
1296 * an empty string.
1297 */
1298 if (wrong_info && *wrong_info)
1299 BIO_snprintf(buf, sizeof(buf)-1,
1300 "Current card: \"%s\"\n", wrong_info);
1301 else
1302 buf[0] = 0;
1303 ok = UI_dup_info_string(ui, buf);
1304 if (ok >= 0 && prompt_info)
1305 {
1306 BIO_snprintf(buf, sizeof(buf)-1,
1307 "Insert card \"%s\"", prompt_info);
1308 ok = UI_dup_input_boolean(ui, buf,
1309 "\n then hit <enter> or C<enter> to cancel\n",
1310 "\r\n", "Cc", UI_INPUT_FLAG_ECHO, &answer);

--- 49 unchanged lines hidden ---