Lines Matching +full:- +full:t
2 * Constant-time functions
5 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
28 * This appears to behave as if the declaration-without-definition was not present
29 * (except for warnings if gcc -Wredundant-decls or similar is used).
31 * Disable -Wredundant-decls so that gcc does not warn about this. This is re-enabled
36 #pragma GCC diagnostic ignored "-Wredundant-decls"
39 /* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */
58 * Core const-time primitives
106 * although we don't actually care about setting the flags.
109 * syntax afterwards - otherwise old versions of gcc seem to apply
114 #define RESTORE_ASM_SYNTAX ".syntax divided \n\t"
123 …* Define mask-generation code that, as far as possible, will not use branches or conditional instr… in mbedtls_ct_bool()
132 asm volatile ("neg %x[s], %x[x] \n\t" in mbedtls_ct_bool()
133 "orr %x[x], %x[s], %x[x] \n\t" in mbedtls_ct_bool()
134 "asr %x[x], %x[x], 63 \n\t" in mbedtls_ct_bool()
144 asm volatile (".syntax unified \n\t" in mbedtls_ct_bool()
145 "negs %[s], %[x] \n\t" in mbedtls_ct_bool()
146 "orrs %[x], %[x], %[s] \n\t" in mbedtls_ct_bool()
147 "asrs %[x], %[x], #31 \n\t" in mbedtls_ct_bool()
159 asm volatile ("mov %[x], %[s] \n\t" in mbedtls_ct_bool()
160 "neg %[s] \n\t" in mbedtls_ct_bool()
161 "or %[x], %[s] \n\t" in mbedtls_ct_bool()
162 "sar $63, %[s] \n\t" in mbedtls_ct_bool()
172 asm volatile ("mov %[x], %[s] \n\t" in mbedtls_ct_bool()
173 "neg %[s] \n\t" in mbedtls_ct_bool()
174 "or %[s], %[x] \n\t" in mbedtls_ct_bool()
175 "sar $31, %[x] \n\t" in mbedtls_ct_bool()
187 * well-defined and precisely what we want to do here */ in mbedtls_ct_bool()
191 // y is negative (i.e., top bit set) iff x is non-zero in mbedtls_ct_bool()
192 mbedtls_ct_int_t y = (-xo) | -(xo >> 1); in mbedtls_ct_bool()
194 // extract only the sign bit of y so that y == 1 (if x is non-zero) or 0 (if x is zero) in mbedtls_ct_bool()
195 y = (((mbedtls_ct_uint_t) y) >> (MBEDTLS_CT_SIZE - 1)); in mbedtls_ct_bool()
197 // -y has all bits set (if x is non-zero), or all bits clear (if x is zero) in mbedtls_ct_bool()
198 return (mbedtls_ct_condition_t) (-y); in mbedtls_ct_bool()
210 asm volatile ("and %x[if1], %x[if1], %x[condition] \n\t" in mbedtls_ct_if()
211 "mvn %x[condition], %x[condition] \n\t" in mbedtls_ct_if()
212 "and %x[condition], %x[condition], %x[if0] \n\t" in mbedtls_ct_if()
223 asm volatile (".syntax unified \n\t" in mbedtls_ct_if()
224 "ands %[if1], %[if1], %[condition] \n\t" in mbedtls_ct_if()
225 "mvns %[condition], %[condition] \n\t" in mbedtls_ct_if()
226 "ands %[condition], %[condition], %[if0] \n\t" in mbedtls_ct_if()
227 "orrs %[condition], %[if1], %[condition] \n\t" in mbedtls_ct_if()
239 asm volatile ("and %[condition], %[if1] \n\t" in mbedtls_ct_if()
240 "not %[condition] \n\t" in mbedtls_ct_if()
241 "and %[condition], %[if0] \n\t" in mbedtls_ct_if()
242 "or %[if1], %[if0] \n\t" in mbedtls_ct_if()
252 asm volatile ("and %[condition], %[if1] \n\t" in mbedtls_ct_if()
253 "not %[condition] \n\t" in mbedtls_ct_if()
254 "and %[if0], %[condition] \n\t" in mbedtls_ct_if()
255 "or %[condition], %[if1] \n\t" in mbedtls_ct_if()
275 asm volatile ("eor %x[s1], %x[y], %x[x] \n\t" in mbedtls_ct_uint_lt()
276 "sub %x[x], %x[x], %x[y] \n\t" in mbedtls_ct_uint_lt()
277 "bic %x[x], %x[x], %x[s1] \n\t" in mbedtls_ct_uint_lt()
278 "and %x[s1], %x[s1], %x[y] \n\t" in mbedtls_ct_uint_lt()
279 "orr %x[s1], %x[x], %x[s1] \n\t" in mbedtls_ct_uint_lt()
292 ".syntax unified \n\t" in mbedtls_ct_uint_lt()
294 "movs %[s1], %[x] \n\t" in mbedtls_ct_uint_lt()
295 "eors %[s1], %[s1], %[y] \n\t" in mbedtls_ct_uint_lt()
297 "eors %[s1], %[x], %[y] \n\t" in mbedtls_ct_uint_lt()
299 "subs %[x], %[x], %[y] \n\t" in mbedtls_ct_uint_lt()
300 "bics %[x], %[x], %[s1] \n\t" in mbedtls_ct_uint_lt()
301 "ands %[y], %[s1], %[y] \n\t" in mbedtls_ct_uint_lt()
302 "orrs %[x], %[x], %[y] \n\t" in mbedtls_ct_uint_lt()
303 "asrs %[x], %[x], #31 \n\t" in mbedtls_ct_uint_lt()
316 asm volatile ("mov %[x], %[s] \n\t" in mbedtls_ct_uint_lt()
317 "xor %[y], %[s] \n\t" in mbedtls_ct_uint_lt()
318 "sub %[y], %[x] \n\t" in mbedtls_ct_uint_lt()
319 "and %[s], %[y] \n\t" in mbedtls_ct_uint_lt()
320 "not %[s] \n\t" in mbedtls_ct_uint_lt()
321 "and %[s], %[x] \n\t" in mbedtls_ct_uint_lt()
322 "or %[y], %[x] \n\t" in mbedtls_ct_uint_lt()
323 "sar $63, %[x] \n\t" in mbedtls_ct_uint_lt()
334 asm volatile ("mov %[x], %[s] \n\t" in mbedtls_ct_uint_lt()
335 "xor %[y], %[s] \n\t" in mbedtls_ct_uint_lt()
336 "sub %[y], %[x] \n\t" in mbedtls_ct_uint_lt()
337 "and %[s], %[y] \n\t" in mbedtls_ct_uint_lt()
338 "not %[s] \n\t" in mbedtls_ct_uint_lt()
339 "and %[s], %[x] \n\t" in mbedtls_ct_uint_lt()
340 "or %[y], %[x] \n\t" in mbedtls_ct_uint_lt()
341 "sar $31, %[x] \n\t" in mbedtls_ct_uint_lt()
360 mbedtls_ct_condition_t cond = mbedtls_ct_bool((xo ^ yo) >> (MBEDTLS_CT_SIZE - 1)); in mbedtls_ct_uint_lt()
363 * If the MSB are the same then the difference x-y will be negative (and in mbedtls_ct_uint_lt()
371 // Select either y, or x - y in mbedtls_ct_uint_lt()
372 mbedtls_ct_uint_t ret = mbedtls_ct_if(cond, yo, (mbedtls_ct_uint_t) (xo - yo)); in mbedtls_ct_uint_lt()
375 ret = ret >> (MBEDTLS_CT_SIZE - 1); in mbedtls_ct_uint_lt()
377 // Convert to a condition (i.e., all bits set iff non-zero) in mbedtls_ct_uint_lt()
384 /* diff = 0 if x == y, non-zero otherwise */ in mbedtls_ct_uint_ne()
394 unsigned char t) in mbedtls_ct_uchar_in_range_if() argument
397 const unsigned char to = (unsigned char) mbedtls_ct_compiler_opaque(t); in mbedtls_ct_uchar_in_range_if()
400 unsigned low_mask = ((unsigned) co - low) >> 8; in mbedtls_ct_uchar_in_range_if()
402 unsigned high_mask = ((unsigned) high - co) >> 8; in mbedtls_ct_uchar_in_range_if()
474 /* Coverting int -> uint -> int here is safe, because we require if1 and if0 to be in mbedtls_ct_error_if()
475 * in the range -32767..0, and we require 32-bit int and uint types. in mbedtls_ct_error_if()
477 * This means that (0 <= -if0 < INT_MAX), so negating if0 is safe, and similarly for in mbedtls_ct_error_if()
480 return -((int) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) (-if1), in mbedtls_ct_error_if()
481 (mbedtls_ct_uint_t) (-if0))); in mbedtls_ct_error_if()
486 return -((int) (condition & (-if1))); in mbedtls_ct_error_if_else_0()
537 /* Restore warnings for -Wredundant-decls on gcc */