Browse Source

faster conversion to little endian

pull/5/head
orignal 7 years ago
parent
commit
708673ac5d
  1. 2
      i2pd
  2. 8
      src/hash.h
  3. 3
      src/uint256.h
  4. 9
      src/util.h

2
i2pd

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit 4448884a3ebf822ecca7b39f2fe9777a79ae1863
Subproject commit abf0f5ac8780c9cb0088e4ccefcd0d0274e63965

8
src/hash.h

@ -22,12 +22,12 @@ inline uint256 Hash(const T1 pbegin, const T1 pend) @@ -22,12 +22,12 @@ inline uint256 Hash(const T1 pbegin, const T1 pend)
static unsigned char pblank[1];
uint8_t hash1[64];
i2p::crypto::GOSTR3411_2012_512 ((pbegin == pend ? pblank : (unsigned char*)&pbegin[0]), (pend - pbegin) * sizeof(pbegin[0]), hash1);
uint8_t digest[32];
i2p::crypto::GOSTR3411_2012_256 (hash1, 64, digest);
uint32_t digest[8];
i2p::crypto::GOSTR3411_2012_256 (hash1, 64, (uint8_t *)digest);
// to little endian
uint256 hash2;
for (int i = 0; i < 32; i++)
hash2.begin ()[i] = digest[31-i];
for (int i = 0; i < 8; i++)
hash2.pn[i] = ByteReverse (digest[7-i]);
return hash2;
}

3
src/uint256.h

@ -26,10 +26,9 @@ inline int Testuint256AdHoc(std::vector<std::string> vArg); @@ -26,10 +26,9 @@ inline int Testuint256AdHoc(std::vector<std::string> vArg);
template<unsigned int BITS>
class base_uint
{
protected:
public:
enum { WIDTH=BITS/32 };
uint32_t pn[WIDTH];
public:
bool operator!() const
{

9
src/util.h

@ -552,12 +552,13 @@ void RenameThread(const char* name); @@ -552,12 +552,13 @@ void RenameThread(const char* name);
inline uint32_t ByteReverse(uint32_t value)
{
#if 0
// #if defined(__x86_64__)
#if defined(__x86_64__) || defined(__i386__)
__asm__
(
"bswap %%eax"
: "=a"(value) ::
"bswap %0"
: "=r"(value)
: "0"(value)
:
);
return value;
#else

Loading…
Cancel
Save