Commit f7ccba3e authored by Geoff Thorpe's avatar Geoff Thorpe
Browse files

There was a need to support thread ID types that couldn't be reliably cast

to 'unsigned long' (ie. odd platforms/compilers), so a pointer-typed
version was added but it required portable code to check *both* modes to
determine equality. This commit maintains the availability of both thread
ID types, but deprecates the type-specific accessor APIs that invoke the
callbacks - instead a single type-independent API is used.  This simplifies
software that calls into this interface, and should also make it less
error-prone - as forgetting to call and compare *both* thread ID accessors
could have led to hard-to-debug/infrequent bugs (that might only affect
certain platforms or thread implementations). As the CHANGES note says,
there were corresponding deprecations and replacements in the
thread-related functions for BN_BLINDING and ERR too.
parent eb77ebe2
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
@@ -4,6 +4,58 @@

 Changes between 0.9.8g and 0.9.9  [xx XXX xxxx]

  *) To support arbitrarily-typed thread IDs, deprecate the existing
     type-specific APIs for a general purpose CRYPTO_THREADID
     interface. Applications can choose the thread ID
     callback type it wishes to register, as before;

        void CRYPTO_set_id_callback(unsigned long (*func)(void));
        void CRYPTO_set_idptr_callback(void *(*func)(void));

     but retrieval, copies, and comparisons of thread IDs are via
     type-independent interfaces;

        void CRYPTO_THREADID_set(CRYPTO_THREADID *id);
        void CRYPTO_THREADID_cmp(const CRYPTO_THREADID *id1,
                                 const CRYPTO_THREADID *id2);
        void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dst,
                                 const CRYPTO_THREADID *src);

     Also, for code that needs a thread ID "value" for use in
     hash-tables or logging, a "hash" is available by;

        unsigned long CRYPTO_THREADID_hash(const CRYPTO_THREADID *id);

     This hash value is likely to be the thread ID anyway, but
     otherwise it will be unique if possible or as collision-free as
     possible if uniqueness can't be guaranteed on the target
     architecture.

     The following functions are deprecated;
        unsigned long (*CRYPTO_get_id_callback(void))(void);
        unsigned long CRYPTO_thread_id(void);

     As a consequence of the above, there are similar deprecations of
     BN_BLINDING functions in favour of CRYPTO_THREADID-based
     alternatives;

        #ifndef OPENSSL_NO_DEPRECATED
        unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *);
        void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);
        #endif
        void BN_BLINDING_set_thread(BN_BLINDING *);
        int BN_BLINDING_cmp_thread(const BN_BLINDING *, const
                                   CRYPTO_THREADID *);

     Also, the ERR_remove_state(int pid) API has been deprecated;

        #ifndef OPENSSL_NO_DEPRECATED
        void ERR_remove_state(unsigned long pid)
        #endif
        void ERR_remove_thread_state(CRYPTO_THREADID *tid);

     [Geoff Thorpe]

  *) Initial support for Cryptographic Message Syntax (aka CMS) based
     on RFC3850, RFC3851 and RFC3852. New cms directory and cms utility,
     support for data, signedData, compressedData, digestedData and
@@ -311,6 +363,14 @@
     callback is &errno.
     [Bodo Moeller]

     -- NOTE -- this change has been reverted and replaced with a
     type-independent wrapper (ie. applications do not have to check
     two type-specific thread ID representations as implied in this
     change note). However, the "idptr" callback form described here
     can still be registered. Please see the more recent CHANGES note
     regarding CRYPTO_THREADID. [Geoff Thorpe]
     -- NOTE --

  *) 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
+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
+5 −2
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@
#ifndef OPENSSL_NO_FP_API
#include <stdio.h> /* FILE */
#endif
#include <openssl/crypto.h>
#include <openssl/ossl_typ.h>

#ifdef  __cplusplus
@@ -563,10 +564,12 @@ 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
void BN_BLINDING_set_thread(BN_BLINDING *);
int BN_BLINDING_cmp_thread(const BN_BLINDING *, const CRYPTO_THREADID *);
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,
+11 −6
Original line number Diff line number Diff line
@@ -121,10 +121,13 @@ struct bn_blinding_st
	BIGNUM *Ai;
	BIGNUM *e;
	BIGNUM *mod; /* just a reference */
/* FIXME: should really try to remove these, but the deprecated APIs that are
 * using them would need to be fudged somehow. */
#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;
@@ -265,6 +268,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 +278,16 @@ 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)
void BN_BLINDING_set_thread(BN_BLINDING *b)
	{
	return b->thread_idptr;
	CRYPTO_THREADID_set(&b->tid);
	}

void BN_BLINDING_set_thread_idptr(BN_BLINDING *b, void *p)
int BN_BLINDING_cmp_thread(const BN_BLINDING *b, const CRYPTO_THREADID *tid)
	{
	b->thread_idptr = p;
	return CRYPTO_THREADID_cmp(&b->tid, tid);
	}

unsigned long BN_BLINDING_get_flags(const BN_BLINDING *b)
+1 −1
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ int main(int argc, char *argv[])
	BN_free(b);
	BN_free(m);
	BN_CTX_free(ctx);
	ERR_remove_state(0);
	ERR_remove_thread_state(NULL);
	CRYPTO_mem_leaks(out);
	BIO_free(out);
	printf(" done\n");
Loading