3 Copyright (C) 2010, 2014 Niels Möller
5 This file is part of GNU Nettle.
7 GNU Nettle is free software: you can redistribute it and/or
8 modify it under the terms of either:
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
16 * the GNU General Public License as published by the Free
17 Software Foundation; either version 2 of the License, or (at your
18 option) any later version.
20 or both in parallel, as here.
22 GNU Nettle is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received copies of the GNU General Public License and
28 the GNU Lesser General Public License along with this program. If
29 not, see http://www.gnu.org/licenses/.
32 #ifndef NETTLE_MEMXOR_INTERNAL_H_INCLUDED
33 #define NETTLE_MEMXOR_INTERNAL_H_INCLUDED
35 #include "nettle-types.h"
37 /* The word_t type is intended to be the native word size. */
38 #if defined(__x86_64__) || defined(__arch64__)
39 /* Including on M$ windows, where unsigned long is only 32 bits */
40 typedef uint64_t word_t;
42 typedef unsigned long int word_t;
45 #define ALIGN_OFFSET(p) ((uintptr_t) (p) % sizeof(word_t))
47 #ifndef WORDS_BIGENDIAN
48 #define MERGE(w0, sh_1, w1, sh_2) \
49 (((w0) >> (sh_1)) | ((w1) << (sh_2)))
51 #define MERGE(w0, sh_1, w1, sh_2) \
52 (((w0) << (sh_1)) | ((w1) >> (sh_2)))
55 #ifndef WORDS_BIGENDIAN
56 #define READ_PARTIAL(r,p,n) do { \
59 for (_rp_i = (n), _rp_x = (p)[--_rp_i]; _rp_i > 0;) \
60 _rp_x = (_rp_x << CHAR_BIT) | (p)[--_rp_i]; \
64 #define READ_PARTIAL(r,p,n) do { \
67 for (_rp_x = (p)[0], _rp_i = 1; _rp_i < (n); _rp_i++) \
68 _rp_x = (_rp_x << CHAR_BIT) | (p)[_rp_i]; \
73 #endif /* NETTLE_MEMXOR_INTERNAL_H_INCLUDED */