Move to REF_DEBUG, for consistency.
[openssl.git] / crypto / dh / dh_lib.c
index cce2514bbfca272bacdd50e620f1ffe09a06a315..9167d69ea8d6214dbeca72b743dd13872ddea764 100644 (file)
@@ -1,4 +1,3 @@
-/* crypto/dh/dh_lib.c */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -64,8 +63,6 @@
 # include <openssl/engine.h>
 #endif
 
-const char DH_version[] = "Diffie-Hellman" OPENSSL_VERSION_PTEXT;
-
 static const DH_METHOD *default_DH_method = NULL;
 
 void DH_set_default_method(const DH_METHOD *meth)
@@ -109,7 +106,7 @@ DH *DH_new(void)
 
 DH *DH_new_method(ENGINE *engine)
 {
-    DH *ret = OPENSSL_malloc(sizeof(*ret));
+    DH *ret = OPENSSL_zalloc(sizeof(*ret));
 
     if (ret == NULL) {
         DHerr(DH_F_DH_NEW_METHOD, ERR_R_MALLOC_FAILURE);
@@ -138,19 +135,6 @@ DH *DH_new_method(ENGINE *engine)
     }
 #endif
 
-    ret->pad = 0;
-    ret->version = 0;
-    ret->p = NULL;
-    ret->g = NULL;
-    ret->length = 0;
-    ret->pub_key = NULL;
-    ret->priv_key = NULL;
-    ret->q = NULL;
-    ret->j = NULL;
-    ret->seed = NULL;
-    ret->seedlen = 0;
-    ret->counter = NULL;
-    ret->method_mont_p = NULL;
     ret->references = 1;
     ret->flags = ret->meth->flags;
     CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);
@@ -173,17 +157,10 @@ void DH_free(DH *r)
     if (r == NULL)
         return;
     i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DH);
-#ifdef REF_PRINT
-    REF_PRINT("DH", r);
-#endif
+    REF_PRINT_COUNT("DH", r);
     if (i > 0)
         return;
-#ifdef REF_CHECK
-    if (i < 0) {
-        fprintf(stderr, "DH_free, bad reference count\n");
-        abort();
-    }
-#endif
+    REF_ASSERT_ISNT(i < 0);
 
     if (r->meth->finish)
         r->meth->finish(r);
@@ -208,23 +185,10 @@ void DH_free(DH *r)
 int DH_up_ref(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)
-{
-    return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DH, argl, argp,
-                                   new_func, dup_func, free_func);
+    REF_PRINT_COUNT("DH", r);
+    REF_ASSERT_ISNT(i < 2);
+    return ((i > 1) ? 1 : 0);
 }
 
 int DH_set_ex_data(DH *d, int idx, void *arg)