remove OPENSSL_malloc and CRYPTO_malloc goo from the regress tests.
authorbeck <beck@openbsd.org>
Sat, 24 May 2014 13:57:18 +0000 (13:57 +0000)
committerbeck <beck@openbsd.org>
Sat, 24 May 2014 13:57:18 +0000 (13:57 +0000)
ok miod@ jsing@ guenther@

regress/lib/libcrypto/dh/dhtest.c
regress/lib/libcrypto/ec/ectest.c
regress/lib/libcrypto/ecdh/ecdhtest.c
regress/lib/libcrypto/ecdsa/ecdsatest.c
regress/lib/libcrypto/engine/enginetest.c
regress/lib/libcrypto/evp/evptest.c

index 916d7ae..9851c4f 100644 (file)
@@ -86,10 +86,6 @@ int main(int argc, char *argv[])
        int i,alen,blen,aout,bout,ret=1;
        BIO *out;
 
-       CRYPTO_malloc_debug_init();
-       CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
-       CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
-
        out=BIO_new(BIO_s_file());
        if (out == NULL) exit(1);
        BIO_set_fp(out,stdout,BIO_NOCLOSE);
@@ -141,7 +137,7 @@ int main(int argc, char *argv[])
        BIO_puts(out,"\n");
 
        alen=DH_size(a);
-       abuf=(unsigned char *)OPENSSL_malloc(alen);
+       abuf=malloc(alen);
        aout=DH_compute_key(abuf,b->pub_key,a);
 
        BIO_puts(out,"key1 =");
@@ -153,7 +149,7 @@ int main(int argc, char *argv[])
        BIO_puts(out,"\n");
 
        blen=DH_size(b);
-       bbuf=(unsigned char *)OPENSSL_malloc(blen);
+       bbuf=malloc(blen);
        bout=DH_compute_key(bbuf,a->pub_key,b);
 
        BIO_puts(out,"key2 =");
@@ -173,8 +169,8 @@ int main(int argc, char *argv[])
 err:
        ERR_print_errors_fp(stderr);
 
-       if (abuf != NULL) OPENSSL_free(abuf);
-       if (bbuf != NULL) OPENSSL_free(bbuf);
+       free(abuf);
+       free(bbuf);
        if(b != NULL) DH_free(b);
        if(a != NULL) DH_free(a);
        BIO_free(out);
index e302888..efb9a52 100644 (file)
@@ -1070,14 +1070,14 @@ static void internal_curve_test(void)
 
        crv_len = EC_get_builtin_curves(NULL, 0);
 
-       curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len);
+       curves = reallocarray(NULL, sizeof(EC_builtin_curve),  crv_len);
 
        if (curves == NULL)
                return;
 
        if (!EC_get_builtin_curves(curves, crv_len))
                {
-               OPENSSL_free(curves);
+               free(curves);
                return;
                }
 
@@ -1115,7 +1115,7 @@ static void internal_curve_test(void)
                fprintf(stdout, " failed\n\n");
                ABORT;
                }
-       OPENSSL_free(curves);
+       free(curves);
        return;
        }
 
@@ -1289,20 +1289,7 @@ void nistp_tests()
 #endif
 
 int main(int argc, char *argv[])
-       {       
-       
-       /* enable memory leak checking unless explicitly disabled */
-       if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
-               {
-               CRYPTO_malloc_debug_init();
-               CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
-               }
-       else
-               {
-               /* OPENSSL_DEBUG_MEMORY=off */
-               CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
-               }
-       CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
+       {
        ERR_load_crypto_strings();
 
        prime_field_tests();
index bf36224..385f680 100644 (file)
@@ -160,14 +160,14 @@ static int test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out)
        (void)BIO_flush(out);
 
        alen=KDF1_SHA1_len;
-       abuf=(unsigned char *)OPENSSL_malloc(alen);
+       abuf=malloc(alen);
        aout=ECDH_compute_key(abuf,alen,EC_KEY_get0_public_key(b),a,KDF1_SHA1);
 
        BIO_printf(out,".");
        (void)BIO_flush(out);
 
        blen=KDF1_SHA1_len;
-       bbuf=(unsigned char *)OPENSSL_malloc(blen);
+       bbuf=malloc(blen);
        bout=ECDH_compute_key(bbuf,blen,EC_KEY_get0_public_key(a),b,KDF1_SHA1);
 
        BIO_printf(out,".");
@@ -218,8 +218,8 @@ static int test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out)
 err:
        ERR_print_errors_fp(stderr);
 
-       if (abuf != NULL) OPENSSL_free(abuf);
-       if (bbuf != NULL) OPENSSL_free(bbuf);
+       free(abuf);
+       free(bbuf);
        if (x_a) BN_free(x_a);
        if (y_a) BN_free(y_a);
        if (x_b) BN_free(x_b);
