nrf_crypto_error.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include "sdk_common.h"
  41. #if NRF_MODULE_ENABLED(NRF_CRYPTO)
  42. #include "nordic_common.h"
  43. #include "nrf_crypto_error.h"
  44. typedef struct
  45. {
  46. ret_code_t error;
  47. const char * p_text;
  48. } error_code_pair;
  49. static const error_code_pair m_crypto_error[] =
  50. {
  51. { NRF_ERROR_CRYPTO_NOT_INITIALIZED, "nrf_crypto_init was not called prior to this crypto function" },
  52. { NRF_ERROR_CRYPTO_CONTEXT_NULL, "A null pointer was provided for the context structure" },
  53. { NRF_ERROR_CRYPTO_CONTEXT_NOT_INITIALIZED, "The context was not initialized prior to this call or it was corrupted. Please call the corresponding init function for the algorithm to initialize it" },
  54. { NRF_ERROR_CRYPTO_FEATURE_UNAVAILABLE, "The function was called with a feature that is unavailable" },
  55. { NRF_ERROR_CRYPTO_BUSY, "The function could not be called because the crypto backend was busy. Please rerun the cryptographic routine at a later time" },
  56. { NRF_ERROR_CRYPTO_INPUT_NULL, "One or more of the input arguments for this function was NULL" },
  57. { NRF_ERROR_CRYPTO_INPUT_LENGTH, "The length of one or more of the input arguments was invalid" },
  58. { NRF_ERROR_CRYPTO_INPUT_LOCATION, "Input data not in RAM" },
  59. { NRF_ERROR_CRYPTO_OUTPUT_NULL, "One or more of the output arguments for this function was NULL" },
  60. { NRF_ERROR_CRYPTO_OUTPUT_LENGTH, "The length of the one or more output arguments was too small" },
  61. { NRF_ERROR_CRYPTO_ALLOC_FAILED, "A required memory allocation failed" },
  62. { NRF_ERROR_CRYPTO_INTERNAL, "An internal error occurred when calling this function" },
  63. { NRF_ERROR_CRYPTO_INVALID_PARAM, "Invalid combination of input parameters" },
  64. { NRF_ERROR_CRYPTO_KEY_SIZE, "Size of the key is not supported by choosen backend" },
  65. { NRF_ERROR_CRYPTO_STACK_OVERFLOW, "Stack overflow detected" },
  66. { NRF_ERROR_CRYPTO_ECC_KEY_NOT_INITIALIZED, "ECC key was not initialized" },
  67. { NRF_ERROR_CRYPTO_ECDH_CURVE_MISMATCH, "Public and private key provided to ECDH have different types of curves" },
  68. { NRF_ERROR_CRYPTO_ECDSA_INVALID_SIGNATURE, "Signature verification check reported invalid signature" },
  69. { NRF_ERROR_CRYPTO_ECC_INVALID_KEY, "Provided key is invalid" },
  70. { NRF_ERROR_CRYPTO_AES_INVALID_PADDING, "Message padding is corrupted." },
  71. { NRF_ERROR_CRYPTO_AEAD_INVALID_MAC, "MAC not matching encrypted text" },
  72. { NRF_ERROR_CRYPTO_AEAD_NONCE_SIZE, "Size of the nonce is not supported in this AEAD mode" },
  73. { NRF_ERROR_CRYPTO_AEAD_MAC_SIZE, "Size of the MAC (tag) is not supported in this AEAD mode" },
  74. { NRF_ERROR_CRYPTO_RNG_INIT_FAILED, "Initialization or startup of RNG failed" },
  75. { NRF_ERROR_CRYPTO_RNG_RESEED_REQUIRED, "Reseed required (reseed counter overflowed)" },
  76. };
  77. char const * nrf_crypto_error_string_get(ret_code_t error)
  78. {
  79. if (error == NRF_SUCCESS)
  80. {
  81. return "No error";
  82. }
  83. else
  84. {
  85. uint32_t i;
  86. for (i = 0; i < ARRAY_SIZE(m_crypto_error); i++)
  87. {
  88. if (m_crypto_error[i].error == error)
  89. {
  90. return m_crypto_error[i].p_text;
  91. }
  92. }
  93. }
  94. return "Error not related to nrf_crypto library";
  95. }
  96. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO)