Commit 4c329696 authored by Geoff Thorpe's avatar Geoff Thorpe
Browse files

Remove the dual-callback scheme for numeric and pointer thread IDs,

deprecate the original (numeric-only) scheme, and replace with the
CRYPTO_THREADID object. This hides the platform-specifics and should reduce
the possibility for programming errors (where failing to explicitly check
both thread ID forms could create subtle, platform-specific bugs).

Thanks to Bodo, for invaluable review and feedback.
parent 96826bfc
Loading
Loading
Loading
Loading
+24 −24
Original line number Diff line number Diff line
@@ -4,6 +4,30 @@

 Changes between 0.9.8i and 0.9.9  [xx XXX xxxx]

  *) To cater for systems that provide a pointer-based thread ID rather
     than numeric, deprecate the current numeric thread ID mechanism and
     replace it with a structure and associated callback type. This
     mechanism allows a numeric "hash" to be extracted from a thread ID in
     either case, and on platforms where pointers are larger than 'long',
     mixing is done to help ensure the numeric 'hash' is usable even if it
     can't be guaranteed unique. The default mechanism is to use "&errno"
     as a pointer-based thread ID to distinguish between threads.

     Applications that want to provide their own thread IDs should now use
     CRYPTO_THREADID_set_callback() to register a callback that will call
     either CRYPTO_THREADID_set_numeric() or CRYPTO_THREADID_set_pointer().

     (This new approach replaces the functions CRYPTO_set_idptr_callback(),
     CRYPTO_get_idptr_callback(), and CRYPTO_thread_idptr() that existed in
     OpenSSL 0.9.9-dev between June 2006 and August 2008. Also, if an
     application was previously providing a numeric thread callback that
     was inappropriate for distinguishing threads, then uniqueness might
     have been obtained with &errno that happened immediately in the
     intermediate development versions of OpenSSL; this is no longer the
     case, the numeric thread callback will now override the automatic use
     of &errno.)
     [Geoff Thorpe, with help from Bodo Moeller]

  *) Initial support for different CRL issuing certificates. This covers a
     simple case where the self issued certificates in the chain exist and
     the real CRL issuer is higher in the existing chain.
@@ -307,30 +331,6 @@
     list-message-digest-algorithms and list-cipher-algorithms.
     [Steve Henson]

  *) 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
+1 −3
Original line number Diff line number Diff line
@@ -717,9 +717,7 @@ file.

Multi-threaded applications must provide two callback functions to
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)
CRYPTO_set_id_callback().  This is described in the threads(3)
manpage.

* I've compiled a program under Windows and it crashes: why?
+2 −2
Original line number Diff line number Diff line
@@ -181,7 +181,7 @@ extern BIO *bio_err;
#    define apps_shutdown() \
			do { CONF_modules_unload(1); destroy_ui_method(); \
			OBJ_cleanup(); EVP_cleanup(); ENGINE_cleanup(); \
			CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \
			CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
			ERR_free_strings(); COMP_zlib_cleanup();} while(0)
#  else
#    define apps_startup() \
@@ -191,7 +191,7 @@ extern BIO *bio_err;
#    define apps_shutdown() \
			do { CONF_modules_unload(1); destroy_ui_method(); \
			OBJ_cleanup(); EVP_cleanup(); \
			CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \
			CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
			ERR_free_strings(); } while(0)
#  endif
#endif
+4 −2
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@
#include <stdio.h> /* FILE */
#endif
#include <openssl/ossl_typ.h>
#include <openssl/crypto.h>

#ifdef  __cplusplus
extern "C" {
@@ -564,10 +565,11 @@ int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
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 *);
#ifndef OPENSSL_NO_DEPRECATED
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 *);
#endif
CRYPTO_THREADID *BN_BLINDING_thread_id(BN_BLINDING *);
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,
+8 −9
Original line number Diff line number Diff line
@@ -121,10 +121,11 @@ struct bn_blinding_st
	BIGNUM *Ai;
	BIGNUM *e;
	BIGNUM *mod; /* just a reference */
#ifndef OPENSSL_NO_DEPRECATED
	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 */
#endif
	CRYPTO_THREADID tid;
	unsigned int  counter;
	unsigned long flags;
	BN_MONT_CTX *m_ctx;
@@ -160,6 +161,7 @@ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod)
		BN_set_flags(ret->mod, BN_FLG_CONSTTIME);

	ret->counter = BN_BLINDING_COUNTER;
	CRYPTO_THREADID_current(&ret->tid);
	return(ret);
err:
	if (ret != NULL) BN_BLINDING_free(ret);
@@ -265,6 +267,7 @@ int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *ct
	return(ret);
	}

#ifndef OPENSSL_NO_DEPRECATED
unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *b)
	{
	return b->thread_id;
@@ -274,15 +277,11 @@ void BN_BLINDING_set_thread_id(BN_BLINDING *b, unsigned long n)
	{
	b->thread_id = n;
	}
#endif

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)
CRYPTO_THREADID *BN_BLINDING_thread_id(BN_BLINDING *b)
	{
	b->thread_idptr = p;
	return &b->tid;
	}

unsigned long BN_BLINDING_get_flags(const BN_BLINDING *b)
Loading