1
0
Fork 0
forked from lthn/blockchain

crypto: generator U + assertion tests for generators

This commit is contained in:
sowle 2023-02-08 18:16:04 +01:00
parent baf2b507ec
commit 5568e0eeaf
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
4 changed files with 26 additions and 12 deletions

View file

@ -23,7 +23,7 @@ namespace crypto
const point_t c_point_H = { 0x05087c1f5b9b32d6, 0x00547595f445c3b5, 0x764df64578552f2a, 0x8a49a651e0e0da45 }; // == Hp(G), this is being checked in bpp_basics
const point_t c_point_H2 = { 0x70c8d1ab9dbf1cc0, 0xc561bb12639a8516, 0x3cfff1def9e5b268, 0xe0936386f3bcce1a }; // == Hp("h2_generator"), checked in bpp_basics
const point_t c_point_U = { 0xc9d2f543dbbc253a, 0x87099e9ac33d06dd, 0x76bcf12dcf6ffcba, 0x20384a4a88752d32 }; // == Hp("U_generator"), checked in
const point_t c_point_X = { 0xc9d2f543dbbc253a, 0x87099e9ac33d06dd, 0x76bcf12dcf6ffcba, 0x20384a4a88752d32 }; // == Hp("X_generator"), checked in clsag_ggxg_basics
const point_t c_point_0 = point_t(point_t::tag_zero());

View file

@ -917,6 +917,7 @@ namespace crypto
extern const point_t c_point_H;
extern const point_t c_point_H2;
extern const point_t c_point_U;
extern const point_t c_point_X;
extern const point_t c_point_0;
extern const point_t c_point_H_plus_G;
@ -1199,6 +1200,13 @@ namespace crypto
return result;
}
static point_t hp(const std::string& str)
{
point_t result;
ge_bytes_hash_to_ec(&result.m_p3, str.data(), str.size());
return result;
}
}; // hash_helper_t struct

View file

@ -12,6 +12,7 @@
#include "common/crypto_stream_operators.h"
#include "common/varint.h"
#include "currency_core/difficulty.h"
#include "currency_core/currency_basic.h"
#include "crypto/crypto-sugar.h"
#include "crypto/range_proofs.h"
@ -500,6 +501,22 @@ struct test_keeper_t
// Tests
//
TEST(crypto, basics)
{
ASSERT_EQ(c_point_H, hash_helper_t::hp(c_point_G));
ASSERT_EQ(c_point_H2, hash_helper_t::hp("h2_generator"));
ASSERT_EQ(c_point_U, hash_helper_t::hp("U_generator"));
ASSERT_EQ(c_point_X, hash_helper_t::hp("X_generator"));
ASSERT_EQ(currency::native_coin_asset_id, c_point_H.to_public_key());
LOG_PRINT_L0("c_point_0 = " << c_point_0 << " = { " << c_point_0.to_hex_comma_separated_uint64_str() << " }");
LOG_PRINT_L0("Zano G = " << c_point_G << " = { " << c_point_G.to_hex_comma_separated_bytes_str() << " }");
LOG_PRINT_L0("Zano H = " << c_point_H << " = { " << c_point_H.to_hex_comma_separated_uint64_str() << " }");
LOG_PRINT_L0("Zano H2 = " << c_point_H2 << " = { " << c_point_H2.to_hex_comma_separated_uint64_str() << " }");
}
#include "crypto_tests_performance.h"
TEST(crypto, ge_scalarmult_vartime_p3)

View file

@ -58,17 +58,6 @@ TEST(bpp, basics)
std::cout << scalar_t::random().to_string_as_secret_key() << ENDL;
*/
point_t H = hash_helper_t::hp(c_point_G);
ASSERT_EQ(H, c_point_H);
std::string h2_hash_str("h2_generator");
point_t H2 = hash_helper_t::hp(h2_hash_str.c_str(), h2_hash_str.size());
ASSERT_EQ(H2, c_point_H2);
LOG_PRINT_L0("c_point_0 = " << c_point_0 << " = { " << c_point_0.to_hex_comma_separated_uint64_str() << " }");
LOG_PRINT_L0("Zano G = " << c_point_G << " = { " << c_point_G.to_hex_comma_separated_bytes_str() << " }");
LOG_PRINT_L0("Zano H = " << H << " = { " << H.to_hex_comma_separated_uint64_str() << " }");
LOG_PRINT_L0("Zano H2 = " << H2 << " = { " << H2.to_hex_comma_separated_uint64_str() << " }");
auto foo = [&](scalar_t v){
scalar_vec_t values = { v };
scalar_vec_t masks = { scalar_t::random() };