Deleted Added
full compact
e_chil.c (206046) e_chil.c (215697)
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);
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
116/* This function is aliased to mod_exp (with the mont stuff dropped). */
117static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
118 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
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);
119#endif
120
121#ifndef OPENSSL_NO_DH
122/* DH stuff */
123/* This function is alised to mod_exp (with the DH and mont dropped). */
124static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r,
125 const BIGNUM *a, const BIGNUM *p,
126 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
127#endif
128
129/* RAND stuff */
130static int hwcrhk_rand_bytes(unsigned char *buf, int num);
131static int hwcrhk_rand_status(void);
132
133/* KM stuff */
134static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,
135 UI_METHOD *ui_method, void *callback_data);
136static EVP_PKEY *hwcrhk_load_pubkey(ENGINE *eng, const char *key_id,
137 UI_METHOD *ui_method, void *callback_data);
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
142
143/* Interaction stuff */
144static int hwcrhk_insert_card(const char *prompt_info,
145 const char *wrong_info,
146 HWCryptoHook_PassphraseContext *ppctx,
147 HWCryptoHook_CallerContext *cactx);
148static int hwcrhk_get_pass(const char *prompt_info,
149 int *len_io, char *buf,

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

188 "CHIL RSA method",
189 NULL,
190 NULL,
191 NULL,
192 NULL,
193 hwcrhk_rsa_mod_exp,
194 hwcrhk_mod_exp_mont,
195 NULL,
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,
197 0,
198 NULL,
199 NULL,
200 NULL,
201 NULL
202 };
203#endif
204

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

598 HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_UNIT_FAILURE);
599 goto err;
600 }
601 /* Everything's fine. */
602#ifndef OPENSSL_NO_RSA
603 if (hndidx_rsa == -1)
604 hndidx_rsa = RSA_get_ex_new_index(0,
605 "nFast HWCryptoHook RSA key handle",
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);
607#endif
608 return 1;
609err:
610 if(hwcrhk_dso)
611 DSO_free(hwcrhk_dso);
612 hwcrhk_dso = NULL;
613 p_hwcrhk_Init = NULL;
614 p_hwcrhk_Finish = NULL;

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

1076
1077#ifndef OPENSSL_NO_RSA
1078/* This function is aliased to mod_exp (with the mont stuff dropped). */
1079static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
1080 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
1081 {
1082 return hwcrhk_mod_exp(r, a, p, m, ctx);
1083 }
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
1084#endif
1085
1086#ifndef OPENSSL_NO_DH
1087/* This function is aliased to mod_exp (with the dh and mont dropped). */
1088static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r,
1089 const BIGNUM *a, const BIGNUM *p,
1090 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
1091 {

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

1134 return to_return;
1135 }
1136
1137static int hwcrhk_rand_status(void)
1138 {
1139 return 1;
1140 }
1141
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
1170/* Mutex calls: since the HWCryptoHook model closely follows the POSIX model
1171 * these just wrap the POSIX functions and add some logging.
1172 */
1173
1174static int hwcrhk_mutex_init(HWCryptoHook_Mutex* mt,
1175 HWCryptoHook_CallerContext *cactx)
1176 {
1177 mt->lockid = CRYPTO_get_new_dynlockid();

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

1311 char answer;
1312 char buf[BUFSIZ];
1313 /* Despite what the documentation says wrong_info can be
1314 * an empty string.
1315 */
1316 if (wrong_info && *wrong_info)
1317 BIO_snprintf(buf, sizeof(buf)-1,
1318 "Current card: \"%s\"\n", wrong_info);
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;
1319 ok = UI_dup_info_string(ui, buf);
1320 if (ok >= 0 && prompt_info)
1321 {
1322 BIO_snprintf(buf, sizeof(buf)-1,
1323 "Insert card \"%s\"", prompt_info);
1324 ok = UI_dup_input_boolean(ui, buf,
1325 "\n then hit <enter> or C<enter> to cancel\n",
1326 "\r\n", "Cc", UI_INPUT_FLAG_ECHO, &answer);

--- 49 unchanged lines hidden ---
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 ---