diff options
| author | Nils Schneider <[email protected]> | 2011-09-27 20:16:07 +0200 |
|---|---|---|
| committer | Nils Schneider <[email protected]> | 2011-09-30 20:00:22 +0200 |
| commit | 6ccff2cbdebca38e4913b679784a4865edfbb12a (patch) | |
| tree | e13e71eb80ffa412810edcae47eea4f2b86e5b2d /src/util.h | |
| parent | Merge pull request #524 from sipa/signandverif (diff) | |
| download | discoin-6ccff2cbdebca38e4913b679784a4865edfbb12a.tar.xz discoin-6ccff2cbdebca38e4913b679784a4865edfbb12a.zip | |
remove cryptopp dependency, add simple unittest for SHA256Transform()
Diffstat (limited to 'src/util.h')
| -rw-r--r-- | src/util.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h index f0b2f4a71..14853a0a2 100644 --- a/src/util.h +++ b/src/util.h @@ -726,4 +726,29 @@ inline bool AffinityBugWorkaround(void(*pfn)(void*)) return false; } +template <class T> inline T rotlFixed(T x, unsigned int y) +{ + assert(y < sizeof(T)*8); + return T((x<<y) | (x>>(sizeof(T)*8-y))); +} + +template <class T> inline T rotrFixed(T x, unsigned int y) +{ + assert(y < sizeof(T)*8); + return T((x>>y) | (x<<(sizeof(T)*8-y))); +} + +inline uint32_t ByteReverse(uint32_t value) +{ +#if defined(__MWERKS__) && TARGET_CPU_PPC + return (uint32_t)__lwbrx(&value,0); +#elif _MSC_VER >= 1400 || (_MSC_VER >= 1300 && !defined(_DLL)) + return _byteswap_ulong(value); +#else + // 6 instructions with rotate instruction, 8 without + value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8); + return rotlFixed(value, 16U); +#endif +} + #endif |