New OID for X509 usage: pseudonym
[oweals/openssl.git] / crypto / engine / hw_atalla.c
index 88719beb791573f7e465e0ccf06a18ae75ea9779..696cfcf156fcac1bd5ffa4ef930e02eaa07f55dd 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,9 @@
 #include "vendor_defns/atalla.h"
 #endif
 
+#define ATALLA_LIB_NAME "atalla engine"
+#include "hw_atalla_err.c"
+
 static int atalla_destroy(ENGINE *e);
 static int atalla_init(ENGINE *e);
 static int atalla_finish(ENGINE *e);
@@ -168,68 +171,6 @@ static DH_METHOD atalla_dh =
        };
 #endif
 
-#ifndef OPENSSL_NO_ERR
-/* Error function codes for use in atalla operation */
-#define ATALLA_F_ATALLA_INIT                   100
-#define ATALLA_F_ATALLA_FINISH                 101
-#define ATALLA_F_ATALLA_CTRL                   102
-#define ATALLA_F_ATALLA_MOD_EXP                        103
-#define ATALLA_F_ATALLA_RSA_MOD_EXP            104
-/* Error reason codes */
-#define ATALLA_R_ALREADY_LOADED                        105
-#define ATALLA_R_NOT_LOADED                    106
-#define ATALLA_R_UNIT_FAILURE                  107
-#define ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED  108
-#define ATALLA_R_BN_CTX_FULL                   109
-#define ATALLA_R_BN_EXPAND_FAIL                        110
-#define ATALLA_R_REQUEST_FAILED                        111
-#define ATALLA_R_MISSING_KEY_COMPONENTS                112
-static ERR_STRING_DATA atalla_str_functs[] =
-       {
-       /* This first element is changed to match the dynamic 'lib' number */
-{ERR_PACK(0,0,0),                              "atalla engine code"},
-{ERR_PACK(0,ATALLA_F_ATALLA_INIT,0),           "atalla_init"},
-{ERR_PACK(0,ATALLA_F_ATALLA_FINISH,0),         "atalla_finish"},
-{ERR_PACK(0,ATALLA_F_ATALLA_CTRL,0),           "atalla_ctrl"},
-{ERR_PACK(0,ATALLA_F_ATALLA_MOD_EXP,0),                "atalla_mod_exp"},
-{ERR_PACK(0,ATALLA_F_ATALLA_RSA_MOD_EXP,0),"atalla_rsa_mod_exp"},
-{ATALLA_R_ALREADY_LOADED               ,"already loaded"},
-{ATALLA_R_UNIT_FAILURE                 ,"unit failure"},
-{ATALLA_R_NOT_LOADED,                  "not loaded"},
-{ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"control command not implemented"},
-{ATALLA_R_BN_CTX_FULL                  ,"BN_CTX full"},
-{ATALLA_R_BN_EXPAND_FAIL               ,"BN_expand failed"},
-{ATALLA_R_REQUEST_FAILED               ,"request failed"},
-{ATALLA_R_MISSING_KEY_COMPONENTS       ,"missing key components"},
-{0,NULL}
-       };
-/* The library number we obtain dynamically from the ERR code */
-static int atalla_err_lib = -1;
-#define ATALLAerr(f,r) ERR_PUT_error(atalla_err_lib,(f),(r),__FILE__,__LINE__)
-static void atalla_load_error_strings(void)
-       {
-       if (atalla_err_lib < 0)
-               {
-               if((atalla_err_lib = ERR_get_next_error_library()) <= 0)
-                       return;
-               atalla_str_functs[0].error = ERR_PACK(atalla_err_lib, 0, 0);
-               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 */
 static const char *engine_atalla_id = "atalla";
 static const char *engine_atalla_name = "Atalla hardware engine support";
@@ -258,7 +199,6 @@ 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) ||
@@ -298,13 +238,11 @@ static int bind_helper(ENGINE *e)
 #endif
 
        /* Ensure the atalla error handling is set up */
-       atalla_load_error_strings();
+       ERR_load_ATALLA_strings();
        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)
@@ -317,6 +255,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
@@ -350,7 +298,7 @@ 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();
+       ERR_unload_ATALLA_strings();
        return 1;
        }