From: Geoff Thorpe Date: Sat, 25 Aug 2001 17:24:21 +0000 (+0000) Subject: Give DH, DSA, and RSA functions to "up" their reference counts. Otherwise, X-Git-Tag: OpenSSL_0_9_6c~123^2~60 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5cbc2e8bc187058e2ec2f17f53c3429c16dbc0d8;p=oweals%2Fopenssl.git Give DH, DSA, and RSA functions to "up" their reference counts. Otherwise, dependant code has to directly increment the "references" value of each such structure using the corresponding lock. Apart from code duplication, this provided no "REF_CHECK/REF_PRINT" checking and violated encapsulation. --- diff --git a/crypto/dh/dh.h b/crypto/dh/dh.h index 2b9a059373..b6601c66f8 100644 --- a/crypto/dh/dh.h +++ b/crypto/dh/dh.h @@ -166,6 +166,7 @@ DH *DH_new_method(struct engine_st *engine); DH * DH_new(void); void DH_free(DH *dh); +int DH_up(DH *dh); int DH_size(const DH *dh); int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); diff --git a/crypto/dh/dh_lib.c b/crypto/dh/dh_lib.c index 7a6e620715..f96b454757 100644 --- a/crypto/dh/dh_lib.c +++ b/crypto/dh/dh_lib.c @@ -219,6 +219,22 @@ void DH_free(DH *r) OPENSSL_free(r); } +int DH_up(DH *r) + { + int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DH); +#ifdef REF_PRINT + REF_PRINT("DH",r); +#endif +#ifdef REF_CHECK + if (i < 2) + { + fprintf(stderr, "DH_up, bad reference count\n"); + abort(); + } +#endif + return ((i > 1) ? 1 : 0); + } + int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) { diff --git a/crypto/dsa/dsa.h b/crypto/dsa/dsa.h index 58cf7b5c76..7fc8fd303b 100644 --- a/crypto/dsa/dsa.h +++ b/crypto/dsa/dsa.h @@ -177,6 +177,9 @@ DSA * DSA_new_method(DSA_METHOD *meth); #else DSA * DSA_new_method(struct engine_st *engine); #endif +void DSA_free (DSA *r); +/* "up" the DSA object's reference count */ +int DSA_up(DSA *r); int DSA_size(const DSA *); /* next 4 return -1 on error */ int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp); @@ -184,7 +187,6 @@ int DSA_sign(int type,const unsigned char *dgst,int dlen, unsigned char *sig, unsigned int *siglen, DSA *dsa); int DSA_verify(int type,const unsigned char *dgst,int dgst_len, const unsigned char *sigbuf, int siglen, DSA *dsa); -void DSA_free (DSA *r); int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); int DSA_set_ex_data(DSA *d, int idx, void *arg); diff --git a/crypto/dsa/dsa_lib.c b/crypto/dsa/dsa_lib.c index 5855568741..98878dfaa3 100644 --- a/crypto/dsa/dsa_lib.c +++ b/crypto/dsa/dsa_lib.c @@ -228,6 +228,22 @@ void DSA_free(DSA *r) OPENSSL_free(r); } +int DSA_up(DSA *r) + { + int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA); +#ifdef REF_PRINT + REF_PRINT("DSA",r); +#endif +#ifdef REF_CHECK + if (i < 2) + { + fprintf(stderr, "DSA_up, bad reference count\n"); + abort(); + } +#endif + return ((i > 1) ? 1 : 0); + } + int DSA_size(const DSA *r) { int ret,i; diff --git a/crypto/rsa/rsa.h b/crypto/rsa/rsa.h index 488f6798fc..9116a6e567 100644 --- a/crypto/rsa/rsa.h +++ b/crypto/rsa/rsa.h @@ -199,6 +199,8 @@ int RSA_public_decrypt(int flen, const unsigned char *from, int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to, RSA *rsa,int padding); void RSA_free (RSA *r); +/* "up" the RSA object's reference count */ +int RSA_up(RSA *r); int RSA_flags(const RSA *r); diff --git a/crypto/rsa/rsa_lib.c b/crypto/rsa/rsa_lib.c index 4fd919808c..3accf013f3 100644 --- a/crypto/rsa/rsa_lib.c +++ b/crypto/rsa/rsa_lib.c @@ -248,6 +248,22 @@ void RSA_free(RSA *r) OPENSSL_free(r); } +int RSA_up(RSA *r) + { + int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA); +#ifdef REF_PRINT + REF_PRINT("RSA",r); +#endif +#ifdef REF_CHECK + if (i < 2) + { + fprintf(stderr, "RSA_up, bad reference count\n"); + abort(); + } +#endif + return ((i > 1) ? 1 : 0); + } + int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) {