|
32 | 32 | #include <iostream>
|
33 | 33 | #include <iomanip>
|
34 | 34 |
|
35 |
| -#include <nil/crypto3/algebra/curves/curve25519.hpp> |
36 | 35 | #include <nil/marshalling/status_type.hpp>
|
37 | 36 | #include <nil/marshalling/field_type.hpp>
|
38 | 37 | #include <nil/marshalling/endianness.hpp>
|
39 | 38 |
|
40 | 39 | #include <nil/crypto3/algebra/random_element.hpp>
|
| 40 | +#include <nil/crypto3/algebra/curves/curve25519.hpp> |
41 | 41 | #include <nil/crypto3/algebra/curves/bls12.hpp>
|
| 42 | +#include <nil/crypto3/algebra/curves/jubjub.hpp> |
42 | 43 |
|
43 | 44 | #include <nil/marshalling/algorithms/pack.hpp>
|
44 | 45 | #include <nil/marshalling/algorithms/unpack.hpp>
|
@@ -106,6 +107,54 @@ BOOST_AUTO_TEST_CASE(curve_element_bls12_381_g2) {
|
106 | 107 | std::cout << "BLS12-381 g2 group test finished" << std::endl;
|
107 | 108 | }
|
108 | 109 |
|
| 110 | +BOOST_AUTO_TEST_CASE(curve_element_jubjub_g1) { |
| 111 | + using curve_type = nil::crypto3::algebra::curves::jubjub; |
| 112 | + using group_type = typename curve_type::template g1_type<nil::crypto3::algebra::curves::coordinates::affine, nil::crypto3::algebra::curves::forms::twisted_edwards>; |
| 113 | + using group_value_type = typename group_type::value_type; |
| 114 | + using field_type = typename group_value_type::field_type; |
| 115 | + using field_value_type = typename field_type::value_type; |
| 116 | + using integral_type = typename field_type::integral_type; |
| 117 | + |
| 118 | + /// correct blobs |
| 119 | + nil::marshalling::status_type status; |
| 120 | + std::vector<std::uint8_t> blob = {0x5f, 0x50, 0xa1, 0xdc, 0x87, 0xd9, 0x9b, 0x13, 0xb3, 0x60, 0x2a, 0xe1, 0x25, 0xce, 0x0, 0x66, 0xe2, 0xab, 0x19, 0x8c, 0x92, 0x69, 0x94, 0x13, 0x13, 0x60, 0x57, 0xa8, 0x1, 0x21, 0x2, 0x41}; |
| 121 | + group_value_type expected = group_value_type(integral_type("34431432384332876907572759816814758423306059590054253468360681509944827160006"), integral_type("29404096654359671878917481308573927330727282437544669652502934947226949079135")); |
| 122 | + group_value_type point = nil::marshalling::pack<nil::marshalling::option::little_endian, group_value_type>(blob, status); |
| 123 | + BOOST_CHECK(point == expected); |
| 124 | + BOOST_CHECK(status == nil::marshalling::status_type::success); |
| 125 | + |
| 126 | + blob = {0x8c, 0x59, 0x25, 0x37, 0x5a, 0x98, 0xc9, 0xd0, 0x5d, 0xe5, 0xb4, 0xf5, 0xc4, 0x7, 0xad, 0x7f, 0x6c, 0xf0, 0xf7, 0x69, 0xbf, 0x80, 0xca, 0x2c, 0x91, 0x33, 0xcb, 0xc4, 0xd8, 0xa1, 0x3, 0x85}; |
| 127 | + expected = group_value_type(integral_type("51845316313984588131191635700847278221892447412874386787531559514756013022179"), integral_type("2267981809345781868602884763436767012634799368758626259799403354148032567692")); |
| 128 | + point = nil::marshalling::pack<nil::marshalling::option::little_endian, group_value_type>(blob, status); |
| 129 | + BOOST_CHECK(point == expected); |
| 130 | + BOOST_CHECK(status == nil::marshalling::status_type::success); |
| 131 | + |
| 132 | + blob = {0xa4, 0x13, 0x70, 0xbc, 0x2e, 0x20, 0x40, 0x11, 0x57, 0x60, 0xd5, 0x53, 0x91, 0xcb, 0x8d, 0x6, 0x23, 0x74, 0xc1, 0x4c, 0xca, 0xe2, 0xa5, 0xe, 0x5e, 0x66, 0x85, 0x24, 0x81, 0x4f, 0x7a, 0xbb}; |
| 133 | + expected = group_value_type(integral_type("25651767798190354528910599415746062172834836761677597036046682114031745402655"), integral_type("26902562127956316343893262683171938435197568407043214449144600616790024786852")); |
| 134 | + point = nil::marshalling::pack<nil::marshalling::option::little_endian, group_value_type>(blob, status); |
| 135 | + BOOST_CHECK(point == expected); |
| 136 | + BOOST_CHECK(status == nil::marshalling::status_type::success); |
| 137 | + |
| 138 | + blob = {0xfc, 0xc9, 0x8e, 0x93, 0xc, 0x7f, 0xc3, 0xfc, 0x89, 0xc4, 0x10, 0x66, 0x6, 0xd, 0x1, 0xeb, 0xf8, 0xc7, 0x82, 0x19, 0x16, 0xfd, 0x12, 0x5b, 0x87, 0x55, 0x69, 0xc4, 0x81, 0xd2, 0xdf, 0x5c}; |
| 139 | + expected = group_value_type(integral_type("40185837415754419626270588927415047095813982975230357263686068930519460729080"), integral_type("42008241830356574617713311689533669924455940847366394238316645523644983724540")); |
| 140 | + point = nil::marshalling::pack<nil::marshalling::option::little_endian, group_value_type>(blob, status); |
| 141 | + BOOST_CHECK(point == expected); |
| 142 | + BOOST_CHECK(status == nil::marshalling::status_type::success); |
| 143 | + |
| 144 | + /// incorrect blobs |
| 145 | + blob = {0x8f, 0xcb, 0xae, 0xbb, 0x2b, 0x32, 0xa6, 0x98, 0xcb, 0x6, 0xba, 0x7f, 0xa7, 0xb7, 0xd9, 0x4b, 0x37, 0x60, 0x2a, 0x7e, 0xa6, 0x20, 0xdc, 0xe2, 0x92, 0xf8, 0x87, 0xca, 0x5, 0xf7, 0x73, 0x7a}; |
| 146 | + nil::marshalling::pack<nil::marshalling::option::little_endian, group_value_type>(blob, status); |
| 147 | + BOOST_CHECK(status != nil::marshalling::status_type::success); |
| 148 | + |
| 149 | + blob = {0x64, 0x43, 0x6c, 0xd4, 0x66, 0xa5, 0x8c, 0x71, 0x2f, 0x8c, 0x6b, 0xa7, 0x82, 0x5b, 0x55, 0xef, 0xb, 0x9f, 0x4a, 0x1e, 0xdc, 0x26, 0xa5, 0x55, 0xf9, 0x35, 0x4e, 0x3e, 0x95, 0xd9, 0xe1, 0x8}; |
| 150 | + nil::marshalling::pack<nil::marshalling::option::little_endian, group_value_type>(blob, status); |
| 151 | + BOOST_CHECK(status != nil::marshalling::status_type::success); |
| 152 | + |
| 153 | + blob = {0x0, 0xde, 0xe0, 0x91, 0xab, 0x96, 0xb2, 0x2, 0x28, 0xc0, 0x11, 0x5c, 0x1d, 0x1d, 0x21, 0xef, 0x9a, 0xfe, 0x63, 0x55, 0x3f, 0x2c, 0xad, 0xc3, 0xbd, 0x16, 0x4f, 0x8d, 0x92, 0x2f, 0x3, 0x20}; |
| 154 | + nil::marshalling::pack<nil::marshalling::option::little_endian, group_value_type>(blob, status); |
| 155 | + BOOST_CHECK(status != nil::marshalling::status_type::success); |
| 156 | +} |
| 157 | + |
109 | 158 | BOOST_AUTO_TEST_CASE(curve_element_curve25519_g1) {
|
110 | 159 | using curve_type = nil::crypto3::algebra::curves::curve25519;
|
111 | 160 | using group_type = typename curve_type::g1_type<>;
|
|
0 commit comments