-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimal test with crypto3::sha256 usage
- Loading branch information
1 parent
45b35aa
commit d3fb1d7
Showing
8 changed files
with
135 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule modules
updated
4 files
+11 −9 | share/modules/cmake/CMConfig.cmake | |
+9 −5 | share/modules/cmake/CMExport.cmake | |
+1 −1 | share/modules/cmake/CMInstallTargets.cmake | |
+26 −23 | share/modules/cmake/CMPkgConfig.cmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <nil/crypto3/hash/algorithm/hash.hpp> | ||
#include <nil/crypto3/hash/sha2.hpp> | ||
|
||
using namespace nil::crypto3; | ||
|
||
typename hashes::sha2<256>::block_type hash_pair( | ||
hashes::sha2<256>::block_type left, | ||
hashes::sha2<256>::block_type right | ||
) { | ||
return hash<hashes::sha2<256>>(left, right); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,10 @@ | ||
#include <nil/crypto3/algebra/curves/pallas.hpp> | ||
#include "lib.hpp" | ||
|
||
using namespace nil::crypto3::algebra::curves; | ||
typename pallas::base_field_type::value_type pow(typename pallas::base_field_type::value_type a, int n) { | ||
if (n == 0) | ||
return 1; | ||
using namespace nil::crypto3; | ||
|
||
typename pallas::base_field_type::value_type res = 1; | ||
for (int i = 0; i < n; ++i) { | ||
res *= a; | ||
} | ||
return res; | ||
} | ||
|
||
[[circuit]] typename pallas::base_field_type::value_type | ||
field_arithmetic_example(typename pallas::base_field_type::value_type a, | ||
typename pallas::base_field_type::value_type b) { | ||
|
||
typename pallas::base_field_type::value_type c = (a + b) * a + b * (a + b) * (a + b); | ||
const typename pallas::base_field_type::value_type constant = 0x12345678901234567890_cppui255; | ||
return c * c * c / (b - a) + pow(a, 2) + constant; | ||
[[circuit]] typename hashes::sha2<256>::block_type circuit( | ||
hashes::sha2<256>::block_type left, | ||
hashes::sha2<256>::block_type right | ||
) { | ||
return hash_pair(left, right); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#---------------------------------------------------------------------------# | ||
# Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation> | ||
# | ||
# Distributed under the Boost Software License, Version 1.0 | ||
# See accompanying file LICENSE_1_0.txt or copy at | ||
# http://www.boost.org/LICENSE_1_0.txt | ||
#---------------------------------------------------------------------------# | ||
|
||
include(CMTest) | ||
|
||
if(NOT Boost_UNIT_TEST_FRAMEWORK_FOUND) | ||
cm_find_package(Boost REQUIRED COMPONENTS unit_test_framework) | ||
endif() | ||
|
||
cm_test_link_libraries(${Boost_LIBRARIES} template_lib) | ||
|
||
macro(define_test name) | ||
cm_test(NAME ${name}_test SOURCES ${name}.cpp) | ||
|
||
set_target_properties(${name}_test PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED TRUE) | ||
|
||
get_target_property(target_type Boost::unit_test_framework TYPE) | ||
if(target_type STREQUAL "SHARED_LIB") | ||
target_compile_definitions(${name}_test PRIVATE BOOST_TEST_DYN_LINK) | ||
elseif(target_type STREQUAL "STATIC_LIB") | ||
|
||
endif() | ||
|
||
# if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
# target_compile_options(${name}_test PRIVATE "-fconstexpr-steps=2147483647") | ||
# elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
# target_compile_options(${name}_test PRIVATE "-fconstexpr-ops-limit=4294967295") | ||
# endif() | ||
|
||
# string(CONCAT TEST_DATA ${CMAKE_CURRENT_SOURCE_DIR} "/data/" "${name}" ".json") | ||
# target_compile_definitions(hash_${name}_test PRIVATE TEST_DATA="${TEST_DATA}") | ||
|
||
endmacro() | ||
|
||
set(TESTS_NAMES | ||
"lib" | ||
) | ||
|
||
foreach(TEST_NAME ${TESTS_NAMES}) | ||
define_test(${TEST_NAME}) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#define BOOST_TEST_MODULE LibTest | ||
#include <boost/test/unit_test.hpp> | ||
#include <boost/test/data/test_case.hpp> | ||
#include <boost/algorithm/string/join.hpp> | ||
|
||
#include <nil/crypto3/hash/algorithm/hash.hpp> | ||
#include <nil/crypto3/hash/sha2.hpp> | ||
|
||
#include "lib.hpp" | ||
|
||
std::string intToHex(unsigned int value) { | ||
std::stringstream sstream; | ||
sstream << std::hex << value; | ||
return sstream.str(); | ||
} | ||
|
||
std::string hash256ToHex(hashes::sha2<256>::block_type hash) { | ||
std::array<std::string, 16> elems; | ||
std::transform(hash.begin(), hash.end(), elems.begin(), intToHex); | ||
return boost::algorithm::join(elems, ""); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE(lib_test) | ||
|
||
BOOST_AUTO_TEST_CASE(test_balance) { | ||
std::string expected = "9a5ee745fda52931b4174b0ea83af76e48f32e03c9ad6fc563c580c2497302fd"; | ||
typename hashes::sha2<256>::block_type root = hash_pair( | ||
hashes::sha2<256>::block_type {1}, | ||
hashes::sha2<256>::block_type {2} | ||
); | ||
BOOST_TEST(hash256ToHex(root) == expected); | ||
} | ||
BOOST_AUTO_TEST_SUITE_END() |