ASCON Suite
ascon-select-backend.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef ASCON_SELECT_BACKEND_H
24 #define ASCON_SELECT_BACKEND_H
25 
26 /* Select the default back end to use for the ASCON permutation,
27  * and any properties we can use to optimize use of the permutation. */
28 
29 #if defined(ASCON_FORCE_C32)
30 
31 /* Force the use of the "c32" backend for testing purposes */
32 #define ASCON_BACKEND_C32 1
33 #define ASCON_BACKEND_SLICED32 1
34 
35 #elif defined(ASCON_FORCE_C64)
36 
37 /* Force the use of the "c64" backend for testing purposes */
38 #define ASCON_BACKEND_C64 1
39 #define ASCON_BACKEND_SLICED64 1
40 
41 #elif defined(ASCON_FORCE_DIRECT_XOR) || defined(ASCON_FORCE_GENERIC)
42 
43 /* Force the use of the "direct xor" backend for testing purposes */
44 #define ASCON_BACKEND_C64_DIRECT_XOR 1
45 #define ASCON_BACKEND_DIRECT_XOR 1
46 
47 #elif defined(__AVR__) && __AVR_ARCH__ >= 5
48 
49 /* AVR5 assembly code backend */
50 #define ASCON_BACKEND_AVR5 1
51 #define ASCON_BACKEND_DIRECT_XOR 1
52 #define ASCON_BACKEND_FREE 1
53 
54 #elif defined(__ARM_ARCH_8A) && defined(__ARM_ARCH_ISA_A64)
55 
56 /* Assembly backend for 64-bit ARMv8-A systems */
57 #define ASCON_BACKEND_ARMV8A 1
58 #define ASCON_BACKEND_SLICED64 1
59 #define ASCON_BACKEND_FREE 1
60 
61 #elif defined(__ARM_ARCH_ISA_THUMB) && __ARM_ARCH == 8 && defined(__ARM_ARCH_8M__)
62 
63 /* Assembly backend for ARMv8-M systems; e.g. ARM Cortex M33 */
64 /* This can actually use the same backend as ARMv7-M systems */
65 #define ASCON_BACKEND_ARMV7M 1
66 #define ASCON_BACKEND_SLICED32 1
67 
68 #elif defined(__ARM_ARCH_ISA_THUMB) && __ARM_ARCH == 7
69 
70 /* Assembly backend for ARMv7-M systems; e.g. ARM Cortex M3, M4, and M7 */
71 /* This backend has also been tested to work on ARMv7-A systems */
72 #define ASCON_BACKEND_ARMV7M 1
73 #define ASCON_BACKEND_SLICED32 1
74 
75 #elif defined(__ARM_ARCH_ISA_THUMB) && __ARM_ARCH == 6 && defined(__ARM_ARCH_6M__)
76 
77 /* Assembly backend for ARMv6-M systems; e.g. ARM Cortex M0+ */
78 #define ASCON_BACKEND_ARMV6M 1
79 #define ASCON_BACKEND_SLICED32 1
80 
81 #elif defined(__ARM_ARCH) && __ARM_ARCH == 6
82 
83 /* Assembly backend for ARMv6 systems, should work with thumb and non-thumb */
84 #define ASCON_BACKEND_ARMV6 1
85 #define ASCON_BACKEND_SLICED32 1
86 
87 #elif defined(__XTENSA__)
88 
89 /* Assembly backend for Xtensa-based systems */
90 #define ASCON_BACKEND_XTENSA 1
91 #define ASCON_BACKEND_SLICED64 1
92 #if !defined(__XTENSA_WINDOWED_ABI__)
93 #define ASCON_BACKEND_FREE 1
94 #endif
95 
96 #elif (defined(__x86_64) || defined(__x86_64__)) && !defined(__CYGWIN__) && !defined(_WIN64)
97 
98 /* Assembly backend for x86-64 based systems. It currently has some
99  * issues when used on Windows platforms so disabled for now. */
100 #define ASCON_BACKEND_X86_64 1
101 #define ASCON_BACKEND_SLICED64 1
102 #define ASCON_BACKEND_FREE 1
103 
104 #elif defined(__i386) || defined(__i386__)
105 
106 /* Assembly backend for i386 based systems */
107 #define ASCON_BACKEND_I386 1
108 #define ASCON_BACKEND_SLICED32 1
109 
110 #elif defined(__m68k) || defined(__m68k__)
111 
112 /* Assembly backend for m68k based systems */
113 #define ASCON_BACKEND_M68K 1
114 #define ASCON_BACKEND_SLICED32 1
115 
116 #elif defined(__riscv) && __riscv_xlen == 64
117 
118 /* Assembly backend for RISC-V systems, RV64I base integer instruction set */
119 #define ASCON_BACKEND_RISCV64I 1
120 #define ASCON_BACKEND_SLICED64 1
121 #define ASCON_BACKEND_FREE 1
122 
123 #elif defined(__riscv) && __riscv_xlen == 32 && defined(__riscv_32e)
124 
125 /* Assembly backend for RISC-V systems, RV32E base integer instruction set */
126 #define ASCON_BACKEND_RISCV32E 1
127 #define ASCON_BACKEND_SLICED32 1
128 #define ASCON_BACKEND_FREE 1
129 
130 #elif defined(__riscv) && __riscv_xlen == 32
131 
132 /* Assembly backend for RISC-V systems, RV32I base integer instruction set */
133 #define ASCON_BACKEND_RISCV32I 1
134 #define ASCON_BACKEND_SLICED32 1
135 #define ASCON_BACKEND_FREE 1
136 
137 #elif defined(__x86_64) || defined(__x86_64__) || \
138  defined(__aarch64__) || defined(__ARM_ARCH_ISA_A64) || \
139  defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64) || \
140  (defined(__riscv) && __riscv_xlen == 64)
141 
142 /* C backend for 64-bit systems with words in host byte order */
143 #define ASCON_BACKEND_C64 1
144 #define ASCON_BACKEND_SLICED64 1
145 
146 #else
147 
148 /* C backend for 32-bit systems, using the bit-slicing method */
149 #define ASCON_BACKEND_C32 1
150 #define ASCON_BACKEND_SLICED32 1
151 
152 #endif
153 
154 #endif