fix formatting of automatically generated error section
[oweals/openssl.git] / crypto / engine / hw_atalla.c
index 5716c2f0b9dc0366e88ae715e83cf3078af289f5..030d5a908c167e612da62b115189207ea6b36b59 100644 (file)
@@ -3,7 +3,7 @@
  * project 2000.
  */
 /* ====================================================================
- * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2001 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -71,6 +71,7 @@
 #include "vendor_defns/atalla.h"
 #endif
 
+static int atalla_destroy(ENGINE *e);
 static int atalla_init(ENGINE *e);
 static int atalla_finish(ENGINE *e);
 static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
@@ -215,9 +216,18 @@ static void atalla_load_error_strings(void)
                ERR_load_strings(atalla_err_lib,atalla_str_functs);
                }
        }
+static void atalla_unload_error_strings(void)
+       {
+       if (atalla_err_lib >= 0)
+               {
+               ERR_unload_strings(atalla_err_lib,atalla_str_functs);
+               atalla_err_lib = -1;
+               }
+       }
 #else
 #define ATALLAerr(f,r)                                 /* NOP */
 static void atalla_load_error_strings(void) { }                /* NOP */
+static void atalla_unload_error_strings(void) { }      /* NOP */
 #endif
 
 /* Constants used when creating the ENGINE */
@@ -248,7 +258,7 @@ static int bind_helper(ENGINE *e)
 #ifndef OPENSSL_NO_DH
                        !ENGINE_set_DH(e, &atalla_dh) ||
 #endif
-                       !ENGINE_set_BN_mod_exp(e, atalla_mod_exp) ||
+                       !ENGINE_set_destroy_function(e, atalla_destroy) ||
                        !ENGINE_set_init_function(e, atalla_init) ||
                        !ENGINE_set_finish_function(e, atalla_finish) ||
                        !ENGINE_set_ctrl_function(e, atalla_ctrl) ||
@@ -291,9 +301,7 @@ static int bind_helper(ENGINE *e)
        return 1;
        }
 
-/* As this is only ever called once, there's no need for locking
- * (indeed - the lock will already be held by our caller!!!) */
-ENGINE *ENGINE_atalla(void)
+static ENGINE *engine_atalla(void)
        {
        ENGINE *ret = ENGINE_new();
        if(!ret)
@@ -306,6 +314,16 @@ ENGINE *ENGINE_atalla(void)
        return ret;
        }
 
+void ENGINE_load_atalla(void)
+       {
+       /* Copied from eng_[openssl|dyn].c */
+       ENGINE *toadd = engine_atalla();
+       if(!toadd) return;
+       ENGINE_add(toadd);
+       ENGINE_free(toadd);
+       ERR_clear_error();
+       }
+
 /* This is a process-global DSO handle used for loading and unloading
  * the Atalla library. NB: This is only set (or unset) during an
  * init() or finish() call (reference counts permitting) and they're
@@ -333,6 +351,16 @@ static const char *ATALLA_F1 = "ASI_GetHardwareConfig";
 static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn";
 static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
 
+/* Destructor (complements the "ENGINE_atalla()" constructor) */
+static int atalla_destroy(ENGINE *e)
+       {
+       /* Unload the atalla error strings so any error state including our
+        * functs or reasons won't lead to a segfault (they simply get displayed
+        * without corresponding string data because none will be found). */
+       atalla_unload_error_strings();
+       return 1;
+       }
+
 /* (de)initialisation functions. */
 static int atalla_init(ENGINE *e)
        {