/src/nettle-with-libgmp/bswap-internal.h
Line  | Count  | Source  | 
1  |  | /* bswap-internal.h  | 
2  |  |  | 
3  |  |    Copyright (C) 2022 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_BSWAP_INTERNAL_H_INCLUDED  | 
33  |  | #define NETTLE_BSWAP_INTERNAL_H_INCLUDED  | 
34  |  |  | 
35  |  | #include "nettle-types.h"  | 
36  |  |  | 
37  |  | /* Note that these definitions depend config.h, which should be  | 
38  |  |    included first. */  | 
39  |  |  | 
40  |  | #if HAVE_BUILTIN_BSWAP64  | 
41  | 73.2k  | #define nettle_bswap64 __builtin_bswap64  | 
42  |  | /* Assume bswap32 is also available. */  | 
43  | 720k  | #define nettle_bswap32 __builtin_bswap32  | 
44  |  | #else  | 
45  |  | static inline uint64_t  | 
46  |  | nettle_bswap64 (uint64_t x)  | 
47  |  | { | 
48  |  |   x = (x >> 32) | (x << 32);  | 
49  |  |   x = ((x >> 16) & UINT64_C (0xffff0000ffff))  | 
50  |  |     | ((x & UINT64_C (0xffff0000ffff)) << 16);  | 
51  |  |   x = ((x >> 8) & UINT64_C (0xff00ff00ff00ff))  | 
52  |  |     | ((x & UINT64_C (0xff00ff00ff00ff)) << 8);  | 
53  |  |   return x;  | 
54  |  | }  | 
55  |  |  | 
56  |  | static inline uint32_t  | 
57  |  | nettle_bswap32 (uint32_t x)  | 
58  |  | { | 
59  |  |   x = (x << 16) | (x >> 16);  | 
60  |  |   x = ((x & 0x00FF00FF) << 8) | ((x >> 8) & 0x00FF00FF);  | 
61  |  |   return x;  | 
62  |  | }  | 
63  |  | #endif  | 
64  |  |  | 
65  |  | static inline void  | 
66  |  | nettle_bswap32_n (unsigned n, uint32_t *x)  | 
67  | 2.57k  | { | 
68  | 2.57k  |   unsigned i;  | 
69  | 677k  |   for (i = 0; i < n; i++)  | 
70  | 675k  |     x[i] = nettle_bswap32 (x[i]);  | 
71  | 2.57k  | } Unexecuted instantiation: cmac.c:nettle_bswap32_n Unexecuted instantiation: cmac64.c:nettle_bswap32_n Unexecuted instantiation: eax.c:nettle_bswap32_n Unexecuted instantiation: gcm.c:nettle_bswap32_n Unexecuted instantiation: ghash-set-key.c:nettle_bswap32_n Unexecuted instantiation: nist-keywrap.c:nettle_bswap32_n Unexecuted instantiation: ocb.c:nettle_bswap32_n Unexecuted instantiation: siv-cmac.c:nettle_bswap32_n Unexecuted instantiation: siv-gcm.c:nettle_bswap32_n Unexecuted instantiation: siv-ghash-set-key.c:nettle_bswap32_n Unexecuted instantiation: siv-ghash-update.c:nettle_bswap32_n Unexecuted instantiation: xts.c:nettle_bswap32_n Unexecuted instantiation: umac-l2.c:nettle_bswap32_n Unexecuted instantiation: umac-l3.c:nettle_bswap32_n umac-set-key.c:nettle_bswap32_n Line  | Count  | Source  |  67  | 2.57k  | { |  68  | 2.57k  |   unsigned i;  |  69  | 677k  |   for (i = 0; i < n; i++)  |  70  | 675k  |     x[i] = nettle_bswap32 (x[i]);  |  71  | 2.57k  | }  |  
  | 
72  |  |  | 
73  |  | #if WORDS_BIGENDIAN  | 
74  |  | #define bswap64_if_be nettle_bswap64  | 
75  |  | #define bswap32_if_be nettle_bswap32  | 
76  |  | #define bswap64_if_le(x) (x)  | 
77  |  | #define bswap32_if_le(x) (x)  | 
78  |  | #define bswap32_n_if_le(n, x)  | 
79  |  | #else  | 
80  | 922  | #define bswap64_if_be(x) (x)  | 
81  |  | #define bswap32_if_be(x) (x)  | 
82  | 71.4k  | #define bswap64_if_le nettle_bswap64  | 
83  | 45.0k  | #define bswap32_if_le nettle_bswap32  | 
84  | 2.57k  | #define bswap32_n_if_le nettle_bswap32_n  | 
85  |  | #endif  | 
86  |  |  | 
87  |  | #endif /* NETTLE_BSWAP_INTERNAL_H_INCLUDED */  |