int main(int argc, char *argv[]) { BN_CTX *ctx = NULL; int nid, ret = 1; EC_builtin_curve *curves = NULL; size_t crv_len = 0, n = 0; BIO *out; CRYPTO_set_mem_debug(1); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); RAND_seed(rnd_seed, sizeof rnd_seed); out = BIO_new(BIO_s_file()); if (out == NULL) EXIT(1); BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); if ((ctx = BN_CTX_new()) == NULL) goto err; /* get a list of all internal curves */ crv_len = EC_get_builtin_curves(NULL, 0); curves = OPENSSL_malloc(sizeof(*curves) * crv_len); if (curves == NULL) goto err; if (!EC_get_builtin_curves(curves, crv_len)) goto err; /* NAMED CURVES TESTS */ for (n = 0; n < crv_len; n++) { nid = curves[n].nid; if (!test_ecdh_curve(nid, ctx, out)) goto err; } /* KATs */ for (n = 0; n < (sizeof(ecdh_kats)/sizeof(ecdh_kat_t)); n++) { if (!ecdh_kat(out, &ecdh_kats[n])) goto err; } ret = 0; err: ERR_print_errors_fp(stderr); OPENSSL_free(curves); BN_CTX_free(ctx); BIO_free(out); CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); #ifndef OPENSSL_NO_CRYPTO_MDEBUG if (CRYPTO_mem_leaks_fp(stderr) <= 0) ret = 1; #endif EXIT(ret); }
int main(int argc, char *argv[]) { BN_CTX *ctx = NULL; int nid, ret = 1; EC_builtin_curve *curves = NULL; size_t crv_len = 0, n = 0; BIO *out; CRYPTO_set_mem_debug(1); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); RAND_seed(rnd_seed, sizeof rnd_seed); out = BIO_new(BIO_s_file()); if (out == NULL) EXIT(1); BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); if ((ctx = BN_CTX_new()) == NULL) goto err; /* get a list of all internal curves */ crv_len = EC_get_builtin_curves(NULL, 0); curves = OPENSSL_malloc(sizeof(*curves) * crv_len); if (curves == NULL) goto err; if (!EC_get_builtin_curves(curves, crv_len)) goto err; /* NAMED CURVES TESTS */ for (n = 0; n < crv_len; n++) { nid = curves[n].nid; /* * Skipped for X25519 because affine coordinate operations are not * supported for this curve. * Higher level ECDH tests are performed in evptests.txt instead. */ if (nid == NID_X25519) continue; if (!test_ecdh_curve(nid, ctx, out)) goto err; } /* KATs */ for (n = 0; n < (sizeof(ecdh_kats)/sizeof(ecdh_kat_t)); n++) { if (!ecdh_kat(out, &ecdh_kats[n])) goto err; } /* NIST SP800-56A co-factor ECDH KATs */ for (n = 0; n < (sizeof(ecdh_cavs_kats)/sizeof(ecdh_cavs_kat_t)); n++) { if (!ecdh_cavs_kat(out, &ecdh_cavs_kats[n])) goto err; } ret = 0; err: ERR_print_errors_fp(stderr); OPENSSL_free(curves); BN_CTX_free(ctx); BIO_free(out); #ifndef OPENSSL_NO_CRYPTO_MDEBUG if (CRYPTO_mem_leaks_fp(stderr) <= 0) ret = 1; #endif EXIT(ret); }