Commit 48fc582f authored by Bodo Möller's avatar Bodo Möller
Browse files

New functions CRYPTO_set_idptr_callback(),

CRYPTO_get_idptr_callback(), CRYPTO_thread_idptr() for a 'void *' type
thread ID, since the 'unsigned long' type of the existing thread ID
does not always work well.
parent 81de1028
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -4,6 +4,30 @@

 Changes between 0.9.8b and 0.9.9  [xx XXX xxxx]

  *) In addition to the numerical (unsigned long) thread ID, provide
     for a pointer (void *) thread ID.  This helps accomodate systems
     that do not provide an unsigned long thread ID.  OpenSSL assumes
     it is in the same thread iff both the numerical and the pointer
     thread ID agree; so applications are just required to define one
     of them appropriately (e.g., by using a pointer to a per-thread
     memory object malloc()ed by the application for the pointer-type
     thread ID).  Exactly analoguous to the existing functions

        void CRYPTO_set_id_callback(unsigned long (*func)(void));
        unsigned long (*CRYPTO_get_id_callback(void))(void);
        unsigned long CRYPTO_thread_id(void);

     we now have additional functions

        void CRYPTO_set_idptr_callback(void *(*func)(void));
        void *(*CRYPTO_get_idptr_callback(void))(void);
        void *CRYPTO_thread_idptr(void);

     also in <openssl/crypto.h>.  The default value for
     CRYPTO_thread_idptr() if the application has not provided its own
     callback is &errno.
     [Bodo Moeller]

  *) Change the array representation of binary polynomials: the list
     of degrees of non-zero coefficients is now terminated with -1.
     Previously it was terminated with 0, which was also part of the
+5 −2
Original line number Diff line number Diff line
@@ -699,8 +699,11 @@ libraries. If your platform is not one of these, consult the INSTALL
file.

Multi-threaded applications must provide two callback functions to
OpenSSL.  This is described in the threads(3) manpage.

OpenSSL by calling CRYPTO_set_locking_callback() and
CRYPTO_set_id_callback().  (For OpenSSL 0.9.9 or later, the new
function CRYPTO_set_idptr_callback() may be used in place of
CRYPTO_set_id_callback().)  This is described in the threads(3)
manpage.

* I've compiled a program under Windows and it crashes: why?

+55 −0
Original line number Diff line number Diff line
@@ -55,6 +55,59 @@
 * copied and put under another distribution licence
 * [including the GNU Public Licence.]
 */
/* ====================================================================
 * Copyright (c) 1998-2006 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
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer. 
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. All advertising materials mentioning features or use of this
 *    software must display the following acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
 *
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For written permission, please contact
 *    openssl-core@openssl.org.
 *
 * 5. Products derived from this software may not be called "OpenSSL"
 *    nor may "OpenSSL" appear in their names without prior written
 *    permission of the OpenSSL Project.
 *
 * 6. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
 *
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 * ====================================================================
 *
 * This product includes cryptographic software written by Eric Young
 * (eay@cryptsoft.com).  This product includes software written by Tim
 * Hudson (tjh@cryptsoft.com).
 *
 */
/* ====================================================================
 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
 *
@@ -502,6 +555,8 @@ int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *);
int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *);
unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *);
void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);
void *BN_BLINDING_get_thread_idptr(const BN_BLINDING *);
void BN_BLINDING_set_thread_idptr(BN_BLINDING *, void *);
unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);
void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);
BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
+13 −1
Original line number Diff line number Diff line
/* crypto/bn/bn_blind.c */
/* ====================================================================
 * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
 * Copyright (c) 1998-2006 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
@@ -123,6 +123,8 @@ struct bn_blinding_st
	BIGNUM *mod; /* just a reference */
	unsigned long thread_id; /* added in OpenSSL 0.9.6j and 0.9.7b;
				  * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */
	void *thread_idptr; /* added in OpenSSL 0.9.9;
			     * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */
	unsigned int  counter;
	unsigned long flags;
	BN_MONT_CTX *m_ctx;
