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