Software APIs
sw
device
lib
crypto
include
freestanding
hardened.h
Go to the documentation of this file.
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_CRYPTO_INCLUDE_FREESTANDING_HARDENED_H_
6
#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_FREESTANDING_HARDENED_H_
7
8
/**
9
* @file
10
* @brief Data Types for use in Hardened Code.
11
*/
12
13
#ifdef __cplusplus
14
extern
"C"
{
15
#endif
// __cplusplus
16
17
/**
18
* This is a boolean type for use in hardened contexts.
19
*
20
* The intention is that this is used instead of `<stdbool.h>`'s #bool, where a
21
* higher hamming distance is required between the truthy and the falsey value.
22
*
23
* The values below were chosen at random, with some specific restrictions. They
24
* have a Hamming Distance of 8, and they are 11-bit values so they can be
25
* materialized with a single instruction on RISC-V. They are also specifically
26
* not the complement of each other.
27
*/
28
typedef
enum
hardened_bool
{
29
/**
30
* The truthy value, expected to be used like #true.
31
*/
32
kHardenedBoolTrue
= 0x739,
33
/**
34
* The falsey value, expected to be used like #false.
35
*/
36
kHardenedBoolFalse
= 0x1d4,
37
}
hardened_bool_t
;
38
39
#ifdef __cplusplus
40
}
41
#endif
// __cplusplus
42
43
#endif
// OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_FREESTANDING_HARDENED_H_
Return to
OpenTitan Documentation