sec_crypto_errcode.h 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2019-2020 Alibaba Group Holding Limited
  3. */
  4. #ifndef _SC_ERRCODE_H
  5. #define _SC_ERRCODE_H
  6. /* common */
  7. #ifndef SC_OK
  8. #define SC_ERROR_BASE 0x10000000
  9. #define SC_OK 0
  10. #define SC_FAIL SC_ERROR_BASE + 1
  11. #define SC_MEM_OVERFLOW SC_ERROR_BASE + 2
  12. #define SC_PARAM_INV SC_ERROR_BASE + 3
  13. #define SC_OPERATION_BUSY SC_ERROR_BASE + 4
  14. #define SC_AUTH_FAIL SC_ERROR_BASE + 5
  15. #define SC_CRYPT_FAIL SC_ERROR_BASE + 6
  16. #define SC_NOT_SUPPORT SC_ERROR_BASE + 7
  17. #define SC_INVALID_PADDING SC_ERROR_BASE + 8
  18. #define SC_BAD_INPUT_DATA SC_ERROR_BASE + 9
  19. #define SC_INVALID_KEY_LENGTH SC_ERROR_BASE + 10
  20. #define SC_INVALID_INPUT_LENGTH SC_ERROR_BASE + 11
  21. #define SC_FEATURE_UNAVAILABLE SC_ERROR_BASE + 12
  22. #define SC_HW_ACCEL_FAILED SC_ERROR_BASE + 13
  23. #define SC_CCM_AUTH_FAILED SC_ERROR_BASE + 14
  24. #define SC_KEY_GEN_FAILED SC_ERROR_BASE + 15
  25. #define SC_KEY_CHECK_FAILED SC_ERROR_BASE + 16
  26. #define SC_PUBLIC_FAILED SC_ERROR_BASE + 17
  27. #define SC_PRIVATE_FAILED SC_ERROR_BASE + 18
  28. #define SC_VERIFY_FAILED SC_ERROR_BASE + 19
  29. #define SC_OUTPUT_TOO_LARGE SC_ERROR_BASE + 20
  30. #define SC_RNG_FAILED SC_ERROR_BASE + 21
  31. #define SC_BUFFER_TOO_SMALL SC_ERROR_BASE + 22
  32. #define SC_INVALID_FORMAT SC_ERROR_BASE + 23
  33. #define SC_ALLOC_FAILED SC_ERROR_BASE + 24
  34. #define SC_DRV_FAILED SC_ERROR_BASE + 25
  35. #define CHECK_RET(x) \
  36. do { \
  37. if (!(x)) { \
  38. LOG_CRIT("err %s, %d\n", __FUNCTION__, __LINE__); \
  39. return; \
  40. } \
  41. } while (0)
  42. #define CHECK_RET_WITH_RET(x, ret) \
  43. do { \
  44. if (!(x)) { \
  45. LOG_CRIT("err %s, %d\n", __FUNCTION__, __LINE__); \
  46. return ret; \
  47. } \
  48. } while (0)
  49. #define CHECK_16byte_ALIGNMENT(_i, ret) \
  50. if ((((uint64_t)_i) & 0xF) != 0) { \
  51. LOG_CRIT("err %s, %d\n", __FUNCTION__, __LINE__); \
  52. return ret; \
  53. }
  54. #define CHECK_32byte_ALIGNMENT(_i, ret) \
  55. if ((((uint64_t)_i) & 0x1F) != 0) { \
  56. LOG_CRIT("err %s, %d\n", __FUNCTION__, __LINE__); \
  57. return ret; \
  58. }
  59. #define CHECK_64byte_ALIGNMENT(_i, ret) \
  60. if ((((uint64_t)_i) & 0x3F) != 0) { \
  61. LOG_CRIT("err %s, %d\n", __FUNCTION__, __LINE__); \
  62. return ret; \
  63. }
  64. #define CHECK_PARAM_RET(c, r) \
  65. do { \
  66. if (!(c)) { \
  67. LOG_CRIT("err %s, %d\n", __FUNCTION__, __LINE__); \
  68. return (r); \
  69. } \
  70. } while (0)
  71. #define CHECK_RET_VOID(c) \
  72. do { \
  73. if (!(c)) { \
  74. LOG_CRIT("err %s, %d\n", __FUNCTION__, __LINE__); \
  75. return; \
  76. } \
  77. } while (0)
  78. #define CHECK_PARAM CHECK_PARAM_RET
  79. #endif
  80. #endif