]> git.ipfire.org Git - thirdparty/openssl.git/blob - engines/e_atalla.c
The inclusion of bn.h from the engine.h API header has been deprecated, so
[thirdparty/openssl.git] / engines / e_atalla.c
1 /* crypto/engine/hw_atalla.c */
2 /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5 /* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59 #include <stdio.h>
60 #include <string.h>
61 #include <openssl/crypto.h>
62 #include <openssl/buffer.h>
63 #include <openssl/dso.h>
64 #include <openssl/engine.h>
65 #include <openssl/rsa.h>
66 #include <openssl/dsa.h>
67 #include <openssl/dh.h>
68 #include <openssl/bn.h>
69
70 #ifndef OPENSSL_NO_HW
71 #ifndef OPENSSL_NO_HW_ATALLA
72
73 #ifdef FLAT_INC
74 #include "atalla.h"
75 #else
76 #include "vendor_defns/atalla.h"
77 #endif
78
79 #define ATALLA_LIB_NAME "atalla engine"
80 #include "e_atalla_err.c"
81
82 static int atalla_destroy(ENGINE *e);
83 static int atalla_init(ENGINE *e);
84 static int atalla_finish(ENGINE *e);
85 static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
86
87 /* BIGNUM stuff */
88 static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
89 const BIGNUM *m, BN_CTX *ctx);
90
91 #ifndef OPENSSL_NO_RSA
92 /* RSA stuff */
93 static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
94 #endif
95 /* This function is aliased to mod_exp (with the mont stuff dropped). */
96 static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
97 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
98
99 #ifndef OPENSSL_NO_DSA
100 /* DSA stuff */
101 static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
102 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
103 BN_CTX *ctx, BN_MONT_CTX *in_mont);
104 static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
105 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
106 BN_MONT_CTX *m_ctx);
107 #endif
108
109 #ifndef OPENSSL_NO_DH
110 /* DH stuff */
111 /* This function is alised to mod_exp (with the DH and mont dropped). */
112 static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r,
113 const BIGNUM *a, const BIGNUM *p,
114 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
115 #endif
116
117 /* The definitions for control commands specific to this engine */
118 #define ATALLA_CMD_SO_PATH ENGINE_CMD_BASE
119 static const ENGINE_CMD_DEFN atalla_cmd_defns[] = {
120 {ATALLA_CMD_SO_PATH,
121 "SO_PATH",
122 "Specifies the path to the 'atasi' shared library",
123 ENGINE_CMD_FLAG_STRING},
124 {0, NULL, NULL, 0}
125 };
126
127 #ifndef OPENSSL_NO_RSA
128 /* Our internal RSA_METHOD that we provide pointers to */
129 static RSA_METHOD atalla_rsa =
130 {
131 "Atalla RSA method",
132 NULL,
133 NULL,
134 NULL,
135 NULL,
136 atalla_rsa_mod_exp,
137 atalla_mod_exp_mont,
138 NULL,
139 NULL,
140 0,
141 NULL,
142 NULL,
143 NULL,
144 NULL
145 };
146 #endif
147
148 #ifndef OPENSSL_NO_DSA
149 /* Our internal DSA_METHOD that we provide pointers to */
150 static DSA_METHOD atalla_dsa =
151 {
152 "Atalla DSA method",
153 NULL, /* dsa_do_sign */
154 NULL, /* dsa_sign_setup */
155 NULL, /* dsa_do_verify */
156 atalla_dsa_mod_exp, /* dsa_mod_exp */
157 atalla_mod_exp_dsa, /* bn_mod_exp */
158 NULL, /* init */
159 NULL, /* finish */
160 0, /* flags */
161 NULL, /* app_data */
162 NULL, /* dsa_paramgen */
163 NULL /* dsa_keygen */
164 };
165 #endif
166
167 #ifndef OPENSSL_NO_DH
168 /* Our internal DH_METHOD that we provide pointers to */
169 static DH_METHOD atalla_dh =
170 {
171 "Atalla DH method",
172 NULL,
173 NULL,
174 atalla_mod_exp_dh,
175 NULL,
176 NULL,
177 0,
178 NULL,
179 NULL
180 };
181 #endif
182
183 /* Constants used when creating the ENGINE */
184 static const char *engine_atalla_id = "atalla";
185 static const char *engine_atalla_name = "Atalla hardware engine support";
186
187 /* This internal function is used by ENGINE_atalla() and possibly by the
188 * "dynamic" ENGINE support too */
189 static int bind_helper(ENGINE *e)
190 {
191 #ifndef OPENSSL_NO_RSA
192 const RSA_METHOD *meth1;
193 #endif
194 #ifndef OPENSSL_NO_DSA
195 const DSA_METHOD *meth2;
196 #endif
197 #ifndef OPENSSL_NO_DH
198 const DH_METHOD *meth3;
199 #endif
200 if(!ENGINE_set_id(e, engine_atalla_id) ||
201 !ENGINE_set_name(e, engine_atalla_name) ||
202 #ifndef OPENSSL_NO_RSA
203 !ENGINE_set_RSA(e, &atalla_rsa) ||
204 #endif
205 #ifndef OPENSSL_NO_DSA
206 !ENGINE_set_DSA(e, &atalla_dsa) ||
207 #endif
208 #ifndef OPENSSL_NO_DH
209 !ENGINE_set_DH(e, &atalla_dh) ||
210 #endif
211 !ENGINE_set_destroy_function(e, atalla_destroy) ||
212 !ENGINE_set_init_function(e, atalla_init) ||
213 !ENGINE_set_finish_function(e, atalla_finish) ||
214 !ENGINE_set_ctrl_function(e, atalla_ctrl) ||
215 !ENGINE_set_cmd_defns(e, atalla_cmd_defns))
216 return 0;
217
218 #ifndef OPENSSL_NO_RSA
219 /* We know that the "PKCS1_SSLeay()" functions hook properly
220 * to the atalla-specific mod_exp and mod_exp_crt so we use
221 * those functions. NB: We don't use ENGINE_openssl() or
222 * anything "more generic" because something like the RSAref
223 * code may not hook properly, and if you own one of these
224 * cards then you have the right to do RSA operations on it
225 * anyway! */
226 meth1 = RSA_PKCS1_SSLeay();
227 atalla_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
228 atalla_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
229 atalla_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
230 atalla_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
231 #endif
232
233 #ifndef OPENSSL_NO_DSA
234 /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
235 * bits. */
236 meth2 = DSA_OpenSSL();
237 atalla_dsa.dsa_do_sign = meth2->dsa_do_sign;
238 atalla_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
239 atalla_dsa.dsa_do_verify = meth2->dsa_do_verify;
240 #endif
241
242 #ifndef OPENSSL_NO_DH
243 /* Much the same for Diffie-Hellman */
244 meth3 = DH_OpenSSL();
245 atalla_dh.generate_key = meth3->generate_key;
246 atalla_dh.compute_key = meth3->compute_key;
247 #endif
248
249 /* Ensure the atalla error handling is set up */
250 ERR_load_ATALLA_strings();
251 return 1;
252 }
253
254 #ifdef OPENSSL_NO_DYNAMIC_ENGINE
255 static ENGINE *engine_atalla(void)
256 {
257 ENGINE *ret = ENGINE_new();
258 if(!ret)
259 return NULL;
260 if(!bind_helper(ret))
261 {
262 ENGINE_free(ret);
263 return NULL;
264 }
265 return ret;
266 }
267
268 void ENGINE_load_atalla(void)
269 {
270 /* Copied from eng_[openssl|dyn].c */
271 ENGINE *toadd = engine_atalla();
272 if(!toadd) return;
273 ENGINE_add(toadd);
274 ENGINE_free(toadd);
275 ERR_clear_error();
276 }
277 #endif
278
279 /* This is a process-global DSO handle used for loading and unloading
280 * the Atalla library. NB: This is only set (or unset) during an
281 * init() or finish() call (reference counts permitting) and they're
282 * operating with global locks, so this should be thread-safe
283 * implicitly. */
284 static DSO *atalla_dso = NULL;
285
286 /* These are the function pointers that are (un)set when the library has
287 * successfully (un)loaded. */
288 static tfnASI_GetHardwareConfig *p_Atalla_GetHardwareConfig = NULL;
289 static tfnASI_RSAPrivateKeyOpFn *p_Atalla_RSAPrivateKeyOpFn = NULL;
290 static tfnASI_GetPerformanceStatistics *p_Atalla_GetPerformanceStatistics = NULL;
291
292 /* These are the static string constants for the DSO file name and the function
293 * symbol names to bind to. Regrettably, the DSO name on *nix appears to be
294 * "atasi.so" rather than something more consistent like "libatasi.so". At the
295 * time of writing, I'm not sure what the file name on win32 is but clearly
296 * native name translation is not possible (eg libatasi.so on *nix, and
297 * atasi.dll on win32). For the purposes of testing, I have created a symbollic
298 * link called "libatasi.so" so that we can use native name-translation - a
299 * better solution will be needed. */
300 static const char *ATALLA_LIBNAME = NULL;
301 static const char *get_ATALLA_LIBNAME(void)
302 {
303 if(ATALLA_LIBNAME)
304 return ATALLA_LIBNAME;
305 return "atasi";
306 }
307 static void free_ATALLA_LIBNAME(void)
308 {
309 if(ATALLA_LIBNAME)
310 OPENSSL_free((void*)ATALLA_LIBNAME);
311 ATALLA_LIBNAME = NULL;
312 }
313 static long set_ATALLA_LIBNAME(const char *name)
314 {
315 free_ATALLA_LIBNAME();
316 return (((ATALLA_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
317 }
318 static const char *ATALLA_F1 = "ASI_GetHardwareConfig";
319 static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn";
320 static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
321
322 /* Destructor (complements the "ENGINE_atalla()" constructor) */
323 static int atalla_destroy(ENGINE *e)
324 {
325 free_ATALLA_LIBNAME();
326 /* Unload the atalla error strings so any error state including our
327 * functs or reasons won't lead to a segfault (they simply get displayed
328 * without corresponding string data because none will be found). */
329 ERR_unload_ATALLA_strings();
330 return 1;
331 }
332
333 /* (de)initialisation functions. */
334 static int atalla_init(ENGINE *e)
335 {
336 tfnASI_GetHardwareConfig *p1;
337 tfnASI_RSAPrivateKeyOpFn *p2;
338 tfnASI_GetPerformanceStatistics *p3;
339 /* Not sure of the origin of this magic value, but Ben's code had it
340 * and it seemed to have been working for a few people. :-) */
341 unsigned int config_buf[1024];
342
343 if(atalla_dso != NULL)
344 {
345 ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_ALREADY_LOADED);
346 goto err;
347 }
348 /* Attempt to load libatasi.so/atasi.dll/whatever. Needs to be
349 * changed unfortunately because the Atalla drivers don't have
350 * standard library names that can be platform-translated well. */
351 /* TODO: Work out how to actually map to the names the Atalla
352 * drivers really use - for now a symbollic link needs to be
353 * created on the host system from libatasi.so to atasi.so on
354 * unix variants. */
355 atalla_dso = DSO_load(NULL, get_ATALLA_LIBNAME(), NULL, 0);
356 if(atalla_dso == NULL)
357 {
358 ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_NOT_LOADED);
359 goto err;
360 }
361 if(!(p1 = (tfnASI_GetHardwareConfig *)DSO_bind_func(
362 atalla_dso, ATALLA_F1)) ||
363 !(p2 = (tfnASI_RSAPrivateKeyOpFn *)DSO_bind_func(
364 atalla_dso, ATALLA_F2)) ||
365 !(p3 = (tfnASI_GetPerformanceStatistics *)DSO_bind_func(
366 atalla_dso, ATALLA_F3)))
367 {
368 ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_NOT_LOADED);
369 goto err;
370 }
371 /* Copy the pointers */
372 p_Atalla_GetHardwareConfig = p1;
373 p_Atalla_RSAPrivateKeyOpFn = p2;
374 p_Atalla_GetPerformanceStatistics = p3;
375 /* Perform a basic test to see if there's actually any unit
376 * running. */
377 if(p1(0L, config_buf) != 0)
378 {
379 ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_UNIT_FAILURE);
380 goto err;
381 }
382 /* Everything's fine. */
383 return 1;
384 err:
385 if(atalla_dso)
386 DSO_free(atalla_dso);
387 p_Atalla_GetHardwareConfig = NULL;
388 p_Atalla_RSAPrivateKeyOpFn = NULL;
389 p_Atalla_GetPerformanceStatistics = NULL;
390 return 0;
391 }
392
393 static int atalla_finish(ENGINE *e)
394 {
395 free_ATALLA_LIBNAME();
396 if(atalla_dso == NULL)
397 {
398 ATALLAerr(ATALLA_F_ATALLA_FINISH,ATALLA_R_NOT_LOADED);
399 return 0;
400 }
401 if(!DSO_free(atalla_dso))
402 {
403 ATALLAerr(ATALLA_F_ATALLA_FINISH,ATALLA_R_UNIT_FAILURE);
404 return 0;
405 }
406 atalla_dso = NULL;
407 p_Atalla_GetHardwareConfig = NULL;
408 p_Atalla_RSAPrivateKeyOpFn = NULL;
409 p_Atalla_GetPerformanceStatistics = NULL;
410 return 1;
411 }
412
413 static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
414 {
415 int initialised = ((atalla_dso == NULL) ? 0 : 1);
416 switch(cmd)
417 {
418 case ATALLA_CMD_SO_PATH:
419 if(p == NULL)
420 {
421 ATALLAerr(ATALLA_F_ATALLA_CTRL,ERR_R_PASSED_NULL_PARAMETER);
422 return 0;
423 }
424 if(initialised)
425 {
426 ATALLAerr(ATALLA_F_ATALLA_CTRL,ATALLA_R_ALREADY_LOADED);
427 return 0;
428 }
429 return set_ATALLA_LIBNAME((const char *)p);
430 default:
431 break;
432 }
433 ATALLAerr(ATALLA_F_ATALLA_CTRL,ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED);
434 return 0;
435 }
436
437 static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
438 const BIGNUM *m, BN_CTX *ctx)
439 {
440 /* I need somewhere to store temporary serialised values for
441 * use with the Atalla API calls. A neat cheat - I'll use
442 * BIGNUMs from the BN_CTX but access their arrays directly as
443 * byte arrays <grin>. This way I don't have to clean anything
444 * up. */
445 BIGNUM *modulus;
446 BIGNUM *exponent;
447 BIGNUM *argument;
448 BIGNUM *result;
449 RSAPrivateKey keydata;
450 int to_return, numbytes;
451
452 modulus = exponent = argument = result = NULL;
453 to_return = 0; /* expect failure */
454
455 if(!atalla_dso)
456 {
457 ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_NOT_LOADED);
458 goto err;
459 }
460 /* Prepare the params */
461 BN_CTX_start(ctx);
462 modulus = BN_CTX_get(ctx);
463 exponent = BN_CTX_get(ctx);
464 argument = BN_CTX_get(ctx);
465 result = BN_CTX_get(ctx);
466 if (!result)
467 {
468 ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_BN_CTX_FULL);
469 goto err;
470 }
471 if(!bn_wexpand(modulus, m->top) || !bn_wexpand(exponent, m->top) ||
472 !bn_wexpand(argument, m->top) || !bn_wexpand(result, m->top))
473 {
474 ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_BN_EXPAND_FAIL);
475 goto err;
476 }
477 /* Prepare the key-data */
478 memset(&keydata, 0,sizeof keydata);
479 numbytes = BN_num_bytes(m);
480 memset(exponent->d, 0, numbytes);
481 memset(modulus->d, 0, numbytes);
482 BN_bn2bin(p, (unsigned char *)exponent->d + numbytes - BN_num_bytes(p));
483 BN_bn2bin(m, (unsigned char *)modulus->d + numbytes - BN_num_bytes(m));
484 keydata.privateExponent.data = (unsigned char *)exponent->d;
485 keydata.privateExponent.len = numbytes;
486 keydata.modulus.data = (unsigned char *)modulus->d;
487 keydata.modulus.len = numbytes;
488 /* Prepare the argument */
489 memset(argument->d, 0, numbytes);
490 memset(result->d, 0, numbytes);
491 BN_bn2bin(a, (unsigned char *)argument->d + numbytes - BN_num_bytes(a));
492 /* Perform the operation */
493 if(p_Atalla_RSAPrivateKeyOpFn(&keydata, (unsigned char *)result->d,
494 (unsigned char *)argument->d,
495 keydata.modulus.len) != 0)
496 {
497 ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_REQUEST_FAILED);
498 goto err;
499 }
500 /* Convert the response */
501 BN_bin2bn((unsigned char *)result->d, numbytes, r);
502 to_return = 1;
503 err:
504 BN_CTX_end(ctx);
505 return to_return;
506 }
507
508 #ifndef OPENSSL_NO_RSA
509 static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
510 {
511 int to_return = 0;
512
513 if(!atalla_dso)
514 {
515 ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_NOT_LOADED);
516 goto err;
517 }
518 if(!rsa->d || !rsa->n)
519 {
520 ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_MISSING_KEY_COMPONENTS);
521 goto err;
522 }
523 to_return = atalla_mod_exp(r0, I, rsa->d, rsa->n, ctx);
524 err:
525 return to_return;
526 }
527 #endif
528
529 #ifndef OPENSSL_NO_DSA
530 /* This code was liberated and adapted from the commented-out code in
531 * dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration
532 * (it doesn't have a CRT form for RSA), this function means that an
533 * Atalla system running with a DSA server certificate can handshake
534 * around 5 or 6 times faster/more than an equivalent system running with
535 * RSA. Just check out the "signs" statistics from the RSA and DSA parts
536 * of "openssl speed -engine atalla dsa1024 rsa1024". */
537 static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
538 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
539 BN_CTX *ctx, BN_MONT_CTX *in_mont)
540 {
541 BIGNUM t;
542 int to_return = 0;
543
544 BN_init(&t);
545 /* let rr = a1 ^ p1 mod m */
546 if (!atalla_mod_exp(rr,a1,p1,m,ctx)) goto end;
547 /* let t = a2 ^ p2 mod m */
548 if (!atalla_mod_exp(&t,a2,p2,m,ctx)) goto end;
549 /* let rr = rr * t mod m */
550 if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
551 to_return = 1;
552 end:
553 BN_free(&t);
554 return to_return;
555 }
556
557 static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
558 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
559 BN_MONT_CTX *m_ctx)
560 {
561 return atalla_mod_exp(r, a, p, m, ctx);
562 }
563 #endif
564
565 /* This function is aliased to mod_exp (with the mont stuff dropped). */
566 static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
567 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
568 {
569 return atalla_mod_exp(r, a, p, m, ctx);
570 }
571
572 #ifndef OPENSSL_NO_DH
573 /* This function is aliased to mod_exp (with the dh and mont dropped). */
574 static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r,
575 const BIGNUM *a, const BIGNUM *p,
576 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
577 {
578 return atalla_mod_exp(r, a, p, m, ctx);
579 }
580 #endif
581
582 /* This stuff is needed if this ENGINE is being compiled into a self-contained
583 * shared-library. */
584 #ifndef OPENSSL_NO_DYNAMIC_ENGINE
585 static int bind_fn(ENGINE *e, const char *id)
586 {
587 if(id && (strcmp(id, engine_atalla_id) != 0))
588 return 0;
589 if(!bind_helper(e))
590 return 0;
591 return 1;
592 }
593 IMPLEMENT_DYNAMIC_CHECK_FN()
594 IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
595 #endif /* OPENSSL_NO_DYNAMIC_ENGINE */
596
597 #endif /* !OPENSSL_NO_HW_ATALLA */
598 #endif /* !OPENSSL_NO_HW */