Software APIs
hardened_asm.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_BASE_HARDENED_ASM_H_
6 #define OPENTITAN_SW_DEVICE_LIB_BASE_HARDENED_ASM_H_
7 
8 /**
9  * Values for a hardened boolean type.
10  *
11  * The intention is that this is used instead of `<stdbool.h>`'s #bool, where a
12  * higher hamming distance is required between the truthy and the falsey value.
13  *
14  * The values below were chosen at random, with some specific restrictions. They
15  * have a Hamming Distance of 8, and they are 11-bit values so they can be
16  * materialized with a single instruction on RISC-V. They are also specifically
17  * not the complement of each other.
18  */
19 #define HARDENED_BOOL_TRUE 0x739
20 #define HARDENED_BOOL_FALSE 0x1d4
21 
22 /**
23  * Values for a byte-sized hardened boolean.
24  *
25  * This type is intended for cases where a byte-sized hardened boolean is
26  * required.
27  *
28  * The values below were chosen to ensure that the hamming difference between
29  * them is greater than 5 and they are not bitwise complements of each other.
30  */
31 #define HARDENED_BYTE_BOOL_TRUE 0xa5
32 #define HARDENED_BYTE_BOOL_FALSE 0x4b
33 
34 #endif // OPENTITAN_SW_DEVICE_LIB_BASE_HARDENED_ASM_H_