error.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * \file error.h
  3. *
  4. * \brief Error to string translation
  5. */
  6. /*
  7. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  8. * SPDX-License-Identifier: Apache-2.0
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  11. * not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  18. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. *
  22. * This file is part of mbed TLS (https://tls.mbed.org)
  23. */
  24. #ifndef MBEDTLS_ERROR_H
  25. #define MBEDTLS_ERROR_H
  26. #include <stddef.h>
  27. /**
  28. * Error code layout.
  29. *
  30. * Currently we try to keep all error codes within the negative space of 16
  31. * bits signed integers to support all platforms (-0x0001 - -0x7FFF). In
  32. * addition we'd like to give two layers of information on the error if
  33. * possible.
  34. *
  35. * For that purpose the error codes are segmented in the following manner:
  36. *
  37. * 16 bit error code bit-segmentation
  38. *
  39. * 1 bit - Unused (sign bit)
  40. * 3 bits - High level module ID
  41. * 5 bits - Module-dependent error code
  42. * 7 bits - Low level module errors
  43. *
  44. * For historical reasons, low-level error codes are divided in even and odd,
  45. * even codes were assigned first, and -1 is reserved for other errors.
  46. *
  47. * Low-level module errors (0x0002-0x007E, 0x0003-0x007F)
  48. *
  49. * Module Nr Codes assigned
  50. * MPI 7 0x0002-0x0010
  51. * GCM 3 0x0012-0x0014 0x0013-0x0013
  52. * BLOWFISH 3 0x0016-0x0018 0x0017-0x0017
  53. * THREADING 3 0x001A-0x001E
  54. * AES 4 0x0020-0x0022 0x0023-0x0025
  55. * CAMELLIA 3 0x0024-0x0026 0x0027-0x0027
  56. * XTEA 2 0x0028-0x0028 0x0029-0x0029
  57. * BASE64 2 0x002A-0x002C
  58. * OID 1 0x002E-0x002E 0x000B-0x000B
  59. * PADLOCK 1 0x0030-0x0030
  60. * DES 2 0x0032-0x0032 0x0033-0x0033
  61. * CTR_DBRG 4 0x0034-0x003A
  62. * ENTROPY 3 0x003C-0x0040 0x003D-0x003F
  63. * NET 11 0x0042-0x0052 0x0043-0x0045
  64. * ASN1 7 0x0060-0x006C
  65. * CMAC 1 0x007A-0x007A
  66. * PBKDF2 1 0x007C-0x007C
  67. * HMAC_DRBG 4 0x0003-0x0009
  68. * CCM 3 0x000D-0x0011
  69. * ARC4 1 0x0019-0x0019
  70. * MD2 1 0x002B-0x002B
  71. * MD4 1 0x002D-0x002D
  72. * MD5 1 0x002F-0x002F
  73. * RIPEMD160 1 0x0031-0x0031
  74. * SHA1 1 0x0035-0x0035
  75. * SHA256 1 0x0037-0x0037
  76. * SHA512 1 0x0039-0x0039
  77. *
  78. * High-level module nr (3 bits - 0x0...-0x7...)
  79. * Name ID Nr of Errors
  80. * PEM 1 9
  81. * PKCS#12 1 4 (Started from top)
  82. * X509 2 20
  83. * PKCS5 2 4 (Started from top)
  84. * DHM 3 11
  85. * PK 3 15 (Started from top)
  86. * RSA 4 11
  87. * ECP 4 9 (Started from top)
  88. * MD 5 5
  89. * CIPHER 6 8
  90. * SSL 6 17 (Started from top)
  91. * SSL 7 31
  92. *
  93. * Module dependent error code (5 bits 0x.00.-0x.F8.)
  94. */
  95. #ifdef __cplusplus
  96. extern "C" {
  97. #endif
  98. /**
  99. * \brief Translate a mbed TLS error code into a string representation,
  100. * Result is truncated if necessary and always includes a terminating
  101. * null byte.
  102. *
  103. * \param errnum error code
  104. * \param buffer buffer to place representation in
  105. * \param buflen length of the buffer
  106. */
  107. void mbedtls_strerror( int errnum, char *buffer, size_t buflen );
  108. #ifdef __cplusplus
  109. }
  110. #endif
  111. #endif /* error.h */