Apply %restore_fcommon macro for Address Sanitizer
[platform/upstream/nettle.git] / memxor-internal.h
1 /* memxor-internal.h
2
3    Copyright (C) 2010, 2014 Niels Möller
4
5    This file is part of GNU Nettle.
6
7    GNU Nettle is free software: you can redistribute it and/or
8    modify it under the terms of either:
9
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.
13
14    or
15
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.
19
20    or both in parallel, as here.
21
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.
26
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/.
30 */
31
32 #ifndef NETTLE_MEMXOR_INTERNAL_H_INCLUDED
33 #define NETTLE_MEMXOR_INTERNAL_H_INCLUDED
34
35 #include "nettle-types.h"
36
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;
41 #else
42 typedef unsigned long int word_t;
43 #endif
44
45 #define ALIGN_OFFSET(p) ((uintptr_t) (p) % sizeof(word_t))
46
47 #ifndef WORDS_BIGENDIAN
48 #define MERGE(w0, sh_1, w1, sh_2) \
49   (((w0) >> (sh_1)) | ((w1) << (sh_2)))
50 #else
51 #define MERGE(w0, sh_1, w1, sh_2) \
52   (((w0) << (sh_1)) | ((w1) >> (sh_2)))
53 #endif
54
55 #ifndef WORDS_BIGENDIAN
56 #define READ_PARTIAL(r,p,n) do {                        \
57     word_t _rp_x;                                       \
58     unsigned _rp_i;                                     \
59     for (_rp_i = (n), _rp_x = (p)[--_rp_i]; _rp_i > 0;) \
60       _rp_x = (_rp_x << CHAR_BIT) | (p)[--_rp_i];       \
61     (r) = _rp_x;                                        \
62   } while (0)
63 #else
64 #define READ_PARTIAL(r,p,n) do {                        \
65     word_t _rp_x;                                               \
66     unsigned _rp_i;                                             \
67     for (_rp_x = (p)[0], _rp_i = 1; _rp_i < (n); _rp_i++)       \
68       _rp_x = (_rp_x << CHAR_BIT) | (p)[_rp_i];                 \
69     (r) = _rp_x;                                                \
70   } while (0)
71 #endif
72
73 #endif /* NETTLE_MEMXOR_INTERNAL_H_INCLUDED */