Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/crypto/crypto-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ DISABLE_VS_WARNINGS(4146 4244)
static void ge_madd(ge_p1p1 *, const ge_p3 *, const ge_precomp *);
static void ge_msub(ge_p1p1 *, const ge_p3 *, const ge_precomp *);
static void ge_p2_0(ge_p2 *);
static void ge_p3_dbl(ge_p1p1 *, const ge_p3 *);
static void fe_divpowm1(fe, const fe, const fe);

/* Common functions */
Expand Down Expand Up @@ -1569,7 +1568,7 @@ static void ge_p3_0(ge_p3 *h) {
r = 2 * p
*/

static void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p) {
void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p) {
ge_p2 q;
ge_p3_to_p2(&q, p);
ge_p2_dbl(r, &q);
Expand Down
4 changes: 4 additions & 0 deletions src/crypto/crypto-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ void ge_p1p1_to_p3(ge_p3 *, const ge_p1p1 *);

void ge_p2_dbl(ge_p1p1 *, const ge_p2 *);

/* From ge_p3_dbl.c */

void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p);

/* From ge_p3_to_cached.c */

extern const fe fe_d2;
Expand Down
57 changes: 25 additions & 32 deletions src/ringct/rctOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <boost/lexical_cast.hpp>
#include "crypto/generators.h"
#include "misc_log_ex.h"
#include "rctOps.h"
using namespace crypto;
Expand Down Expand Up @@ -216,40 +217,32 @@ static const zero_commitment zero_commitments[] = {
{ (uint64_t)10000000000000000000ull, {{0x65, 0x8d, 0x1, 0x37, 0x6d, 0x18, 0x63, 0xe7, 0x7b, 0x9, 0x6f, 0x98, 0xe6, 0xe5, 0x13, 0xc2, 0x4, 0x10, 0xf5, 0xc7, 0xfb, 0x18, 0xa6, 0xe5, 0x9a, 0x52, 0x66, 0x84, 0x5c, 0xd9, 0xb1, 0xe3}} },
};

static const std::size_t H_TABLE_SIZE = 64;
static std::vector<ge_cached> INIT_H_TABLE()
static constexpr std::size_t H_TABLE_SIZE = 64;
const std::vector<ge_cached>& H_TABLE()
{
std::vector<ge_p3> h_table_ge_p3;
std::vector<ge_cached> h_table;

h_table_ge_p3.resize(H_TABLE_SIZE);
h_table.resize(H_TABLE_SIZE);

static_assert(H_TABLE_SIZE > 0, "H_TABLE_SIZE must be > 0");
h_table_ge_p3[0] = ge_p3_H;
ge_p3_to_cached(&h_table[0], &h_table_ge_p3[0]);

for (std::size_t i = 1; i < H_TABLE_SIZE; ++i)
struct static_h_table
{
ge_p2 p2;
ge_p3_to_p2(&p2, &h_table_ge_p3[i - 1]);
ge_p1p1 p2_dbl;
ge_p2_dbl(&p2_dbl, &p2);
ge_p1p1_to_p3(&h_table_ge_p3[i], &p2_dbl);
ge_p3_to_cached(&h_table[i], &h_table_ge_p3[i]);
}
std::vector<ge_cached> h_table;
static_h_table()
: h_table()
{
h_table.resize(H_TABLE_SIZE);

return h_table;
};
static const std::vector<ge_cached> H_TABLE = INIT_H_TABLE();
ge_p3_to_cached(&h_table.at(0), &ge_p3_H);
ge_p3 H_bit_p3 = ge_p3_H;

static ge_p3 INIT_G_GE_P3()
{
ge_p3 G_GE_P3;
CHECK_AND_ASSERT_THROW_MES(ge_frombytes_vartime(&G_GE_P3, rct::G.bytes) == 0, "ge_frombytes_vartime failed for G");
return G_GE_P3;
};
static const ge_p3 G_GE_P3 = INIT_G_GE_P3();
for (std::size_t i = 1; i < H_TABLE_SIZE; ++i)
{
ge_p1p1 H_bit_p1p1;
ge_p3_dbl(&H_bit_p1p1, &H_bit_p3);
ge_p1p1_to_p3(&H_bit_p3, &H_bit_p1p1);
ge_p3_to_cached(&h_table.at(i), &H_bit_p3);
}
}
};
static const static_h_table out;
return out.h_table;
}

namespace rct {

Expand Down Expand Up @@ -362,14 +355,14 @@ namespace rct {
{
return it->commitment;
}
ge_p3 res_ge_p3 = G_GE_P3;
ge_p3 res_ge_p3 = get_G_p3();
static_assert(sizeof(xmr_amount) * 8 == H_TABLE_SIZE, "unexpected size of h table");
for (size_t i = 0; i < H_TABLE_SIZE; ++i)
{
if (amount & (xmr_amount(1) << i))
{
ge_p1p1 p1p1;
ge_add(&p1p1, &res_ge_p3, &H_TABLE[i]);
ge_add(&p1p1, &res_ge_p3, &H_TABLE()[i]);
ge_p1p1_to_p3(&res_ge_p3, &p1p1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/performance_tests/zero_commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class test_zero_commit

bool test()
{
if (fast)
if constexpr (fast)
{
rct::zeroCommitVartime(m_amount);
}
Expand Down
18 changes: 9 additions & 9 deletions tests/unit_tests/ringct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ TEST(ringct, zeroCommmit)
ASSERT_EQ(z, manual);
}

static rct::key uncachedZeroCommit(uint64_t amount)
static rct::key uncachedZeroCommitVartime(uint64_t amount)
{
const rct::key am = rct::d2h(amount);
const rct::key bH = rct::scalarmultH(am);
Expand All @@ -1229,14 +1229,14 @@ static rct::key uncachedZeroCommit(uint64_t amount)

TEST(ringct, zeroCommitCache)
{
ASSERT_EQ(rct::zeroCommitVartime(0), uncachedZeroCommit(0));
ASSERT_EQ(rct::zeroCommitVartime(1), uncachedZeroCommit(1));
ASSERT_EQ(rct::zeroCommitVartime(2), uncachedZeroCommit(2));
ASSERT_EQ(rct::zeroCommitVartime(10), uncachedZeroCommit(10));
ASSERT_EQ(rct::zeroCommitVartime(200), uncachedZeroCommit(200));
ASSERT_EQ(rct::zeroCommitVartime(1000000000), uncachedZeroCommit(1000000000));
ASSERT_EQ(rct::zeroCommitVartime(3000000000000), uncachedZeroCommit(3000000000000));
ASSERT_EQ(rct::zeroCommitVartime(900000000000000), uncachedZeroCommit(900000000000000));
ASSERT_EQ(rct::zeroCommitVartime(0), uncachedZeroCommitVartime(0));
ASSERT_EQ(rct::zeroCommitVartime(1), uncachedZeroCommitVartime(1));
ASSERT_EQ(rct::zeroCommitVartime(2), uncachedZeroCommitVartime(2));
ASSERT_EQ(rct::zeroCommitVartime(10), uncachedZeroCommitVartime(10));
ASSERT_EQ(rct::zeroCommitVartime(200), uncachedZeroCommitVartime(200));
ASSERT_EQ(rct::zeroCommitVartime(1000000000), uncachedZeroCommitVartime(1000000000));
ASSERT_EQ(rct::zeroCommitVartime(3000000000000), uncachedZeroCommitVartime(3000000000000));
ASSERT_EQ(rct::zeroCommitVartime(900000000000000), uncachedZeroCommitVartime(900000000000000));
}

TEST(ringct, H)
Expand Down