ssl/libcrypto/src/crypto/libcrypto_wsd.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
       
     3 
       
     4 Redistribution and use in source and binary forms, with or without 
       
     5 modification, are permitted provided that the following conditions are met:
       
     6 
       
     7 * Redistributions of source code must retain the above copyright notice, this 
       
     8   list of conditions and the following disclaimer.
       
     9 * Redistributions in binary form must reproduce the above copyright notice, 
       
    10   this list of conditions and the following disclaimer in the documentation 
       
    11   and/or other materials provided with the distribution.
       
    12 * Neither the name of Nokia Corporation nor the names of its contributors 
       
    13   may be used to endorse or promote products derived from this software 
       
    14   without specific prior written permission.
       
    15 
       
    16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
       
    17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
       
    18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
       
    19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
       
    20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
       
    21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
       
    22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
       
    23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
       
    24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
       
    25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    26 
       
    27 Description:
       
    28 */
       
    29 
       
    30 #include <e32std.h>
       
    31 #include <_ansi.h>
       
    32 #include <libcrypto_wsd.h>
       
    33 #include <stdlib.h>
       
    34 #include <openssl/objects.h>
       
    35 #include <openssl/bn.h>
       
    36 #include <openssl/buffer.h>
       
    37 #include <openssl/comp.h>
       
    38 #include <openssl/conf.h>
       
    39 #include <openssl/dh.h>
       
    40 #include <openssl/dsa.h>
       
    41 #include <openssl/dso.h>
       
    42 #include <openssl/engine.h>
       
    43 #include <openssl/err.h>
       
    44 #include <openssl/evp.h>
       
    45 #include <openssl/ocsp.h>
       
    46 #include <openssl/pem.h>
       
    47 #include <openssl/pkcs7.h>
       
    48 #include <openssl/pkcs12.h>
       
    49 #include <openssl/rand.h>
       
    50 #include <openssl/rsa.h>
       
    51 #include <openssl/ui.h>
       
    52 #include <openssl/x509.h>
       
    53 #include <openssl/x509v3.h>
       
    54 #include <openssl/lhash.h>
       
    55 #include <openssl/crypto.h>
       
    56 #include "obj_dat.h"
       
    57 //#include "libcrypto_wsd_solution.h"
       
    58 #ifdef __WINSCW__ 
       
    59 #include <emulator.h> //GetProcAddress, GetModuleHandle
       
    60 #include "pls.h" // For emulator WSD API 
       
    61 const TUid KLibdlUid3 = {0x10281F35}; // This is the UID of the library
       
    62 #endif//defined(__WINSCW__) || defined(__WINS__)
       
    63 
       
    64 #ifdef __cplusplus
       
    65 extern "C" 
       
    66 {
       
    67 #endif
       
    68 extern CRYPTO_EX_DATA_IMPL temp_s_impl_default;
       
    69 extern BIO_METHOD temp_s_mem_method;
       
    70 extern BIO_METHOD temp_s_null_method;
       
    71 extern BIO_METHOD temp_s_methods_fdp;
       
    72 extern BIO_METHOD temp_s_methods_sockp;
       
    73 extern BIO_METHOD temp_s_methods_filep;
       
    74 extern BIO_METHOD temp_s_methods_dgramp;
       
    75 extern BIO_METHOD temp_s_methods_connectp;
       
    76 extern BIO_METHOD temp_s_methods_biop;
       
    77 extern BIO_METHOD temp_s_methods_acceptp;
       
    78 extern BIO_METHOD temp_s_methods_md;
       
    79 extern BIO_METHOD temp_s_methods_b64;
       
    80 extern BIO_METHOD temp_s_methods_enc;
       
    81 extern BIO_METHOD temp_s_methods_ok;
       
    82 extern COMP_METHOD temp_s_rle_method;
       
    83 extern COMP_METHOD temp_s_zlib_method_nozlib;
       
    84 extern COMP_METHOD temp_s_zlib_stateful_method;
       
    85 extern CONF_METHOD temp_s_default_method;
       
    86 extern CONF_METHOD temp_s_WIN32_method;
       
    87 extern DH_METHOD temp_s_dh_ossl;
       
    88 extern DSA_METHOD temp_s_openssl_dsa_meth;
       
    89 //extern DSO_METHOD temp_s_dso_meth_dl;
       
    90 extern DSO_METHOD temp_s_dso_meth_dlfcn;
       
    91 extern DSO_METHOD temp_s_dso_meth_null;
       
    92 extern RSA_METHOD temp_s_rsa_pkcs1_eay_meth;
       
    93 extern STORE_METHOD temp_s_store_memory;
       
    94 extern UI_METHOD temp_s_ui_openssl;
       
    95 extern X509V3_CONF_METHOD temp_s_nconf_method;
       
    96 extern X509V3_CONF_METHOD temp_s_conf_lhash_method;
       
    97 extern ASN1_METHOD temp_s_meth;
       
    98 extern ASN1_METHOD temp_s_method;
       
    99 extern RAND_METHOD temp_g_rand_ssleay_meth;
       
   100 extern X509_LOOKUP_METHOD temp_g_x509_file_lookup;
       
   101 extern X509_LOOKUP_METHOD temp_g_x509_dir_lookup;
       
   102 
       
   103 extern void *default_malloc_ex(size_t num, const char *file, int line);
       
   104 extern void *default_realloc_ex(void *str, size_t num,
       
   105         const char *file, int line);
       
   106 extern void *default_malloc_locked_ex(size_t num, const char *file, int line);
       
   107 
       
   108 extern const ERR_STRING_DATA temp_ASN1_str_functs[108];
       
   109 extern const ERR_STRING_DATA temp_ASN1_str_reasons[99];
       
   110 extern const ERR_STRING_DATA temp_CRYPTO_str_functs[10];
       
   111 extern const ERR_STRING_DATA temp_CRYPTO_str_reasons[2];
       
   112 extern const ERR_STRING_DATA temp_BIO_str_functs[33];
       
   113 extern const ERR_STRING_DATA temp_BIO_str_reasons[30];	
       
   114 extern const ERR_STRING_DATA temp_BN_str_functs[39];
       
   115 extern const ERR_STRING_DATA temp_BN_str_reasons[18];
       
   116 extern const ERR_STRING_DATA temp_BUF_str_functs[7];
       
   117 extern const ERR_STRING_DATA temp_BUF_str_reasons[1];
       
   118 extern const ERR_STRING_DATA temp_COMP_str_functs[1];
       
   119 extern const ERR_STRING_DATA temp_COMP_str_reasons[1];
       
   120 extern const ERR_STRING_DATA temp_CONF_str_functs[22];
       
   121 extern const ERR_STRING_DATA temp_CONF_str_reasons[16];
       
   122 extern const ERR_STRING_DATA temp_DH_str_functs[8];
       
   123 extern const ERR_STRING_DATA temp_DH_str_reasons[5];
       
   124 extern const ERR_STRING_DATA temp_DSA_str_functs[15];
       
   125 extern const ERR_STRING_DATA temp_DSA_str_reasons[5];
       
   126 extern const ERR_STRING_DATA temp_DSO_str_functs[38];
       
   127 extern const ERR_STRING_DATA temp_DSO_str_reasons[18];
       
   128 extern const ERR_STRING_DATA temp_ENGINE_str_functs[37];
       
   129 extern const ERR_STRING_DATA temp_ENGINE_str_reasons[40];
       
   130 extern const ERR_STRING_DATA temp_ERR_str_libraries[25];
       
   131 extern const ERR_STRING_DATA temp_ERR_str_functs[11];
       
   132 extern const ERR_STRING_DATA temp_ERR_str_reasons[36];
       
   133 extern const ERR_STRING_DATA temp_EVP_str_functs[36];
       
   134 extern const ERR_STRING_DATA temp_EVP_str_reasons[45];
       
   135 extern const ERR_STRING_DATA temp_OBJ_str_functs[8];
       
   136 extern const ERR_STRING_DATA temp_OBJ_str_reasons[3];
       
   137 extern const ERR_STRING_DATA temp_OCSP_str_functs[18];
       
   138 extern const ERR_STRING_DATA temp_OCSP_str_reasons[31];
       
   139 extern const ERR_STRING_DATA temp_PEM_str_functs[27];
       
   140 extern const ERR_STRING_DATA temp_PEM_str_reasons[17];
       
   141 extern const ERR_STRING_DATA temp_PKCS7_str_functs[29];
       
   142 extern const ERR_STRING_DATA temp_PKCS7_str_reasons[47];
       
   143 extern const  ERR_STRING_DATA temp_PKCS12_str_functs[30];
       
   144 extern const ERR_STRING_DATA temp_PKCS12_str_reasons[23];
       
   145 extern const ERR_STRING_DATA temp_RAND_str_functs[3];
       
   146 extern const ERR_STRING_DATA temp_RAND_str_reasons[2];
       
   147 extern const ERR_STRING_DATA temp_RSA_str_functs[38];
       
   148 extern const ERR_STRING_DATA temp_RSA_str_reasons[42];
       
   149 extern const ERR_STRING_DATA temp_UI_str_functs[13];
       
   150 extern const ERR_STRING_DATA temp_UI_str_reasons[8];
       
   151 extern const ERR_STRING_DATA temp_X509_str_functs[46];
       
   152 extern const ERR_STRING_DATA temp_X509_str_reasons[24];
       
   153 extern const ERR_STRING_DATA temp_X509V3_str_functs[57];
       
   154 extern const ERR_STRING_DATA temp_X509V3_str_reasons[61];
       
   155 extern const DES_cblock temp_weak_keys[16];
       
   156 extern const ASN1_METHOD temp_ia5string_meth;
       
   157 extern const ASN1_METHOD temp_bit_string_meth;
       
   158 #ifdef __cplusplus
       
   159 }
       
   160 #endif
       
   161 
       
   162 
       
   163 libcrypto_global_struct *libcrypto_ImpurePtr()
       
   164 {
       
   165 	  /*struct libcrypto_global_struct *g = (struct libcrypto_global_struct *)Pls();
       
   166 	
       
   167 	  if(g)
       
   168 		return g;
       
   169 	
       
   170 	  g = (struct libcrypto_global_struct *)
       
   171 	          AllocatePls(sizeof(struct libcrypto_global_struct));
       
   172 	          
       
   173 		//new (g) struct libcrypto_global_struct;
       
   174 		
       
   175 	  Mem::FillZ(g,sizeof(struct libcrypto_global_struct));
       
   176 	  libcrypto_Init(g);
       
   177 
       
   178 		TInt err = SetPls(g);
       
   179 	
       
   180 	  if(g == 0 || err)
       
   181 		User::Panic(_L("LIBCRYPTO-INIT"),err);
       
   182 	  return g;*/
       
   183 	  libcrypto_global_struct *p = Pls<libcrypto_global_struct>(KLibdlUid3,libcrypto_Init);
       
   184 	  return p;
       
   185 }
       
   186 
       
   187 int libcrypto_Init(libcrypto_global_struct *g)
       
   188 {
       
   189 	  if(g)
       
   190 	  {
       
   191 	    memcpy(&(g->GET_WSD_VAR_NAME(ia5string_meth,a_meth,s)),&temp_ia5string_meth,sizeof(ASN1_METHOD));
       
   192 	    memcpy(&(g->GET_WSD_VAR_NAME(bit_string_meth,a_meth,s)),&temp_bit_string_meth,sizeof(ASN1_METHOD));
       
   193 		  
       
   194 		  g->GET_WSD_VAR_NAME(stable,a_strnid,s)= NULL;
       
   195       g->GET_WSD_VAR_NAME(global_mask,a_strnid,s)=0xFFFFFFFFL;
       
   196       g->GET_WSD_VAR_NAME(app_locks,cryptlib,s)=NULL;			
       
   197       g->GET_WSD_VAR_NAME(dyn_locks,cryptlib,s)=NULL;
       
   198       g->GET_WSD_VAR_NAME(allow_customize,mem,s)=1;
       
   199       g->GET_WSD_VAR_NAME(allow_customize_debug,mem,s)=1;
       
   200       g->GET_WSD_VAR_NAME(mh_mode,mem_dbg,s)=0x0;
       
   201       g->GET_WSD_VAR_NAME(order,mem_dbg,s)=0x0;
       
   202       g->GET_WSD_VAR_NAME(mh,mem_dbg,s)= NULL;
       
   203       g->GET_WSD_VAR_NAME(amih,mem_dbg,s)=NULL;
       
   204       g->GET_WSD_VAR_NAME(options,mem_dbg,s)=
       
   205       #if defined(CRYPTO_MDEBUG_TIME) || defined(CRYPTO_MDEBUG_ALL)
       
   206 	    V_CRYPTO_MDEBUG_TIME |
       
   207       #endif
       
   208       #if defined(CRYPTO_MDEBUG_THREAD) || defined(CRYPTO_MDEBUG_ALL)
       
   209 	    V_CRYPTO_MDEBUG_THREAD |
       
   210       #endif
       
   211 	    0;
       
   212       g->GET_WSD_VAR_NAME(num_disable,mem_dbg,s)=0;
       
   213       g->GET_WSD_VAR_NAME(disabling_thread,mem_dbg,s)=0;
       
   214       g->GET_WSD_VAR_NAME(impl,ex_data,s)=NULL;
       
   215       g->GET_WSD_VAR_NAME(ex_class,ex_data,s)=CRYPTO_EX_INDEX_USER;
       
   216       g->GET_WSD_VAR_NAME(ex_data,ex_data,s)=NULL;
       
   217   		
       
   218   		
       
   219   			
       
   220   	  g->GET_WSD_VAR_NAME(init,bn_lib,s) = 0;		
       
   221   		
       
   222   		g->GET_WSD_VAR_NAME(data_one,bn_lib,s)=1L;
       
   223   		g->GET_WSD_VAR_NAME(const_one,bn_lib,s).d=&(g->GET_WSD_VAR_NAME(data_one,bn_lib,s));
       
   224   		g->GET_WSD_VAR_NAME(const_one,bn_lib,s).top = 1;
       
   225   		g->GET_WSD_VAR_NAME(const_one,bn_lib,s).dmax = 1;
       
   226   		g->GET_WSD_VAR_NAME(const_one,bn_lib,s).neg = 0;
       
   227   		g->GET_WSD_VAR_NAME(const_one,bn_lib,s).flags = BN_FLG_STATIC_DATA;
       
   228   		g->GET_WSD_VAR_NAME(_is_set_256_data,bn_nist,s)=0;
       
   229       g->GET_WSD_VAR_NAME(_is_set_384_data,bn_nist,s)=0;
       
   230   		g->GET_WSD_VAR_NAME(zlib_stateful_ex_idx,c_zlib,s)=-1;
       
   231   		g->GET_WSD_VAR_NAME(p_compress,c_zlib,s) = NULL;
       
   232       g->GET_WSD_VAR_NAME(p_inflateEnd,c_zlib,s) = NULL;
       
   233       g->GET_WSD_VAR_NAME(p_inflate,c_zlib,s) = NULL;
       
   234       g->GET_WSD_VAR_NAME(p_inflateInit_,c_zlib,s) = NULL;
       
   235       g->GET_WSD_VAR_NAME(p_deflateEnd,c_zlib,s)=NULL;
       
   236       g->GET_WSD_VAR_NAME(p_deflate,c_zlib,s)=NULL;
       
   237       g->GET_WSD_VAR_NAME(p_deflateInit_,c_zlib,s)=NULL;
       
   238       g->GET_WSD_VAR_NAME(zlib_loaded ,c_zlib,s)=0;
       
   239       g->GET_WSD_VAR_NAME(zlib_dso ,c_zlib,s)=NULL;
       
   240       g->GET_WSD_VAR_NAME(supported_modules,conf_mod,s)=NULL;
       
   241       g->GET_WSD_VAR_NAME(initialized_modules,conf_mod,s)=NULL;
       
   242       g->GET_WSD_VAR_NAME(openssl_configured,conf_sap,s)=0;
       
   243       g->GET_WSD_VAR_NAME(init,ecb_enc,s)=1;
       
   244       
       
   245       memset(&(g->GET_WSD_VAR_NAME(buf,ecb_enc,s)),0,32);
       
   246 
       
   247   		g->GET_WSD_VAR_NAME(net,enc_read,s)=NULL;
       
   248       g->GET_WSD_VAR_NAME(unnet,enc_read,s)=NULL;
       
   249       g->GET_WSD_VAR_NAME(unnet_start,enc_read,s)=0;
       
   250       g->GET_WSD_VAR_NAME(unnet_left,enc_read,s)=0;
       
   251       g->GET_WSD_VAR_NAME(tmpbuf,enc_read,s)=NULL;
       
   252   		g->GET_WSD_VAR_NAME(outbuf,enc_write,s)=NULL;
       
   253       g->GET_WSD_VAR_NAME(start,enc_write,s)=1;
       
   254       
       
   255       memcpy(&(g->GET_WSD_VAR_NAME(weak_keys,set_key_c,s)),&temp_weak_keys,16);
       
   256          
       
   257       g->GET_WSD_VAR_NAME(cleanup_stack,eng_lib,s)= NULL;
       
   258       g->GET_WSD_VAR_NAME(internal_static_hack,eng_lib,s)=0;
       
   259       g->GET_WSD_VAR_NAME(engine_list_head,eng_list,s)=NULL;
       
   260       g->GET_WSD_VAR_NAME(engine_list_tail,eng_list,s)=NULL;
       
   261       g->GET_WSD_VAR_NAME(table_flags,eng_table,s)=0;
       
   262       g->GET_WSD_VAR_NAME(rsa_table,tb_rsa,s)=NULL;
       
   263       g->GET_WSD_VAR_NAME(dsa_table,tb_dsa,s)=NULL;
       
   264       g->GET_WSD_VAR_NAME(ecdh_table,tb_ecdh,s)=NULL;
       
   265       g->GET_WSD_VAR_NAME(ecdsa_table,tb_ecdsa,s)=NULL;
       
   266       g->GET_WSD_VAR_NAME(rand_table,tb_rand,s)=NULL;
       
   267       g->GET_WSD_VAR_NAME(digest_table,tb_digest,s)=NULL;
       
   268       g->GET_WSD_VAR_NAME(store_table,tb_store,s)=NULL;
       
   269       g->GET_WSD_VAR_NAME(dh_table,tb_dh,s)=NULL;
       
   270       g->GET_WSD_VAR_NAME(cipher_table,tb_cipher,s)=NULL;
       
   271   		 
       
   272   		g->GET_WSD_VAR_NAME(initialized_engines,eng_cnf,s)=NULL;
       
   273   		g->GET_WSD_VAR_NAME(dynamic_ex_data_idx,eng_dyn,s)= -1;
       
   274   		g->GET_WSD_VAR_NAME(err_fns,err,s)=NULL;
       
   275   		g->GET_WSD_VAR_NAME(pbe_algs,evp_pbe,s)=NULL; 
       
   276   		g->GET_WSD_VAR_NAME(int_error_hash,err,s)=NULL;
       
   277       g->GET_WSD_VAR_NAME(int_thread_hash,err,s)=NULL;
       
   278       g->GET_WSD_VAR_NAME(int_thread_hash_references,err,s)=0;
       
   279       g->GET_WSD_VAR_NAME(int_err_library_number,err,s)=ERR_LIB_USER;
       
   280       g->GET_WSD_VAR_NAME(init,err,s)=1;
       
   281 
       
   282       g->GET_WSD_VAR_NAME(names_lh,o_names,s)=NULL;
       
   283       g->GET_WSD_VAR_NAME(names_type_num,o_names,s)=OBJ_NAME_TYPE_NUM;
       
   284       g->GET_WSD_VAR_NAME(name_funcs_stack,o_names,s)=NULL;
       
   285       g->GET_WSD_VAR_NAME(free_type,o_names,s)=0;
       
   286       g->GET_WSD_VAR_NAME(new_nid,obj_dat,s)=NUM_NID;
       
   287       g->GET_WSD_VAR_NAME(added,obj_dat,s)=NULL;
       
   288          
       
   289       g->GET_WSD_VAR_NAME(state_num,md_rand,s)=0;
       
   290       g->GET_WSD_VAR_NAME(state_index,md_rand,s)=0;
       
   291       memset(&(g->GET_WSD_VAR_NAME(state,md_rand,s)),0,1023+MD_DIGEST_LENGTH);
       
   292       memset(&(g->GET_WSD_VAR_NAME(md,md_rand,s)),0,MD_DIGEST_LENGTH);
       
   293       g->GET_WSD_VAR_NAME(md_count,md_rand,s)[0]=0;
       
   294       g->GET_WSD_VAR_NAME(md_count,md_rand,s)[1]=0;
       
   295       g->GET_WSD_VAR_NAME(entropy,md_rand,s)=0;
       
   296       g->GET_WSD_VAR_NAME(initialized,md_rand,s)=0;
       
   297       g->GET_WSD_VAR_NAME(crypto_lock_rand,md_rand,s)=0;
       
   298       g->GET_WSD_VAR_NAME(locking_thread,md_rand,s)=0;
       
   299       g->GET_WSD_VAR_NAME(default_RAND_meth,rand_lib,s)=NULL;
       
   300          
       
   301       g->GET_WSD_VAR_NAME(tty_in,ui_openssl,s)=NULL;
       
   302       g->GET_WSD_VAR_NAME(tty_out,ui_openssl,s)=NULL;
       
   303       g->GET_WSD_VAR_NAME(is_a_tty,ui_openssl,s)=0;
       
   304       g->GET_WSD_VAR_NAME(ext_nid_list,x509_req,s)[0]= NID_ext_req;
       
   305       g->GET_WSD_VAR_NAME(ext_nid_list,x509_req,s)[1]= NID_ms_ext_req,
       
   306       g->GET_WSD_VAR_NAME(ext_nid_list,x509_req,s)[2]= NID_undef;
       
   307       g->GET_WSD_VAR_NAME(ext_nids,x509_req,s)=(int *)&(g->GET_WSD_VAR_NAME(ext_nid_list,x509_req,s));
       
   308          
       
   309       g->GET_WSD_VAR_NAME(trtable,x509_trs,s)=NULL;
       
   310       g->GET_WSD_VAR_NAME(param_table,x509_vpm,s)=NULL;
       
   311       g->GET_WSD_VAR_NAME(ext_list,v3_lib,s)=NULL;
       
   312       g->GET_WSD_VAR_NAME(xptable,v3_purp,s)=NULL;
       
   313 
       
   314       g->GET_WSD_VAR_NAME(default_CONF_method,conf_lib,s)=NULL;
       
   315       g->GET_WSD_VAR_NAME(default_DH_method,dh_lib,s)=NULL;
       
   316       g->GET_WSD_VAR_NAME(default_DSA_method,dsa_lib,s)=NULL;
       
   317       g->GET_WSD_VAR_NAME(default_DSO_meth,dso_lib,s)=NULL;
       
   318       g->GET_WSD_VAR_NAME(default_RSA_meth,rsa_lib,s)=NULL;
       
   319       g->GET_WSD_VAR_NAME(default_UI_meth,ui_lib,s)=NULL;
       
   320       g->GET_WSD_VAR_NAME(stirred_pool,md_rand,s)=0;
       
   321 
       
   322       g->malloc_func=malloc;
       
   323       g->malloc_ex_func=default_malloc_ex;
       
   324       g->realloc_func=realloc;
       
   325       g->realloc_ex_func=default_realloc_ex;
       
   326       g->free_func_openssl= free;
       
   327       g->malloc_locked_func= malloc;
       
   328       g->malloc_locked_ex_func= default_malloc_locked_ex;
       
   329       g->free_locked_func= free;
       
   330 
       
   331 #ifdef CRYPTO_MDEBUG
       
   332       g->malloc_debug_func=CRYPTO_dbg_malloc;
       
   333       g->realloc_debug_func=CRYPTO_dbg_realloc;
       
   334       g->free_debug_func=CRYPTO_dbg_free;
       
   335       g->set_debug_options_func=CRYPTO_dbg_set_options;
       
   336       g->get_debug_options_func=CRYPTO_dbg_get_options;
       
   337 #else
       
   338       g->malloc_debug_func=NULL;
       
   339       g->realloc_debug_func=NULL;
       
   340       g->free_debug_func=NULL;
       
   341       g->set_debug_options_func=NULL;
       
   342       g->get_debug_options_func=NULL;
       
   343 #endif
       
   344       g->locking_callback=NULL;
       
   345       g->add_lock_callback=NULL;
       
   346       g->id_callback=NULL;
       
   347       g->dynlock_create_callback=NULL;
       
   348       g->dynlock_lock_callback=NULL;
       
   349       g->dynlock_destroy_callback=NULL;
       
   350       g->_shadow_DES_rw_mode=DES_PCBC_MODE;
       
   351       g->_shadow_DES_check_key=0;
       
   352           		 
       
   353   		 memset(&(g->GET_WSD_VAR_NAME(data,bn_lib,s)),0,16);
       
   354   		 memset(&(g->GET_WSD_VAR_NAME(buff,fcrypt,s)),0,14);
       
   355   		 memset(&(g->GET_WSD_VAR_NAME(buf,err,s)),0,256);
       
   356   		 memset(&(g->GET_WSD_VAR_NAME(fallback,err,s)),0,sizeof(ERR_STATE));
       
   357   		 memset(&(g->GET_WSD_VAR_NAME(SYS_str_reasons,err,s)),0,128*sizeof(ERR_STRING_DATA));
       
   358   		 memset(&(g->GET_WSD_VAR_NAME(prompt_string,evp_key,s)),0,80);
       
   359   		 
       
   360   		 memset(&(g->GET_WSD_VAR_NAME(m,hmac,s)),0,EVP_MAX_MD_SIZE);
       
   361   		 memset(&(g->GET_WSD_VAR_NAME(m,md2,s)),0,EVP_MAX_MD_SIZE);
       
   362   		 memset(&(g->GET_WSD_VAR_NAME(m,md5,s)),0,EVP_MAX_MD_SIZE);
       
   363   		 memset(&(g->GET_WSD_VAR_NAME(m,sha1_one,s)),0,SHA_DIGEST_LENGTH);
       
   364   		 memset(&(g->GET_WSD_VAR_NAME(m,sha_one,s)),0,SHA_DIGEST_LENGTH);
       
   365   		 
       
   366   		 memset(&(g->GET_WSD_VAR_NAME(buf,x509_txt,s)),0,100);
       
   367   		  		  		  		 
       
   368   		 memcpy(&(g->GET_WSD_VAR_NAME(ASN1_str_functs,asn1_err,s)),&temp_ASN1_str_functs,108*sizeof(ERR_STRING_DATA));
       
   369   		 memcpy(&(g->GET_WSD_VAR_NAME(ASN1_str_reasons,asn1_err,s)),&temp_ASN1_str_reasons,99*sizeof(ERR_STRING_DATA));
       
   370        memcpy(&(g->GET_WSD_VAR_NAME(CRYPTO_str_functs,cpt_err,s)),&temp_CRYPTO_str_functs,10*sizeof(ERR_STRING_DATA));  		 
       
   371   		 memcpy(&(g->GET_WSD_VAR_NAME(CRYPTO_str_reasons,cpt_err,s)),&temp_CRYPTO_str_reasons,2*sizeof(ERR_STRING_DATA));  		 
       
   372        memcpy(&(g->GET_WSD_VAR_NAME(BIO_str_functs,bio_err,s)),&temp_BIO_str_functs,33*sizeof(ERR_STRING_DATA));  		 
       
   373   		 memcpy(&(g->GET_WSD_VAR_NAME(BIO_str_reasons,bio_err,s)),&temp_BIO_str_reasons,30*sizeof(ERR_STRING_DATA));  		 
       
   374        memcpy(&(g->GET_WSD_VAR_NAME(BN_str_functs,bn_err,s)),&temp_BN_str_functs,39*sizeof(ERR_STRING_DATA));  		 
       
   375   		 memcpy(&(g->GET_WSD_VAR_NAME(BN_str_reasons,bn_err,s)),&temp_BN_str_reasons,19*sizeof(ERR_STRING_DATA));  		 
       
   376   		 memcpy(&(g->GET_WSD_VAR_NAME(BUF_str_functs,buf_err,s)),&temp_BUF_str_functs,7*sizeof(ERR_STRING_DATA));  		 
       
   377   		 memcpy(&(g->GET_WSD_VAR_NAME(BUF_str_reasons,buf_err,s)),&temp_BUF_str_reasons,1*sizeof(ERR_STRING_DATA));  		 
       
   378        memcpy(&(g->GET_WSD_VAR_NAME(COMP_str_functs,comp_err,s)),&temp_COMP_str_functs,sizeof(ERR_STRING_DATA));  		 
       
   379   		 memcpy(&(g->GET_WSD_VAR_NAME(COMP_str_reasons,comp_err,s)),&temp_COMP_str_reasons,sizeof(ERR_STRING_DATA));  		 
       
   380        memcpy(&(g->GET_WSD_VAR_NAME(CONF_str_functs,conf_err,s)),&temp_CONF_str_functs,22*sizeof(ERR_STRING_DATA));  		 
       
   381   		 memcpy(&(g->GET_WSD_VAR_NAME(CONF_str_reasons,conf_err,s)),&temp_CONF_str_reasons,16*sizeof(ERR_STRING_DATA));  		 
       
   382        memcpy(&(g->GET_WSD_VAR_NAME(DH_str_functs,dh_err,s)),&temp_DH_str_functs,8*sizeof(ERR_STRING_DATA));  		 
       
   383   		 memcpy(&(g->GET_WSD_VAR_NAME(DH_str_reasons,dh_err,s)),&temp_DH_str_reasons,5*sizeof(ERR_STRING_DATA));  		 
       
   384 		   memcpy(&(g->GET_WSD_VAR_NAME(DSA_str_functs,dsa_err,s)),&temp_DSA_str_functs,15*sizeof(ERR_STRING_DATA));  		 
       
   385   		 memcpy(&(g->GET_WSD_VAR_NAME(DSA_str_reasons,dsa_err,s)),&temp_DSA_str_reasons,5*sizeof(ERR_STRING_DATA));  		 
       
   386 		   memcpy(&(g->GET_WSD_VAR_NAME(DSO_str_functs,dso_err,s)),&temp_DSO_str_functs,38*sizeof(ERR_STRING_DATA));  		 
       
   387   		 memcpy(&(g->GET_WSD_VAR_NAME(DSO_str_reasons,dso_err,s)),&temp_DSO_str_reasons,18*sizeof(ERR_STRING_DATA));  		 
       
   388 		   memcpy(&(g->GET_WSD_VAR_NAME(ENGINE_str_functs,eng_err,s)),&temp_ENGINE_str_functs,37*sizeof(ERR_STRING_DATA));  		 
       
   389   		 memcpy(&(g->GET_WSD_VAR_NAME(ENGINE_str_reasons,eng_err,s)),&temp_ENGINE_str_reasons,40*sizeof(ERR_STRING_DATA));  		 
       
   390 		   memcpy(&(g->GET_WSD_VAR_NAME(ERR_str_libraries,err_err,s)),&temp_ERR_str_libraries,25*sizeof(ERR_STRING_DATA));  		 
       
   391 		   memcpy(&(g->GET_WSD_VAR_NAME(ERR_str_functs,err_err,s)),&temp_ERR_str_functs,11*sizeof(ERR_STRING_DATA));  		 
       
   392   		 memcpy(&(g->GET_WSD_VAR_NAME(ERR_str_reasons,err_err,s)),&temp_ERR_str_reasons,36*sizeof(ERR_STRING_DATA));  		 
       
   393   		 memcpy(&(g->GET_WSD_VAR_NAME(EVP_str_functs,evp_err,s)),&temp_EVP_str_functs,36*sizeof(ERR_STRING_DATA));  		 
       
   394   		 memcpy(&(g->GET_WSD_VAR_NAME(EVP_str_reasons,evp_err,s)),&temp_EVP_str_reasons,45*sizeof(ERR_STRING_DATA));  		 
       
   395        memcpy(&(g->GET_WSD_VAR_NAME(OBJ_str_functs,obj_err,s)),&temp_OBJ_str_functs,8*sizeof(ERR_STRING_DATA));  		 
       
   396   		 memcpy(&(g->GET_WSD_VAR_NAME(OBJ_str_reasons,obj_err,s)),&temp_OBJ_str_reasons,3*sizeof(ERR_STRING_DATA));  		 
       
   397 		   memcpy(&(g->GET_WSD_VAR_NAME(OCSP_str_functs,ocsp_err,s)),&temp_OCSP_str_functs,18*sizeof(ERR_STRING_DATA));  		 
       
   398   		 memcpy(&(g->GET_WSD_VAR_NAME(OCSP_str_reasons,ocsp_err,s)),&temp_OCSP_str_reasons,31*sizeof(ERR_STRING_DATA));  		 
       
   399        memcpy(&(g->GET_WSD_VAR_NAME(PEM_str_functs,pem_err,s)),&temp_PEM_str_functs,27*sizeof(ERR_STRING_DATA));  		 
       
   400   		 memcpy(&(g->GET_WSD_VAR_NAME(PEM_str_reasons,pem_err,s)),&temp_PEM_str_reasons,17*sizeof(ERR_STRING_DATA));  		 
       
   401 		   memcpy(&(g->GET_WSD_VAR_NAME(PKCS7_str_functs,pkcs7_err,s)),&temp_PKCS7_str_functs,29*sizeof(ERR_STRING_DATA));  		 
       
   402   		 memcpy(&(g->GET_WSD_VAR_NAME(PKCS7_str_reasons,pkcs7_err,s)),&temp_PKCS7_str_reasons,47*sizeof(ERR_STRING_DATA));  		 
       
   403        memcpy(&(g->GET_WSD_VAR_NAME(PKCS12_str_functs,pkcs12_err,s)),&temp_PKCS12_str_functs,30*sizeof(ERR_STRING_DATA));  		 
       
   404   		 memcpy(&(g->GET_WSD_VAR_NAME(PKCS12_str_reasons,pkcs12_err,s)),&temp_PKCS12_str_reasons,23*sizeof(ERR_STRING_DATA));  		 
       
   405        memcpy(&(g->GET_WSD_VAR_NAME(RAND_str_functs,rand_err,s)),&temp_RAND_str_functs,3*sizeof(ERR_STRING_DATA));  		 
       
   406   		 memcpy(&(g->GET_WSD_VAR_NAME(RAND_str_reasons,rand_err,s)),&temp_RAND_str_reasons,2*sizeof(ERR_STRING_DATA));  		 
       
   407        memcpy(&(g->GET_WSD_VAR_NAME(RSA_str_functs,rsa_err,s)),&temp_RSA_str_functs,38*sizeof(ERR_STRING_DATA));  		 
       
   408   		 memcpy(&(g->GET_WSD_VAR_NAME(RSA_str_reasons,rsa_err,s)),&temp_RSA_str_reasons,42*sizeof(ERR_STRING_DATA));  		 
       
   409        memcpy(&(g->GET_WSD_VAR_NAME(UI_str_functs,ui_err,s)),&temp_UI_str_functs,13*sizeof(ERR_STRING_DATA));  		 
       
   410   		 memcpy(&(g->GET_WSD_VAR_NAME(UI_str_reasons,ui_err,s)),&temp_UI_str_reasons,8*sizeof(ERR_STRING_DATA));  		 
       
   411        memcpy(&(g->GET_WSD_VAR_NAME(X509_str_functs,x509_err,s)),&temp_X509_str_functs,46*sizeof(ERR_STRING_DATA));  		 
       
   412   		 memcpy(&(g->GET_WSD_VAR_NAME(X509_str_reasons,x509_err,s)),&temp_X509_str_reasons,24*sizeof(ERR_STRING_DATA));  		 
       
   413        memcpy(&(g->GET_WSD_VAR_NAME(X509V3_str_functs,x509v3_err,s)),&temp_X509V3_str_functs,57*sizeof(ERR_STRING_DATA));  		 
       
   414   		 memcpy(&(g->GET_WSD_VAR_NAME(X509V3_str_reasons,x509v3_err,s)),&temp_X509V3_str_reasons,61*sizeof(ERR_STRING_DATA));  		 
       
   415   		 
       
   416   		 
       
   417   		 
       
   418   		 /*START - static funcs*/
       
   419  		   memcpy(&(g->GET_WSD_VAR_NAME(impl_default,ex_data,s)),&temp_s_impl_default,sizeof(CRYPTO_EX_DATA_IMPL));
       
   420  		   memcpy(&(g->GET_WSD_VAR_NAME(mem_method,bss_mem,s)),&temp_s_mem_method,sizeof(BIO_METHOD));
       
   421  		   memcpy(&(g->GET_WSD_VAR_NAME(null_method,bss_null,s)),&temp_s_null_method,sizeof(BIO_METHOD));
       
   422        memcpy(&(g->GET_WSD_VAR_NAME(methods_fdp,bss_fd,s)),&temp_s_methods_fdp,sizeof(BIO_METHOD));  		 
       
   423        memcpy(&(g->GET_WSD_VAR_NAME(methods_sockp,bss_sock,s)),&temp_s_methods_sockp,sizeof(BIO_METHOD));  
       
   424        memcpy(&(g->GET_WSD_VAR_NAME(methods_filep,bss_file,s)),&temp_s_methods_filep,sizeof(BIO_METHOD));  		 		 
       
   425        memcpy(&(g->GET_WSD_VAR_NAME(methods_dgramp,bss_dgram,s)),&temp_s_methods_dgramp,sizeof(BIO_METHOD));  		 		 
       
   426        memcpy(&(g->GET_WSD_VAR_NAME(methods_connectp,bss_conn,s)),&temp_s_methods_connectp,sizeof(BIO_METHOD));  		 		 
       
   427        memcpy(&(g->GET_WSD_VAR_NAME(methods_biop,bss_bio,s)),&temp_s_methods_biop,sizeof(BIO_METHOD));  		 		 
       
   428        memcpy(&(g->GET_WSD_VAR_NAME(methods_acceptp,bss_acpt,s)),&temp_s_methods_acceptp,sizeof(BIO_METHOD));  		 		 
       
   429          
       
   430          
       
   431        memcpy(&(g->GET_WSD_VAR_NAME(default_method,conf_def,s)),&temp_s_default_method,sizeof(CONF_METHOD));  		 		 
       
   432        memcpy(&(g->GET_WSD_VAR_NAME(WIN32_method,conf_def,s)),&temp_s_WIN32_method,sizeof(CONF_METHOD));  		 		 
       
   433          
       
   434        memcpy(&(g->GET_WSD_VAR_NAME(rle_method,c_rle,s)),&temp_s_rle_method,sizeof(COMP_METHOD));  		 		 
       
   435        memcpy(&(g->GET_WSD_VAR_NAME(zlib_method_nozlib,c_zlib,s)),&temp_s_zlib_method_nozlib,sizeof(COMP_METHOD));  		 		 
       
   436 #ifdef ZLIB       
       
   437        memcpy(&(g->GET_WSD_VAR_NAME(zlib_stateful_method,c_zlib,s)),&temp_s_zlib_stateful_method,sizeof(COMP_METHOD));  		 		 
       
   438 #endif       
       
   439        
       
   440 
       
   441        memcpy(&(g->GET_WSD_VAR_NAME(dh_ossl,dh_key,s)),&temp_s_dh_ossl,sizeof(DH_METHOD));  
       
   442        memcpy(&(g->GET_WSD_VAR_NAME(openssl_dsa_meth,dsa_ossl,s)),&temp_s_openssl_dsa_meth,sizeof(DSA_METHOD));  		 		          		 		          
       
   443          
       
   444        //memcpy(&(g->GET_WSD_VAR_NAME(dso_meth_dl,dso_dl,s)),&temp_s_dso_meth_dl,sizeof(DSO_METHOD));  		 		          		 		          
       
   445        memcpy(&(g->GET_WSD_VAR_NAME(dso_meth_dlfcn,dso_dlfcn,s)),&temp_s_dso_meth_dlfcn,sizeof(DSO_METHOD));  		 		          		 		          
       
   446        memcpy(&(g->GET_WSD_VAR_NAME(dso_meth_null,dso_null,s)),&temp_s_dso_meth_null,sizeof(DSO_METHOD));  		 		          		 		          
       
   447          
       
   448          
       
   449        memcpy(&(g->GET_WSD_VAR_NAME(methods_md,bio_md,s)),&temp_s_methods_md,sizeof(BIO_METHOD));  		 		          		 		          
       
   450        memcpy(&(g->GET_WSD_VAR_NAME(methods_b64,bio_b64,s)),&temp_s_methods_b64,sizeof(BIO_METHOD));  		 		          		 		          
       
   451        memcpy(&(g->GET_WSD_VAR_NAME(methods_enc,bio_enc,s)),&temp_s_methods_enc,sizeof(BIO_METHOD));  		 		          		 		          
       
   452        memcpy(&(g->GET_WSD_VAR_NAME(methods_ok,bio_ok,s)),&temp_s_methods_ok,sizeof(BIO_METHOD));  		 		          		 		          
       
   453          
       
   454        memcpy(&(g->GET_WSD_VAR_NAME(rsa_pkcs1_eay_meth,rsa_eay,s)),&temp_s_rsa_pkcs1_eay_meth,sizeof(RSA_METHOD));  		 		          		 		                   
       
   455          
       
   456        memcpy(&(g->GET_WSD_VAR_NAME(store_memory,str_mem,s)),&temp_s_store_memory,sizeof(STORE_METHOD));  		 		          		 		                   
       
   457          
       
   458        memcpy(&(g->GET_WSD_VAR_NAME(ui_openssl,ui_openssl,s)),&temp_s_ui_openssl,sizeof(UI_METHOD));  		 		          		 		                   
       
   459        memcpy(&(g->GET_WSD_VAR_NAME(nconf_method,v3_conf,s)),&temp_s_nconf_method,sizeof(X509V3_CONF_METHOD));  		 		          		 		                   
       
   460        memcpy(&(g->GET_WSD_VAR_NAME(conf_lhash_method,v3_conf,s)),&temp_s_conf_lhash_method,sizeof(X509V3_CONF_METHOD));  		 		          		 		                   
       
   461          
       
   462        memcpy(&(g->GET_WSD_VAR_NAME(meth,x_x509,s)),&temp_s_meth,sizeof(ASN1_METHOD));  		 		          		 		                   
       
   463          
       
   464        memcpy(&(g->GET_WSD_VAR_NAME(method,rsa_asn1,s)),&temp_s_method,sizeof(ASN1_METHOD));  		 		          		 		                   
       
   465                
       
   466   		 /*START -global vars*/
       
   467   		 g->GET_WSD_VAR_NAME(cleanse_ctr,mem_clr,g)=0;
       
   468   		 memcpy(&(g->GET_WSD_VAR_NAME(rand_ssleay_meth,md_rand,g)),&temp_g_rand_ssleay_meth,sizeof(RAND_METHOD));  		 		          		 		                   
       
   469   		 memcpy(&(g->GET_WSD_VAR_NAME(x509_file_lookup,by_file,g)),&temp_g_x509_file_lookup,sizeof(X509_LOOKUP_METHOD));  		 		          		 		                   
       
   470   		 memcpy(&(g->GET_WSD_VAR_NAME(x509_dir_lookup,by_dir,g)),&temp_g_x509_dir_lookup,sizeof(X509_LOOKUP_METHOD));  		 		          		 		                   
       
   471   		 
       
   472 
       
   473 				
       
   474 	  }
       
   475 	  return KErrNone;
       
   476 }
       
   477