diff options
Diffstat (limited to 'src/3rdparty/SHA-3/Rotation.h')
-rw-r--r-- | src/3rdparty/SHA-3/Rotation.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/3rdparty/SHA-3/Rotation.h b/src/3rdparty/SHA-3/Rotation.h new file mode 100644 index 0000000000..f25716147d --- /dev/null +++ b/src/3rdparty/SHA-3/Rotation.h @@ -0,0 +1,28 @@ +#ifndef ROTATION_H_ +#define ROTATION_H_ + +#include <cstdint> + +// As we're not using assembly, we can't use the native rotation instructions +// replace it with a small inline +static inline uint64_t rotateLeft(uint64_t x, int n) +{ + const unsigned int mask = (8*sizeof(x) - 1); // assumes width is a power of 2. + + // assert ( (c<=mask) &&"rotate by type width or more"); + n &= mask; + return (x << n) | (x >> ((-n)&mask)); +} + +static inline uint64_t rotateRight(uint64_t x, int n) +{ + const unsigned int mask = (8 * sizeof(x) - 1); // assumes width is a power of 2. + + // assert ( (c<=mask) &&"rotate by type width or more"); + n &= mask; + return (x >> n) | (x << ((-n)&mask)); + +} + +#endif //ROTATION_H_ + |