 |
Software APIs
|
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"
28#define OTCRYPTO_OK ((status_t){.value = kHardenedBoolTrue})
30#define LAUNDERED_OTCRYPTO_OK \
31 ((status_t){.value = (int)launder32(kHardenedBoolTrue)})
33#ifdef OTCRYPTO_STATUS_DEBUG
35#define OTCRYPTO_RECOV_ERR \
36 ((status_t){.value = (int32_t)(0x80000000 | \
37 status_encode_module_id(MODULE_ID) << 16 | \
38 ((__LINE__ & 0x7ff) << 5) | kAborted)})
39#define OTCRYPTO_FATAL_ERR \
40 ((status_t){.value = \
41 (int32_t)(0x80000000 | \
42 status_encode_module_id(MODULE_ID) << 16 | \
43 ((__LINE__ & 0x7ff) << 5) | kFailedPrecondition)})
44#define OTCRYPTO_BAD_ARGS \
45 ((status_t){.value = \
46 (int32_t)(0x80000000 | \
47 status_encode_module_id(MODULE_ID) << 16 | \
48 ((__LINE__ & 0x7ff) << 5) | kInvalidArgument)})
49#define OTCRYPTO_ASYNC_INCOMPLETE \
50 ((status_t){.value = (int32_t)(0x80000000 | \
51 status_encode_module_id(MODULE_ID) << 16 | \
52 ((__LINE__ & 0x7ff) << 5) | kUnavailable)})
53#define OTCRYPTO_NOT_IMPLEMENTED \
54 ((status_t){.value = (int32_t)(0x80000000 | \
55 status_encode_module_id(MODULE_ID) << 16 | \
56 ((__LINE__ & 0x7ff) << 5) | kUnimplemented)})
59#define OTCRYPTO_RECOV_ERR \
60 ((status_t){.value = kOtcryptoStatusValueInternalError})
61#define OTCRYPTO_FATAL_ERR ((status_t){.value = kOtcryptoStatusValueFatalError})
62#define OTCRYPTO_BAD_ARGS ((status_t){.value = kOtcryptoStatusValueBadArgs})
63#define OTCRYPTO_ASYNC_INCOMPLETE \
64 ((status_t){.value = kOtcryptoStatusValueAsyncIncomplete})
65#define OTCRYPTO_NOT_IMPLEMENTED \
66 ((status_t){.value = kOtcryptoStatusValueNotImplemented})
70#if !defined(OT_DISABLE_HARDENING) && defined(OT_PLATFORM_RV32)
90#define HARDENED_TRY(expr_) \
92 uint32_t status_ = OT_UNSIGNED(expr_.value); \
93 asm volatile("addi %[status_], %[status_], -%[kHardenedBoolTrue]" \
94 : [status_] "+r"(status_) \
95 : [kHardenedBoolTrue] "i"(kHardenedBoolTrue) \
98 asm volatile("addi %[status_], %[status_], %[kHardenedBoolTrue]" \
99 : [status_] "+r"(status_) \
100 : [kHardenedBoolTrue] "i"(kHardenedBoolTrue) \
102 if ((int32_t)(status_) < 0) { \
103 return (status_t){.value = (int32_t)(status_ | 0x80000000)}; \
105 asm volatile("unimp"); \
107 if (launder32(status_)) { \
108 asm volatile("unimp"); \
123#define HARDENED_TRY(expr_) \
125 status_t status_ = expr_; \
126 if (status_.value != kHardenedBoolTrue) { \
128 .value = (int32_t)(OT_UNSIGNED(status_.value) | 0x80000000)}; \