|  | // Copyright lowRISC contributors. | 
|  | // Licensed under the Apache License, Version 2.0, see LICENSE for details. | 
|  | // SPDX-License-Identifier: Apache-2.0 | 
|  |  | 
|  | #ifndef OPENTITAN_SW_DEVICE_LIB_BASE_HARDENED_STATUS_H_ | 
|  | #define OPENTITAN_SW_DEVICE_LIB_BASE_HARDENED_STATUS_H_ | 
|  |  | 
|  | /** | 
|  | * @file | 
|  | * @brief Hardened handling of status codes. | 
|  | */ | 
|  |  | 
|  | #include "sw/device/lib/base/hardened.h" | 
|  | #include "sw/device/lib/base/status.h" | 
|  |  | 
|  | #ifdef __cplusplus | 
|  | extern "C" { | 
|  | #endif  // __cplusplus | 
|  |  | 
|  | /** | 
|  | * Hardened variant of `OK_STATUS` . | 
|  | * | 
|  | * This passes `kHardenedBoolTrue` as the status code argument, for extra bits | 
|  | * of redundancy in `HARDENED_TRY` and others. | 
|  | */ | 
|  | #define HARDENED_OK_STATUS ((status_t){.value = kHardenedBoolTrue}) | 
|  |  | 
|  | /** | 
|  | * Hardened version of the `TRY` macro from `status.h`. | 
|  | * | 
|  | * @param expr_ An expression that evaluates to a `status_t`. | 
|  | * @return The enclosed OK value. | 
|  | */ | 
|  | #define HARDENED_TRY(expr_)                                 \ | 
|  | ({                                                        \ | 
|  | status_t status_ = expr_;                               \ | 
|  | if (hardened_status_ok(status_) != kHardenedBoolTrue) { \ | 
|  | return status_;                                       \ | 
|  | }                                                       \ | 
|  | HARDENED_CHECK_EQ(status_.value, kHardenedBoolTrue);    \ | 
|  | status_.value;                                          \ | 
|  | }) | 
|  |  | 
|  | /** | 
|  | * Hardened version of `status_ok`. | 
|  | * | 
|  | * Returns `kHardenedBoolTrue` if the status is OK with an argument code of | 
|  | * `kHardenedBoolTrue` (i.e. equal to `HARDENED_OK_STATUS`), and | 
|  | * `kHardenedBoolFalse` otherwise. | 
|  | * | 
|  | * @param s The status code. | 
|  | * @return True if the status represents Ok. | 
|  | */ | 
|  | hardened_bool_t hardened_status_ok(status_t s); | 
|  |  | 
|  | #ifdef __cplusplus | 
|  | }  // extern "C" | 
|  | #endif  // __cplusplus | 
|  |  | 
|  | #endif  // OPENTITAN_SW_DEVICE_LIB_BASE_HARDENED_STATUS_H_ |