Welcome to little lamb

Code » test-hashes » master » tree

[master] / include / sha3-nettle-impl-memxor.h

#ifndef MEMXOR_H
#define MEMXOR_H

#include <stdint.h>
#include <stdlib.h>

void *memxor(void *dst, const void *src, size_t n);
void *memxor3(void *dst, const void *a, const void *b, size_t n);


/* memxor-internal */

/* The word_t type is intended to be the native word size. */
#if defined(__x86_64__) || defined(__arch64__)
/* Including on M$ windows, where unsigned long is only 32 bits */
typedef uint64_t word_t;
#else
typedef unsigned long int word_t;
#endif

#define ALIGN_OFFSET(p) ((uintptr_t) (p) % sizeof(word_t))

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define MERGE(w0, sh_1, w1, sh_2) \
  (((w0) >> (sh_1)) | ((w1) << (sh_2)))
#else
#define MERGE(w0, sh_1, w1, sh_2) \
  (((w0) << (sh_1)) | ((w1) >> (sh_2)))
#endif

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define READ_PARTIAL(r,p,n) do {			\
	word_t _rp_x;					\
	unsigned _rp_i;					\
	for (_rp_i = (n), _rp_x = (p)[--_rp_i]; _rp_i > 0;)	\
	_rp_x = (_rp_x << CHAR_BIT) | (p)[--_rp_i];	\
	(r) = _rp_x;					\
} while (0)
#else
#define READ_PARTIAL(r,p,n) do {			\
	word_t _rp_x;						\
	unsigned _rp_i;						\
	for (_rp_x = (p)[0], _rp_i = 1; _rp_i < (n); _rp_i++)	\
	_rp_x = (_rp_x << CHAR_BIT) | (p)[_rp_i];			\
	(r) = _rp_x;						\
} while (0)
#endif

#endif /* MEMXOR_H */