summaryrefslogtreecommitdiff
path: root/src/regress/lib/libcrypto/ecdsa/ecdsatest.c
diff options
context:
space:
mode:
authorbeck <>2014-05-24 13:57:18 +0000
committerbeck <>2014-05-24 13:57:18 +0000
commitcae65df81b69f410afddb3d880daac7c43ce3daf (patch)
treedeb94273e62c0be2f39f578173b1232887e77c64 /src/regress/lib/libcrypto/ecdsa/ecdsatest.c
parent4eb4d7bb8c263141ef39d6b0ad13ef197e422063 (diff)
downloadopenbsd-cae65df81b69f410afddb3d880daac7c43ce3daf.tar.gz
openbsd-cae65df81b69f410afddb3d880daac7c43ce3daf.tar.bz2
openbsd-cae65df81b69f410afddb3d880daac7c43ce3daf.zip
remove OPENSSL_malloc and CRYPTO_malloc goo from the regress tests.
ok miod@ jsing@ guenther@
Diffstat (limited to 'src/regress/lib/libcrypto/ecdsa/ecdsatest.c')
-rw-r--r--src/regress/lib/libcrypto/ecdsa/ecdsatest.c35
1 files changed, 8 insertions, 27 deletions
diff --git a/src/regress/lib/libcrypto/ecdsa/ecdsatest.c b/src/regress/lib/libcrypto/ecdsa/ecdsatest.c
index 232fb9b4d1..eadb43d652 100644
--- a/src/regress/lib/libcrypto/ecdsa/ecdsatest.c
+++ b/src/regress/lib/libcrypto/ecdsa/ecdsatest.c
@@ -184,7 +184,7 @@ int test_builtin(BIO *out)
184 /* get a list of all internal curves */ 184 /* get a list of all internal curves */
185 crv_len = EC_get_builtin_curves(NULL, 0); 185 crv_len = EC_get_builtin_curves(NULL, 0);
186 186
187 curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len); 187 curves = reallocarray(NULL, sizeof(EC_builtin_curve), crv_len);
188 188
189 if (curves == NULL) 189 if (curves == NULL)
190 { 190 {
@@ -257,7 +257,7 @@ int test_builtin(BIO *out)
257 (void)BIO_flush(out); 257 (void)BIO_flush(out);
258 /* create signature */ 258 /* create signature */
259 sig_len = ECDSA_size(eckey); 259 sig_len = ECDSA_size(eckey);
260 if ((signature = OPENSSL_malloc(sig_len)) == NULL) 260 if ((signature = malloc(sig_len)) == NULL)
261 goto builtin_err; 261 goto builtin_err;
262 if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey)) 262 if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey))
263 { 263 {
@@ -322,10 +322,8 @@ int test_builtin(BIO *out)
322 goto builtin_err; 322 goto builtin_err;
323 } 323 }
324 buf_len = 2 * bn_len; 324 buf_len = 2 * bn_len;
325 if ((raw_buf = OPENSSL_malloc(buf_len)) == NULL) 325 if ((raw_buf = calloc(1, buf_len)) == NULL)
326 goto builtin_err; 326 goto builtin_err;
327 /* Pad the bignums with leading zeroes. */
328 memset(raw_buf, 0, buf_len);
329 BN_bn2bin(ecdsa_sig->r, raw_buf + bn_len - r_len); 327 BN_bn2bin(ecdsa_sig->r, raw_buf + bn_len - r_len);
330 BN_bn2bin(ecdsa_sig->s, raw_buf + buf_len - s_len); 328 BN_bn2bin(ecdsa_sig->s, raw_buf + buf_len - s_len);
331 329
@@ -365,7 +363,7 @@ int test_builtin(BIO *out)
365 /* cleanup */ 363 /* cleanup */
366 /* clean bogus errors */ 364 /* clean bogus errors */
367 ERR_clear_error(); 365 ERR_clear_error();
368 OPENSSL_free(signature); 366 free(signature);
369 signature = NULL; 367 signature = NULL;
370 EC_KEY_free(eckey); 368 EC_KEY_free(eckey);
371 eckey = NULL; 369 eckey = NULL;
@@ -373,7 +371,7 @@ int test_builtin(BIO *out)
373 wrong_eckey = NULL; 371 wrong_eckey = NULL;
374 ECDSA_SIG_free(ecdsa_sig); 372 ECDSA_SIG_free(ecdsa_sig);
375 ecdsa_sig = NULL; 373 ecdsa_sig = NULL;
376 OPENSSL_free(raw_buf); 374 free(raw_buf);
377 raw_buf = NULL; 375 raw_buf = NULL;
378 } 376 }
379 377
@@ -385,12 +383,9 @@ builtin_err:
385 EC_KEY_free(wrong_eckey); 383 EC_KEY_free(wrong_eckey);
386 if (ecdsa_sig) 384 if (ecdsa_sig)
387 ECDSA_SIG_free(ecdsa_sig); 385 ECDSA_SIG_free(ecdsa_sig);
388 if (signature) 386 free(signature);
389 OPENSSL_free(signature); 387 free(raw_buf);
390 if (raw_buf) 388 free(curves);
391 OPENSSL_free(raw_buf);
392 if (curves)
393 OPENSSL_free(curves);
394 389
395 return ret; 390 return ret;
396 } 391 }
@@ -401,20 +396,6 @@ int main(void)
401 BIO *out; 396 BIO *out;
402 397
403 out = BIO_new_fp(stdout, BIO_NOCLOSE); 398 out = BIO_new_fp(stdout, BIO_NOCLOSE);
404
405 /* enable memory leak checking unless explicitly disabled */
406 if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) &&
407 (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
408 {
409 CRYPTO_malloc_debug_init();
410 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
411 }
412 else
413 {
414 /* OPENSSL_DEBUG_MEMORY=off */
415 CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
416 }
417 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
418 399
419 ERR_load_crypto_strings(); 400 ERR_load_crypto_strings();
420 401