@@ -235,10 +235,6 @@ int main(int argc, char *argv[])
        int ret=1;
        BIO *out;
 
-       CRYPTO_malloc_debug_init();
-       CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
-       CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
-
        out=BIO_new(BIO_s_file());
        if (out == NULL) exit(1);
        BIO_set_fp(out,stdout,BIO_NOCLOSE);
index 232fb9b..eadb43d 100644 (file)
@@ -184,7 +184,7 @@ int test_builtin(BIO *out)
        /* get a list of all internal curves */
        crv_len = EC_get_builtin_curves(NULL, 0);
 
-       curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len);
+       curves = reallocarray(NULL, sizeof(EC_builtin_curve), crv_len);
 
        if (curves == NULL)
                {
@@ -257,7 +257,7 @@ int test_builtin(BIO *out)
                (void)BIO_flush(out);
                /* create signature */
                sig_len = ECDSA_size(eckey);
-               if ((signature = OPENSSL_malloc(sig_len)) == NULL)
+               if ((signature = malloc(sig_len)) == NULL)
                        goto builtin_err;
                 if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey))
                        {
@@ -322,10 +322,8 @@ int test_builtin(BIO *out)
                        goto builtin_err;
                        }
                buf_len = 2 * bn_len;
-               if ((raw_buf = OPENSSL_malloc(buf_len)) == NULL)
+               if ((raw_buf = calloc(1, buf_len)) == NULL)
                        goto builtin_err;
-               /* Pad the bignums with leading zeroes. */
-               memset(raw_buf, 0, buf_len);
                BN_bn2bin(ecdsa_sig->r, raw_buf + bn_len - r_len);
                BN_bn2bin(ecdsa_sig->s, raw_buf + buf_len - s_len);
 
@@ -365,7 +363,7 @@ int test_builtin(BIO *out)
                /* cleanup */
                /* clean bogus errors */
                ERR_clear_error();
-               OPENSSL_free(signature);
+               free(signature);
                signature = NULL;
                EC_KEY_free(eckey);
                eckey = NULL;
@@ -373,7 +371,7 @@ int test_builtin(BIO *out)
                wrong_eckey = NULL;
                ECDSA_SIG_free(ecdsa_sig);
                ecdsa_sig = NULL;
-               OPENSSL_free(raw_buf);
+               free(raw_buf);
                raw_buf = NULL;
                }
 
@@ -385,12 +383,9 @@ builtin_err:
                EC_KEY_free(wrong_eckey);
        if (ecdsa_sig)
                ECDSA_SIG_free(ecdsa_sig);
-       if (signature)
-               OPENSSL_free(signature);
-       if (raw_buf)
-               OPENSSL_free(raw_buf);
-       if (curves)
-               OPENSSL_free(curves);
+       free(signature);
+       free(raw_buf);
+       free(curves);
 
        return ret;
        }
@@ -401,20 +396,6 @@ int main(void)
        BIO     *out;
 
        out = BIO_new_fp(stdout, BIO_NOCLOSE);
-       
-       /* enable memory leak checking unless explicitly disabled */
-       if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && 
-               (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
-               {
-               CRYPTO_malloc_debug_init();
-               CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
-               }
-       else
-               {
-               /* OPENSSL_DEBUG_MEMORY=off */
-               CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
-               }
-       CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
        ERR_load_crypto_strings();
 
index f4d70e7..5032dc4 100644 (file)
@@ -105,18 +105,6 @@ int main(int argc, char *argv[])
        ENGINE *new_h3 = NULL;
        ENGINE *new_h4 = NULL;
 
-       /* enable memory leak checking unless explicitly disabled */
-       if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
-               {
-               CRYPTO_malloc_debug_init();
-               CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
-               }
-       else
-               {
-               /* OPENSSL_DEBUG_MEMORY=off */
-               CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
-               }
-       CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
        ERR_load_crypto_strings();
 
        memset(block, 0, 512 * sizeof(ENGINE *));
@@ -258,8 +246,8 @@ cleanup_loop:
                }
        for(loop = 0; loop < 512; loop++)
                {
-               OPENSSL_free((void *)ENGINE_get_id(block[loop]));
-               OPENSSL_free((void *)ENGINE_get_name(block[loop]));
+               free((void *)ENGINE_get_id(block[loop]));
+               free((void *)ENGINE_get_name(block[loop]));
                }
        printf("\nTests completed happily\n");
        to_return = 0;
index c88bf13..f107ad5 100644 (file)
@@ -306,9 +306,6 @@ main(int argc, char **argv)
                fprintf(stderr, "%s <test file>\n",argv[0]);
                exit(1);
        }
-       CRYPTO_malloc_debug_init();
-       CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
-       CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
        szTestFile = argv[1];