crypto: torsion clearing for FCMP++

This commit is contained in:
j-berman
2026-07-07 14:32:13 -07:00
parent 52f02f26fc
commit 79a996be02
12 changed files with 314 additions and 4 deletions
+1
View File
@@ -70,6 +70,7 @@ target_link_libraries(ringct
common
cncrypto
device
fcmp_pp
PRIVATE
${OPENSSL_LIBRARIES}
${EXTRA_LIBRARIES})
+32
View File
@@ -30,6 +30,8 @@
#include "rctSigs.h"
#include <atomic>
#include "misc_log_ex.h"
#include "misc_language.h"
#include "common/perf_timer.h"
@@ -39,6 +41,7 @@
#include "bulletproofs_plus.h"
#include "cryptonote_config.h"
#include "device/device.hpp"
#include "fcmp_pp/fcmp_pp_crypto.h"
#include "serialization/crypto.h"
using namespace crypto;
@@ -1574,4 +1577,33 @@ namespace rct {
key mask;
return decodeRct(rv, sk, i, mask, hwdev);
}
bool verPointsForTorsion(const std::vector<key> & pts) {
if (pts.empty())
return true;
tools::threadpool& tpool = tools::threadpool::getInstanceForCompute();
tools::threadpool::waiter waiter(tpool);
std::atomic<bool> all_valid{true};
for (std::size_t i = 0; i < pts.size(); ++i)
{
tpool.submit(&waiter, [&pts, &all_valid, i]
{
const crypto::ec_point &point = rct::rct2pt(pts[i]);
crypto::ec_point torsion_cleared_point;
if (fcmp_pp::get_valid_torsion_cleared_point_vartime(point, torsion_cleared_point)
&& point == torsion_cleared_point)
{
// Point is torsion free if it's equal to itself after clearing torsion
return;
}
all_valid.store(false);
});
}
CHECK_AND_ASSERT_MES(waiter.wait(), false, "threadpool waiter failed in torsion check");
CHECK_AND_ASSERT_MES(all_valid.load(), false, "Torsion check failed");
return true;
}
}
+3
View File
@@ -136,6 +136,9 @@ namespace rct {
xmr_amount decodeRct(const rctSig & rv, const key & sk, unsigned int i, key & mask, hw::device &hwdev);
xmr_amount decodeRct(const rctSig & rv, const key & sk, unsigned int i, hw::device &hwdev);
key get_pre_mlsag_hash(const rctSig &rv, hw::device &hwdev);
// Make sure points are valid points, don't have torsion, and are not equal to identity
bool verPointsForTorsion(const std::vector<key> & pts);
}
#endif /* RCTSIGS_H */
+2
View File
@@ -741,10 +741,12 @@ namespace rct {
static inline const rct::key &sk2rct(const crypto::secret_key &sk) { return (const rct::key&)sk; }
static inline const rct::key &ki2rct(const crypto::key_image &ki) { return (const rct::key&)ki; }
static inline const rct::key &hash2rct(const crypto::hash &h) { return (const rct::key&)h; }
static inline const rct::key &pt2rct(const crypto::ec_point &pt) { return (const rct::key&)pt; }
static inline const crypto::public_key &rct2pk(const rct::key &k) { return (const crypto::public_key&)k; }
static inline const crypto::secret_key &rct2sk(const rct::key &k) { return (const crypto::secret_key&)k; }
static inline const crypto::key_image &rct2ki(const rct::key &k) { return (const crypto::key_image&)k; }
static inline const crypto::hash &rct2hash(const rct::key &k) { return (const crypto::hash&)k; }
static inline const crypto::ec_point &rct2pt(const rct::key &k) { return (const crypto::ec_point&)k; }
static inline bool operator==(const rct::key &k0, const crypto::public_key &k1) { return !crypto_verify_32(k0.bytes, (const unsigned char*)&k1); }
static inline bool operator!=(const rct::key &k0, const crypto::public_key &k1) { return crypto_verify_32(k0.bytes, (const unsigned char*)&k1); }
}