diff --git a/src/ringct/rctOps.cpp b/src/ringct/rctOps.cpp index 3860a7e1f..34d64033e 100644 --- a/src/ringct/rctOps.cpp +++ b/src/ringct/rctOps.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2024, Monero Research Labs +// Copyright (c) 2016-2026, Monero Research Labs // // Author: Shen Noether // @@ -30,7 +30,11 @@ #include #include "misc_log_ex.h" +extern "C" { +#include "rctCryptoOps.h" +} #include "rctOps.h" + using namespace crypto; using namespace std; @@ -340,7 +344,8 @@ namespace rct { //generates a random uint long long (for testing) xmr_amount randXmrAmount(xmr_amount upperlimit) { - return h2d(skGen()) % (upperlimit); + assert(upperlimit > 0); + return crypto::rand() % upperlimit; } //Scalar multiplications of curve points diff --git a/src/ringct/rctOps.h b/src/ringct/rctOps.h index 0edd0308c..88aad0e7c 100644 --- a/src/ringct/rctOps.h +++ b/src/ringct/rctOps.h @@ -1,5 +1,5 @@ //#define DBG -// Copyright (c) 2016-2024, Monero Research Labs +// Copyright (c) 2016-2026, Monero Research Labs // // Author: Shen Noether // @@ -37,15 +37,6 @@ #include #include -#include "crypto/generic-ops.h" - -extern "C" { -#include "crypto/random.h" -#include "crypto/keccak.h" -#include "rctCryptoOps.h" -} -#include "crypto/crypto.h" - #include "rctTypes.h" //Define this flag when debugging to get additional info on the console diff --git a/src/ringct/rctSigs.cpp b/src/ringct/rctSigs.cpp index 206a9a51d..08e47cc51 100644 --- a/src/ringct/rctSigs.cpp +++ b/src/ringct/rctSigs.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2024, Monero Research Labs +// Copyright (c) 2016-2026, Monero Research Labs // // Author: Shen Noether // @@ -1573,7 +1573,10 @@ namespace rct { if (equalKeys(C, Ctmp) == false) { CHECK_AND_ASSERT_THROW_MES(false, "warning, amount decoded incorrectly, will be unable to spend"); } - return h2d(amount); + rct::xmr_amount amount_8; + CHECK_AND_ASSERT_THROW_MES(h2d(amount_8, amount), + "long decoded amount contains superfluous data"); + return amount_8; } xmr_amount decodeRct(const rctSig & rv, const key & sk, unsigned int i, hw::device &hwdev) { @@ -1604,7 +1607,10 @@ namespace rct { if (equalKeys(C, Ctmp) == false) { CHECK_AND_ASSERT_THROW_MES(false, "warning, amount decoded incorrectly, will be unable to spend"); } - return h2d(amount); + rct::xmr_amount amount_8; + CHECK_AND_ASSERT_THROW_MES(h2d(amount_8, amount), + "long decoded amount contains superfluous data"); + return amount_8; } xmr_amount decodeRctSimple(const rctSig & rv, const key & sk, unsigned int i, hw::device &hwdev) { diff --git a/src/ringct/rctTypes.cpp b/src/ringct/rctTypes.cpp index 8b0345e97..51260c079 100644 --- a/src/ringct/rctTypes.cpp +++ b/src/ringct/rctTypes.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2024, Monero Research Labs +// Copyright (c) 2016-2026, Monero Research Labs // // Author: Shen Noether // @@ -140,14 +140,18 @@ namespace rct { //32 byte key to uint long long // if the key holds a value > 2^64 - // then the value in the first 8 bytes is returned - xmr_amount h2d(const key & test) { - xmr_amount vali = 0; + // then false is returned + bool h2d(xmr_amount &amountd, const key & test) { + amountd = 0; int j = 0; - for (j = 7; j >= 0; j--) { - vali = (xmr_amount)(vali * 256 + (unsigned char)test.bytes[j]); + for (j = 8; j < 32; ++j) { + if (test.bytes[j]) + return false; } - return vali; + for (j = 7; j >= 0; j--) { + amountd = (xmr_amount)(amountd * 256 + (unsigned char)test.bytes[j]); + } + return true; } //32 byte key to int[64] diff --git a/src/ringct/rctTypes.h b/src/ringct/rctTypes.h index ee896f11e..038c2e150 100644 --- a/src/ringct/rctTypes.h +++ b/src/ringct/rctTypes.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2024, Monero Research Labs +// Copyright (c) 2016-2026, Monero Research Labs // // Author: Shen Noether // @@ -722,8 +722,8 @@ namespace rct { void d2b(bits amountb, xmr_amount val); //32 byte key to uint long long // if the key holds a value > 2^64 - // then the value in the first 8 bytes is returned - xmr_amount h2d(const key &test); + // then false is returned + bool h2d(xmr_amount &amountd, const key &test); //32 byte key to int[64] void h2b(bits amountb2, const key & test); //int[64] to 32 byte key diff --git a/tests/core_tests/multisig.cpp b/tests/core_tests/multisig.cpp index 9cec96ff1..c3874f98c 100644 --- a/tests/core_tests/multisig.cpp +++ b/tests/core_tests/multisig.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2024, The Monero Project +// Copyright (c) 2017-2026, The Monero Project // // All rights reserved. // @@ -438,7 +438,10 @@ bool gen_multisig_tx_validation_base::generate_with(std::vector