Print this page
4853 illumos-gate is not lint-clean when built with openssl 1.0


  99  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 100  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 101  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 102  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 103  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 104  * SUCH DAMAGE.
 105  *
 106  * The licence and distribution terms for any publically available version or
 107  * derivative of this code cannot be changed.  i.e. this code cannot simply be
 108  * copied and put under another distribution licence
 109  * [including the GNU Public Licence.]
 110  */
 111 /* ====================================================================
 112  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
 113  * ECDH support in OpenSSL originally developed by
 114  * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
 115  */
 116 
 117 #include "cryptlib.h"
 118 #include <openssl/safestack.h>

 119 
 120 #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
 121 static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
 122 #endif
 123 
 124 DECLARE_STACK_OF(CRYPTO_dynlock)
 125 
 126 /* real #defines in crypto.h, keep these upto date */
 127 static const char* const lock_names[CRYPTO_NUM_LOCKS] =
 128         {
 129         "<<ERROR>>",
 130         "err",
 131         "ex_data",
 132         "x509",
 133         "x509_info",
 134         "x509_pkey",
 135         "x509_crl",
 136         "x509_req",
 137         "dsa",
 138         "rsa",


 164         "bn",
 165         "ec_pre_comp",
 166         "store",
 167         "comp",
 168         "fips",
 169         "fips2",
 170 #if CRYPTO_NUM_LOCKS != 41
 171 # error "Inconsistency between crypto.h and cryptlib.c"
 172 #endif
 173         };
 174 
 175 /* This is for applications to allocate new type names in the non-dynamic
 176    array of lock names.  These are numbered with positive numbers.  */
 177 static STACK_OF(OPENSSL_STRING) *app_locks=NULL;
 178 
 179 /* For applications that want a more dynamic way of handling threads, the
 180    following stack is used.  These are externally numbered with negative
 181    numbers.  */
 182 static STACK_OF(CRYPTO_dynlock) *dyn_locks=NULL;
 183 

 184 
 185 static void (MS_FAR *locking_callback)(int mode,int type,
 186         const char *file,int line)=0;
 187 static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
 188         int type,const char *file,int line)=0;
 189 #ifndef OPENSSL_NO_DEPRECATED
 190 static unsigned long (MS_FAR *id_callback)(void)=0;
 191 #endif
 192 static void (MS_FAR *threadid_callback)(CRYPTO_THREADID *)=0;
 193 static struct CRYPTO_dynlock_value *(MS_FAR *dynlock_create_callback)
 194         (const char *file,int line)=0;
 195 static void (MS_FAR *dynlock_lock_callback)(int mode,
 196         struct CRYPTO_dynlock_value *l, const char *file,int line)=0;
 197 static void (MS_FAR *dynlock_destroy_callback)(struct CRYPTO_dynlock_value *l,
 198         const char *file,int line)=0;
 199 
 200 int CRYPTO_get_new_lockid(char *name)
 201         {
 202         char *str;
 203         int i;


 389 
 390 void CRYPTO_set_dynlock_destroy_callback(void (*func)
 391         (struct CRYPTO_dynlock_value *l, const char *file, int line))
 392         {
 393         dynlock_destroy_callback=func;
 394         }
 395 
 396 
 397 void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
 398                 int line)
 399         {
 400         return(locking_callback);
 401         }
 402 
 403 int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
 404                                           const char *file,int line)
 405         {
 406         return(add_lock_callback);
 407         }
 408 









































































 409 void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
 410                                               const char *file,int line))
 411         {
 412         /* Calling this here ensures initialisation before any threads
 413          * are started.
 414          */
 415         OPENSSL_init();
 416         locking_callback=func;




 417         }
 418 
 419 void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
 420                                               const char *file,int line))
 421         {
 422         add_lock_callback=func;
 423         }
 424 
 425 /* the memset() here and in set_pointer() seem overkill, but for the sake of
 426  * CRYPTO_THREADID_cmp() this avoids any platform silliness that might cause two
 427  * "equal" THREADID structs to not be memcmp()-identical. */
 428 void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val)
 429         {
 430         memset(id, 0, sizeof(*id));
 431         id->val = val;
 432         }
 433 
 434 static const unsigned char hash_coeffs[] = { 3, 5, 7, 11, 13, 17, 19, 23 };
 435 void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr)
 436         {




  99  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 100  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 101  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 102  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 103  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 104  * SUCH DAMAGE.
 105  *
 106  * The licence and distribution terms for any publically available version or
 107  * derivative of this code cannot be changed.  i.e. this code cannot simply be
 108  * copied and put under another distribution licence
 109  * [including the GNU Public Licence.]
 110  */
 111 /* ====================================================================
 112  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
 113  * ECDH support in OpenSSL originally developed by
 114  * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
 115  */
 116 
 117 #include "cryptlib.h"
 118 #include <openssl/safestack.h>
 119 #include <pthread.h>
 120 
 121 #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
 122 static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
 123 #endif
 124 
 125 DECLARE_STACK_OF(CRYPTO_dynlock)
 126 
 127 /* real #defines in crypto.h, keep these upto date */
 128 static const char* const lock_names[CRYPTO_NUM_LOCKS] =
 129         {
 130         "<<ERROR>>",
 131         "err",
 132         "ex_data",
 133         "x509",
 134         "x509_info",
 135         "x509_pkey",
 136         "x509_crl",
 137         "x509_req",
 138         "dsa",
 139         "rsa",


 165         "bn",
 166         "ec_pre_comp",
 167         "store",
 168         "comp",
 169         "fips",
 170         "fips2",
 171 #if CRYPTO_NUM_LOCKS != 41
 172 # error "Inconsistency between crypto.h and cryptlib.c"
 173 #endif
 174         };
 175 
 176 /* This is for applications to allocate new type names in the non-dynamic
 177    array of lock names.  These are numbered with positive numbers.  */
 178 static STACK_OF(OPENSSL_STRING) *app_locks=NULL;
 179 
 180 /* For applications that want a more dynamic way of handling threads, the
 181    following stack is used.  These are externally numbered with negative
 182    numbers.  */
 183 static STACK_OF(CRYPTO_dynlock) *dyn_locks=NULL;
 184 
 185 static pthread_mutex_t *illumos_openssl_locks;
 186 
 187 static void (MS_FAR *locking_callback)(int mode,int type,
 188         const char *file,int line)=0;
 189 static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
 190         int type,const char *file,int line)=0;
 191 #ifndef OPENSSL_NO_DEPRECATED
 192 static unsigned long (MS_FAR *id_callback)(void)=0;
 193 #endif
 194 static void (MS_FAR *threadid_callback)(CRYPTO_THREADID *)=0;
 195 static struct CRYPTO_dynlock_value *(MS_FAR *dynlock_create_callback)
 196         (const char *file,int line)=0;
 197 static void (MS_FAR *dynlock_lock_callback)(int mode,
 198         struct CRYPTO_dynlock_value *l, const char *file,int line)=0;
 199 static void (MS_FAR *dynlock_destroy_callback)(struct CRYPTO_dynlock_value *l,
 200         const char *file,int line)=0;
 201 
 202 int CRYPTO_get_new_lockid(char *name)
 203         {
 204         char *str;
 205         int i;


 391 
 392 void CRYPTO_set_dynlock_destroy_callback(void (*func)
 393         (struct CRYPTO_dynlock_value *l, const char *file, int line))
 394         {
 395         dynlock_destroy_callback=func;
 396         }
 397 
 398 
 399 void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
 400                 int line)
 401         {
 402         return(locking_callback);
 403         }
 404 
 405 int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
 406                                           const char *file,int line)
 407         {
 408         return(add_lock_callback);
 409         }
 410 
 411 /*
 412  * This is the locking callback function which all applications will be
 413  * using when CRYPTO_lock() is called.
 414  */
 415 static void illumos_locking_callback(int mode, int type, const char *file,
 416     int line)
 417         {
 418         if (mode & CRYPTO_LOCK)
 419                 {
 420                 pthread_mutex_lock(&illumos_openssl_locks[type]);
 421                 }
 422         else
 423                 {
 424                 pthread_mutex_unlock(&illumos_openssl_locks[type]);
 425                 }
 426         }
 427 
 428 
 429 /*
 430  * This function is called when a child process is forked to setup its own
 431  * global locking callback function ptr and mutexes.
 432  */
 433 static void illumos_fork_child(void)
 434         {
 435                 /*
 436                  * clear locking_callback to indicate that locks should
 437                  * be reinitialized.
 438                  */
 439                 locking_callback = NULL;
 440                 illumos_locking_setup();
 441         }
 442 
 443 /*
 444  * This function allocates and initializes the global mutex array, and
 445  * sets the locking callback.
 446  */
 447 void illumos_locking_setup()
 448         {
 449         int i;
 450         int num_locks;
 451 
 452         /* locking callback is already setup. Nothing to do */
 453         if (locking_callback != NULL)
 454                 {
 455                 return;
 456                 }
 457 
 458         /*
 459          * Set atfork handler so that child can setup its own mutexes and
 460          * locking callbacks when it is forked
 461          */
 462         (void) pthread_atfork(NULL, NULL, illumos_fork_child);
 463 
 464         /* allocate locks needed by OpenSSL  */
 465         num_locks = CRYPTO_num_locks();
 466         illumos_openssl_locks =
 467             OPENSSL_malloc(sizeof (pthread_mutex_t) * num_locks);
 468         if (illumos_openssl_locks == NULL)
 469                 {
 470                 fprintf(stderr,
 471                         "illumos_locking_setup: memory allocation failure.\n");
 472                 abort();
 473                 }
 474 
 475         /* initialize openssl mutexes */
 476         for (i = 0; i < num_locks; i++)
 477                 {
 478                 pthread_mutex_init(&illumos_openssl_locks[i], NULL);
 479                 }
 480         locking_callback = illumos_locking_callback;
 481 
 482         }
 483 
 484 void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
 485                                               const char *file,int line))
 486         {
 487         /* Calling this here ensures initialisation before any threads
 488          * are started.
 489          */
 490         OPENSSL_init();
 491 
 492         /*
 493          * we now setup our own locking callback and mutexes, and disallow
 494          * setting of another locking callback.
 495          */
 496         }
 497 
 498 void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
 499                                               const char *file,int line))
 500         {
 501         add_lock_callback=func;
 502         }
 503 
 504 /* the memset() here and in set_pointer() seem overkill, but for the sake of
 505  * CRYPTO_THREADID_cmp() this avoids any platform silliness that might cause two
 506  * "equal" THREADID structs to not be memcmp()-identical. */
 507 void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val)
 508         {
 509         memset(id, 0, sizeof(*id));
 510         id->val = val;
 511         }
 512 
 513 static const unsigned char hash_coeffs[] = { 3, 5, 7, 11, 13, 17, 19, 23 };
 514 void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr)
 515         {