5#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_STATUS_H_
6#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_STATUS_H_
9#include "sw/device/lib/base/status.h"
29#define OTCRYPTO_OK ((status_t){.value = kHardenedBoolTrue})
31#define LAUNDERED_OTCRYPTO_OK \
32 ((status_t){.value = (int)launder32(kHardenedBoolTrue)})
34#ifdef OTCRYPTO_STATUS_DEBUG
36#define OTCRYPTO_RECOV_ERR \
37 ((status_t){.value = (int32_t)(0x80000000 | \
38 status_encode_module_id(MODULE_ID) << 16 | \
39 ((__LINE__ & 0x7ff) << 5) | kAborted)})
40#define OTCRYPTO_FATAL_ERR \
41 ((status_t){.value = \
42 (int32_t)(0x80000000 | \
43 status_encode_module_id(MODULE_ID) << 16 | \
44 ((__LINE__ & 0x7ff) << 5) | kFailedPrecondition)})
45#define OTCRYPTO_BAD_ARGS \
46 ((status_t){.value = \
47 (int32_t)(0x80000000 | \
48 status_encode_module_id(MODULE_ID) << 16 | \
49 ((__LINE__ & 0x7ff) << 5) | kInvalidArgument)})
50#define OTCRYPTO_ASYNC_INCOMPLETE \
51 ((status_t){.value = (int32_t)(0x80000000 | \
52 status_encode_module_id(MODULE_ID) << 16 | \
53 ((__LINE__ & 0x7ff) << 5) | kUnavailable)})
54#define OTCRYPTO_NOT_IMPLEMENTED \
55 ((status_t){.value = (int32_t)(0x80000000 | \
56 status_encode_module_id(MODULE_ID) << 16 | \
57 ((__LINE__ & 0x7ff) << 5) | kUnimplemented)})
60#define OTCRYPTO_RECOV_ERR \
61 ((status_t){.value = kOtcryptoStatusValueInternalError})
62#define OTCRYPTO_FATAL_ERR ((status_t){.value = kOtcryptoStatusValueFatalError})
63#define OTCRYPTO_BAD_ARGS ((status_t){.value = kOtcryptoStatusValueBadArgs})
64#define OTCRYPTO_ASYNC_INCOMPLETE \
65 ((status_t){.value = kOtcryptoStatusValueAsyncIncomplete})
66#define OTCRYPTO_NOT_IMPLEMENTED \
67 ((status_t){.value = kOtcryptoStatusValueNotImplemented})
71#if !defined(OT_DISABLE_HARDENING) && defined(OT_PLATFORM_RV32)
113#define HARDENED_TRY(expr_) \
115 int32_t status_ = (expr_).value; \
116 asm volatile("addi %0, %0, -1" : "+r"(status_)); \
119 (int32_t)(hardened_try_barrier_(OT_UNSIGNED(status_)) + 1u); \
123 return (status_t){.value = orig_}; \
125 asm volatile("xori %0, %0, %1" \
127 : "i"(kHardenedBoolTrue - 1)); \
128 if (status_ != 0) { \
144#define HARDENED_TRY(expr_) \
146 status_t status_ = expr_; \
147 if (status_.value != kHardenedBoolTrue) { \
149 .value = (int32_t)(OT_UNSIGNED(status_.value) | 0x80000000)}; \