 |
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})
29#ifdef OTCRYPTO_STATUS_DEBUG
31#define OTCRYPTO_RECOV_ERR \
32 ((status_t){.value = (int32_t)(0x80000000 | \
33 status_encode_module_id(MODULE_ID) << 16 | \
34 ((__LINE__ & 0x7ff) << 5) | kAborted)})
35#define OTCRYPTO_FATAL_ERR \
36 ((status_t){.value = \
37 (int32_t)(0x80000000 | \
38 status_encode_module_id(MODULE_ID) << 16 | \
39 ((__LINE__ & 0x7ff) << 5) | kFailedPrecondition)})
40#define OTCRYPTO_BAD_ARGS \
41 ((status_t){.value = \
42 (int32_t)(0x80000000 | \
43 status_encode_module_id(MODULE_ID) << 16 | \
44 ((__LINE__ & 0x7ff) << 5) | kInvalidArgument)})
45#define OTCRYPTO_ASYNC_INCOMPLETE \
46 ((status_t){.value = (int32_t)(0x80000000 | \
47 status_encode_module_id(MODULE_ID) << 16 | \
48 ((__LINE__ & 0x7ff) << 5) | kUnavailable)})
49#define OTCRYPTO_NOT_IMPLEMENTED \
50 ((status_t){.value = (int32_t)(0x80000000 | \
51 status_encode_module_id(MODULE_ID) << 16 | \
52 ((__LINE__ & 0x7ff) << 5) | kUnimplemented)})
55#define OTCRYPTO_RECOV_ERR \
56 ((status_t){.value = kOtcryptoStatusValueInternalError})
57#define OTCRYPTO_FATAL_ERR ((status_t){.value = kOtcryptoStatusValueFatalError})
58#define OTCRYPTO_BAD_ARGS ((status_t){.value = kOtcryptoStatusValueBadArgs})
59#define OTCRYPTO_ASYNC_INCOMPLETE \
60 ((status_t){.value = kOtcryptoStatusValueAsyncIncomplete})
61#define OTCRYPTO_NOT_IMPLEMENTED \
62 ((status_t){.value = kOtcryptoStatusValueNotImplemented})
66#if !defined(OT_DISABLE_HARDENING) && defined(OT_PLATFORM_RV32)
86#define HARDENED_TRY(expr_) \
88 uint32_t status_ = OT_UNSIGNED(expr_.value); \
89 asm volatile("addi %[status_], %[status_], -%[kHardenedBoolTrue]" \
90 : [status_] "+r"(status_) \
91 : [kHardenedBoolTrue] "i"(kHardenedBoolTrue) \
94 asm volatile("addi %[status_], %[status_], %[kHardenedBoolTrue]" \
95 : [status_] "+r"(status_) \
96 : [kHardenedBoolTrue] "i"(kHardenedBoolTrue) \
98 if ((int32_t)(status_) < 0) { \
99 return (status_t){.value = (int32_t)(status_ | 0x80000000)}; \
101 asm volatile("unimp"); \
103 if (launder32(status_)) { \
104 asm volatile("unimp"); \
117#define HARDENED_TRY(expr_) \
119 status_t status_ = expr_; \
120 if (status_.value != kHardenedBoolTrue) { \
122 .value = (int32_t)(OT_UNSIGNED(status_.value) | 0x80000000)}; \