| 691 | }*/ |
| 692 | |
| 693 | void test_crypto(const std::string &test_vectors_folder, |
| 694 | const std::vector<std::string> &selected_test_cases = std::vector<std::string>(), |
| 695 | const std::string &test_results_log = "", const bool break_on_failure = false) { |
| 696 | // test_fe(); |
| 697 | // test_jade(); |
| 698 | |
| 699 | std::map<std::string, test_case> test_function; |
| 700 | test_function["elligator"] = test_elligator; |
| 701 | test_function["check_key"] = test_check_key; |
| 702 | test_function["check_ring_signature"] = test_check_ring_signature; |
| 703 | test_function["check_ring_signature_amethyst"] = test_check_ring_signature_amethyst; |
| 704 | test_function["check_ring_signature_amethyst_big"] = test_check_ring_signature_amethyst; |
| 705 | test_function["check_scalar"] = test_check_scalar; |
| 706 | test_function["check_signature"] = test_check_signature; |
| 707 | test_function["derive_public_key"] = test_derive_public_key; |
| 708 | test_function["derive_secret_key"] = test_derive_secret_key; |
| 709 | test_function["generate_key_derivation"] = test_generate_key_derivation; |
| 710 | test_function["generate_key_image"] = test_generate_key_image; |
| 711 | test_function["generate_ring_signature"] = test_generate_ring_signature; |
| 712 | test_function["generate_ring_signature_amethyst"] = test_generate_ring_signature_amethyst; |
| 713 | test_function["generate_ring_signature_amethyst_big"] = test_generate_ring_signature_amethyst; |
| 714 | test_function["generate_ring_signature_big"] = test_generate_ring_signature; |
| 715 | test_function["generate_signature"] = test_generate_signature; |
| 716 | test_function["hash_to_scalar"] = test_hash_to_scalar; |
| 717 | test_function["hash_to_subgroup"] = test_hash_to_subgroup; |
| 718 | test_function["random_keypair"] = test_random_keypair; |
| 719 | test_function["random_scalar"] = test_random_scalar; |
| 720 | test_function["secret_key_to_public_key"] = test_secret_key_to_public_key; |
| 721 | test_function["underive_public_key"] = test_underive_public_key; |
| 722 | |
| 723 | std::vector<std::string> test_cases = select_tests_to_run(selected_test_cases, test_function); |
| 724 | |
| 725 | size_t max_name_size = max_length(test_cases); |
| 726 | for (auto &name : test_cases) { |
| 727 | std::stringstream test_file_path_buf; |
| 728 | test_file_path_buf << test_vectors_folder << "/" |
| 729 | << "test_" << name << ".txt"; |
| 730 | auto test_file_path = test_file_path_buf.str(); |
| 731 | std::fstream input(test_file_path, std::ios_base::in); |
| 732 | if (!input.is_open()) { |
| 733 | std::cerr << "Could not open test vectors with name \"" << test_file_path << "\" for test \"" << name |
| 734 | << "\"." << std::endl; |
| 735 | continue; |
| 736 | } |
| 737 | input.exceptions(std::ios_base::badbit); |
| 738 | |
| 739 | std::vector<size_t> passed_tests, failed_tests; |
| 740 | run_test_suite(name, input, test_function, break_on_failure, passed_tests, failed_tests); |
| 741 | |
| 742 | std::stringstream name_buf; |
| 743 | name_buf << "\"" << name << "\": "; |
| 744 | std::cout << "In test suite " << std::left << std::setfill(' ') |
| 745 | << std::setw(static_cast<int>(max_name_size + 4)) << name_buf.str() << passed_tests.size() |
| 746 | << " passed, " << failed_tests.size() << " failed." << std::endl; |
| 747 | |
| 748 | if (!failed_tests.empty()) { |
| 749 | std::cout << "\tFailed tests: "; |
| 750 | std::cout << failed_tests[0]; |
nothing calls this directly
no test coverage detected