@@ -267,6 +269,16 @@ void BN_BLINDING_set_thread_id(BN_BLINDING *b, unsigned long n)
	b->thread_id = n;
	}

void *BN_BLINDING_get_thread_idptr(const BN_BLINDING *b)
	{
	return b->thread_idptr;
	}

void BN_BLINDING_set_thread_idptr(BN_BLINDING *b, void *p)
	{
	b->thread_idptr = p;
	}

unsigned long BN_BLINDING_get_flags(const BN_BLINDING *b)
	{
	return b->flags;
+36 −13
Original line number Diff line number Diff line
/* crypto/cryptlib.c */
/* ====================================================================
 * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
 * Copyright (c) 1998-2006 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
@@ -182,16 +182,17 @@ static STACK_OF(CRYPTO_dynlock) *dyn_locks=NULL;


static void (MS_FAR *locking_callback)(int mode,int type,
	const char *file,int line)=NULL;
	const char *file,int line)=0;
static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
	int type,const char *file,int line)=NULL;
static unsigned long (MS_FAR *id_callback)(void)=NULL;
	int type,const char *file,int line)=0;
static unsigned long (MS_FAR *id_callback)(void)=0;
static void *(MS_FAR *idptr_callback)(void)=0;
static struct CRYPTO_dynlock_value *(MS_FAR *dynlock_create_callback)
	(const char *file,int line)=NULL;
	(const char *file,int line)=0;
static void (MS_FAR *dynlock_lock_callback)(int mode,
	struct CRYPTO_dynlock_value *l, const char *file,int line)=NULL;
	struct CRYPTO_dynlock_value *l, const char *file,int line)=0;
static void (MS_FAR *dynlock_destroy_callback)(struct CRYPTO_dynlock_value *l,
	const char *file,int line)=NULL;
	const char *file,int line)=0;

int CRYPTO_get_new_lockid(char *name)
	{
@@ -447,6 +448,28 @@ unsigned long CRYPTO_thread_id(void)
	return(ret);
	}

void *(*CRYPTO_get_idptr_callback(void))(void)
	{
	return(idptr_callback);
	}

void CRYPTO_set_idptr_callback(void *(*func)(void))
	{
	idptr_callback=func;
	}

void *CRYPTO_thread_idptr(void)
	{
	void *ret=NULL;

	if (idptr_callback == NULL)
		ret = &errno;
	else
		ret = idptr_callback();

	return ret;
	}

void CRYPTO_lock(int mode, int type, const char *file, int line)
	{
#ifdef LOCK_DEBUG
@@ -467,8 +490,8 @@ void CRYPTO_lock(int mode, int type, const char *file, int line)
		else
			rw_text="ERROR";

		fprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\n",
			CRYPTO_thread_id(), rw_text, operation_text,
		fprintf(stderr,"lock:%08lx/%08p:(%s)%s %-18s %s:%d\n",
			CRYPTO_thread_id(), CRYPTO_thread_idptr(), rw_text, operation_text,
			CRYPTO_get_lock_name(type), file, line);
		}
#endif
@@ -504,8 +527,8 @@ int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

		ret=add_lock_callback(pointer,amount,type,file,line);
#ifdef LOCK_DEBUG
		fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
			CRYPTO_thread_id(),
		fprintf(stderr,"ladd:%08lx/%0xp:%2d+%2d->%2d %-18s %s:%d\n",
			CRYPTO_thread_id(), CRYPTO_thread_idptr(),
			before,amount,ret,
			CRYPTO_get_lock_name(type),
			file,line);
@@ -517,8 +540,8 @@ int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

		ret= *pointer+amount;
#ifdef LOCK_DEBUG
		fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
			CRYPTO_thread_id(),
		fprintf(stderr,"ladd:%08lx/%0xp:%2d+%2d->%2d %-18s %s:%d\n",
			CRYPTO_thread_id(), CRYPTO_thread_idptr(),
			*pointer,amount,ret,
			CRYPTO_get_lock_name(type),
			file,line);
Loading