mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-30 03:03:17 +00:00
difficulty: fix check_hash on big endian
This commit is contained in:
parent
1b93cb74bb
commit
d046ca1db0
3 changed files with 20 additions and 9 deletions
|
@ -34,7 +34,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <boost/multiprecision/cpp_int.hpp>
|
#include <boost/multiprecision/cpp_int.hpp>
|
||||||
|
|
||||||
#include "crypto/hash.h"
|
#include "crypto/hash.h"
|
||||||
|
|
||||||
namespace cryptonote
|
namespace cryptonote
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "string_tools.h"
|
#include "string_tools.h"
|
||||||
|
#include "int-util.h"
|
||||||
#include "cryptonote_basic/difficulty.h"
|
#include "cryptonote_basic/difficulty.h"
|
||||||
|
|
||||||
template<uint64_t hash_target_high, uint64_t hash_target_low, uint64_t difficulty_high, uint64_t difficulty_low>
|
template<uint64_t hash_target_high, uint64_t hash_target_low, uint64_t difficulty_high, uint64_t difficulty_low>
|
||||||
|
@ -44,13 +45,18 @@ public:
|
||||||
difficulty = difficulty_high;
|
difficulty = difficulty_high;
|
||||||
difficulty = (difficulty << 64) | difficulty_low;
|
difficulty = (difficulty << 64) | difficulty_low;
|
||||||
boost::multiprecision::uint256_t hash_value = std::numeric_limits<boost::multiprecision::uint256_t>::max() / hash_target;
|
boost::multiprecision::uint256_t hash_value = std::numeric_limits<boost::multiprecision::uint256_t>::max() / hash_target;
|
||||||
((uint64_t*)&hash)[0] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
uint64_t val;
|
||||||
|
val = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
||||||
|
((uint64_t*)&hash)[0] = SWAP64LE(val);
|
||||||
hash_value >>= 64;
|
hash_value >>= 64;
|
||||||
((uint64_t*)&hash)[1] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
val = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
||||||
|
((uint64_t*)&hash)[1] = SWAP64LE(val);
|
||||||
hash_value >>= 64;
|
hash_value >>= 64;
|
||||||
((uint64_t*)&hash)[2] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
val = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
||||||
|
((uint64_t*)&hash)[2] = SWAP64LE(val);
|
||||||
hash_value >>= 64;
|
hash_value >>= 64;
|
||||||
((uint64_t*)&hash)[3] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
val = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
||||||
|
((uint64_t*)&hash)[3] = SWAP64LE(val);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "int-util.h"
|
||||||
#include "cryptonote_basic/difficulty.h"
|
#include "cryptonote_basic/difficulty.h"
|
||||||
|
|
||||||
static cryptonote::difficulty_type MKDIFF(uint64_t high, uint64_t low)
|
static cryptonote::difficulty_type MKDIFF(uint64_t high, uint64_t low)
|
||||||
|
@ -42,13 +43,18 @@ static crypto::hash MKHASH(uint64_t high, uint64_t low)
|
||||||
hash_target = (hash_target << 64) | low;
|
hash_target = (hash_target << 64) | low;
|
||||||
boost::multiprecision::uint256_t hash_value = std::numeric_limits<boost::multiprecision::uint256_t>::max() / hash_target;
|
boost::multiprecision::uint256_t hash_value = std::numeric_limits<boost::multiprecision::uint256_t>::max() / hash_target;
|
||||||
crypto::hash h;
|
crypto::hash h;
|
||||||
((uint64_t*)&h)[0] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
uint64_t val;
|
||||||
|
val = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
||||||
|
((uint64_t*)&h)[0] = SWAP64LE(val);
|
||||||
hash_value >>= 64;
|
hash_value >>= 64;
|
||||||
((uint64_t*)&h)[1] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
val = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
||||||
|
((uint64_t*)&h)[1] = SWAP64LE(val);
|
||||||
hash_value >>= 64;
|
hash_value >>= 64;
|
||||||
((uint64_t*)&h)[2] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
val = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
||||||
|
((uint64_t*)&h)[2] = SWAP64LE(val);
|
||||||
hash_value >>= 64;
|
hash_value >>= 64;
|
||||||
((uint64_t*)&h)[3] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
val = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
|
||||||
|
((uint64_t*)&h)[3] = SWAP64LE(val);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue