Welcome to little lamb

Code » test-hashes » next » tree

[next] / include / sha3-nettle-impl-le.h

#ifndef LE_H
#define LE_H

#include <stdint.h>
#include <string.h> /* size_t */

/* The masking of the right shift is needed to allow n == 0 (using
   just 32 - n and 64 - n results in undefined behaviour). Most uses
   of these macros use a constant and non-zero rotation count. */
#define ROTL32(n,x) (((x)<<(n)) | ((x)>>((-(n)&31))))

#define LE_READ_UINT32(p)                       \
	  (  (((uint32_t) (p)[3]) << 24)            \
	   | (((uint32_t) (p)[2]) << 16)            \
	   | (((uint32_t) (p)[1]) << 8)             \
	   |  ((uint32_t) (p)[0]))

#define LE_WRITE_UINT32(p, i)                   \
	do {                                        \
		(p)[3] = ((i) >> 24) & 0xff;            \
		(p)[2] = ((i) >> 16) & 0xff;            \
		(p)[1] = ((i) >> 8) & 0xff;             \
		(p)[0] = (i) & 0xff;                    \
	} while (0)


#define ROTL64(n,x) (((x)<<(n)) | ((x)>>((-(n))&63)))

#define LE_READ_UINT64(p)                       \
	  (  (((uint64_t) (p)[7]) << 56)            \
	   | (((uint64_t) (p)[6]) << 48)            \
	   | (((uint64_t) (p)[5]) << 40)            \
	   | (((uint64_t) (p)[4]) << 32)            \
	   | (((uint64_t) (p)[3]) << 24)            \
	   | (((uint64_t) (p)[2]) << 16)            \
	   | (((uint64_t) (p)[1]) << 8)             \
	   |  ((uint64_t) (p)[0]))

#define LE_WRITE_UINT64(p, i)                   \
	do {                                        \
		(p)[7] = ((i) >> 56) & 0xff;            \
		(p)[6] = ((i) >> 48) & 0xff;            \
		(p)[5] = ((i) >> 40) & 0xff;            \
		(p)[4] = ((i) >> 32) & 0xff;            \
		(p)[3] = ((i) >> 24) & 0xff;            \
		(p)[2] = ((i) >> 16) & 0xff;            \
		(p)[1] = ((i) >> 8) & 0xff;             \
		(p)[0] = (i) & 0xff;                    \
	} while (0)


void _nettle_write_le64(size_t length, uint8_t *dst, const uint64_t *src);

#endif /* LE_H */