PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/ctaocrypt/src/error.c

https://github.com/andersmalm/cyassl
C | 291 lines | 198 code | 72 blank | 21 comment | 1 complexity | fab77272a5a1ce0fc635263f6fb17442 MD5 | raw file
Possible License(s): GPL-2.0
  1. /* error.c
  2. *
  3. * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
  4. *
  5. * This file is part of CyaSSL.
  6. *
  7. * CyaSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * CyaSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include <cyassl/ctaocrypt/error.h>
  25. #ifdef _MSC_VER
  26. /* 4996 warning to use MS extensions e.g., strcpy_s instead of XSTRNCPY */
  27. #pragma warning(disable: 4996)
  28. #endif
  29. void CTaoCryptErrorString(int error, char* buffer)
  30. {
  31. const int max = MAX_ERROR_SZ; /* shorthand */
  32. #ifdef NO_ERROR_STRINGS
  33. (void)error;
  34. XSTRNCPY(buffer, "no support for error strings built in", max);
  35. #else
  36. switch (error) {
  37. case OPEN_RAN_E :
  38. XSTRNCPY(buffer, "opening random device error", max);
  39. break;
  40. case READ_RAN_E :
  41. XSTRNCPY(buffer, "reading random device error", max);
  42. break;
  43. case WINCRYPT_E :
  44. XSTRNCPY(buffer, "windows crypt init error", max);
  45. break;
  46. case CRYPTGEN_E :
  47. XSTRNCPY(buffer, "windows crypt generation error", max);
  48. break;
  49. case RAN_BLOCK_E :
  50. XSTRNCPY(buffer, "random device read would block error", max);
  51. break;
  52. case MP_INIT_E :
  53. XSTRNCPY(buffer, "mp_init error state", max);
  54. break;
  55. case MP_READ_E :
  56. XSTRNCPY(buffer, "mp_read error state", max);
  57. break;
  58. case MP_EXPTMOD_E :
  59. XSTRNCPY(buffer, "mp_exptmod error state", max);
  60. break;
  61. case MP_TO_E :
  62. XSTRNCPY(buffer, "mp_to_xxx error state, can't convert", max);
  63. break;
  64. case MP_SUB_E :
  65. XSTRNCPY(buffer, "mp_sub error state, can't subtract", max);
  66. break;
  67. case MP_ADD_E :
  68. XSTRNCPY(buffer, "mp_add error state, can't add", max);
  69. break;
  70. case MP_MUL_E :
  71. XSTRNCPY(buffer, "mp_mul error state, can't multiply", max);
  72. break;
  73. case MP_MULMOD_E :
  74. XSTRNCPY(buffer, "mp_mulmod error state, can't multiply mod", max);
  75. break;
  76. case MP_MOD_E :
  77. XSTRNCPY(buffer, "mp_mod error state, can't mod", max);
  78. break;
  79. case MP_INVMOD_E :
  80. XSTRNCPY(buffer, "mp_invmod error state, can't inv mod", max);
  81. break;
  82. case MP_CMP_E :
  83. XSTRNCPY(buffer, "mp_cmp error state", max);
  84. break;
  85. case MP_ZERO_E :
  86. XSTRNCPY(buffer, "mp zero result, not expected", max);
  87. break;
  88. case MEMORY_E :
  89. XSTRNCPY(buffer, "out of memory error", max);
  90. break;
  91. case RSA_WRONG_TYPE_E :
  92. XSTRNCPY(buffer, "RSA wrong block type for RSA function", max);
  93. break;
  94. case RSA_BUFFER_E :
  95. XSTRNCPY(buffer, "RSA buffer error, output too small or input too big",
  96. max);
  97. break;
  98. case BUFFER_E :
  99. XSTRNCPY(buffer, "Buffer error, output too small or input too big",max);
  100. break;
  101. case ALGO_ID_E :
  102. XSTRNCPY(buffer, "Setting Cert AlogID error", max);
  103. break;
  104. case PUBLIC_KEY_E :
  105. XSTRNCPY(buffer, "Setting Cert Public Key error", max);
  106. break;
  107. case DATE_E :
  108. XSTRNCPY(buffer, "Setting Cert Date validity error", max);
  109. break;
  110. case SUBJECT_E :
  111. XSTRNCPY(buffer, "Setting Cert Subject name error", max);
  112. break;
  113. case ISSUER_E :
  114. XSTRNCPY(buffer, "Setting Cert Issuer name error", max);
  115. break;
  116. case CA_TRUE_E :
  117. XSTRNCPY(buffer, "Setting basic constraint CA true error", max);
  118. break;
  119. case EXTENSIONS_E :
  120. XSTRNCPY(buffer, "Setting extensions error", max);
  121. break;
  122. case ASN_PARSE_E :
  123. XSTRNCPY(buffer, "ASN parsing error, invalid input", max);
  124. break;
  125. case ASN_VERSION_E :
  126. XSTRNCPY(buffer, "ASN version error, invalid number", max);
  127. break;
  128. case ASN_GETINT_E :
  129. XSTRNCPY(buffer, "ASN get big int error, invalid data", max);
  130. break;
  131. case ASN_RSA_KEY_E :
  132. XSTRNCPY(buffer, "ASN key init error, invalid input", max);
  133. break;
  134. case ASN_OBJECT_ID_E :
  135. XSTRNCPY(buffer, "ASN object id error, invalid id", max);
  136. break;
  137. case ASN_TAG_NULL_E :
  138. XSTRNCPY(buffer, "ASN tag error, not null", max);
  139. break;
  140. case ASN_EXPECT_0_E :
  141. XSTRNCPY(buffer, "ASN expect error, not zero", max);
  142. break;
  143. case ASN_BITSTR_E :
  144. XSTRNCPY(buffer, "ASN bit string error, wrong id", max);
  145. break;
  146. case ASN_UNKNOWN_OID_E :
  147. XSTRNCPY(buffer, "ASN oid error, unknown sum id", max);
  148. break;
  149. case ASN_DATE_SZ_E :
  150. XSTRNCPY(buffer, "ASN date error, bad size", max);
  151. break;
  152. case ASN_BEFORE_DATE_E :
  153. XSTRNCPY(buffer, "ASN date error, current date before", max);
  154. break;
  155. case ASN_AFTER_DATE_E :
  156. XSTRNCPY(buffer, "ASN date error, current date after", max);
  157. break;
  158. case ASN_SIG_OID_E :
  159. XSTRNCPY(buffer, "ASN signature error, mismatched oid", max);
  160. break;
  161. case ASN_TIME_E :
  162. XSTRNCPY(buffer, "ASN time error, unkown time type", max);
  163. break;
  164. case ASN_INPUT_E :
  165. XSTRNCPY(buffer, "ASN input error, not enough data", max);
  166. break;
  167. case ASN_SIG_CONFIRM_E :
  168. XSTRNCPY(buffer, "ASN sig error, confirm failure", max);
  169. break;
  170. case ASN_SIG_HASH_E :
  171. XSTRNCPY(buffer, "ASN sig error, unsupported hash type", max);
  172. break;
  173. case ASN_SIG_KEY_E :
  174. XSTRNCPY(buffer, "ASN sig error, unsupported key type", max);
  175. break;
  176. case ASN_DH_KEY_E :
  177. XSTRNCPY(buffer, "ASN key init error, invalid input", max);
  178. break;
  179. case ASN_NTRU_KEY_E :
  180. XSTRNCPY(buffer, "ASN NTRU key decode error, invalid input", max);
  181. break;
  182. case ECC_BAD_ARG_E :
  183. XSTRNCPY(buffer, "ECC input argument wrong type, invalid input", max);
  184. break;
  185. case ASN_ECC_KEY_E :
  186. XSTRNCPY(buffer, "ECC ASN1 bad key data, invalid input", max);
  187. break;
  188. case ECC_CURVE_OID_E :
  189. XSTRNCPY(buffer, "ECC curve sum OID unsupported, invalid input", max);
  190. break;
  191. case BAD_FUNC_ARG :
  192. XSTRNCPY(buffer, "Bad function argument", max);
  193. break;
  194. case NOT_COMPILED_IN :
  195. XSTRNCPY(buffer, "Feature not compiled in", max);
  196. break;
  197. case UNICODE_SIZE_E :
  198. XSTRNCPY(buffer, "Unicode password too big", max);
  199. break;
  200. case NO_PASSWORD :
  201. XSTRNCPY(buffer, "No password provided by user", max);
  202. break;
  203. case ALT_NAME_E :
  204. XSTRNCPY(buffer, "Alt Name problem, too big", max);
  205. break;
  206. case AES_GCM_AUTH_E:
  207. XSTRNCPY(buffer, "AES-GCM Authentication check fail", max);
  208. break;
  209. case AES_CCM_AUTH_E:
  210. XSTRNCPY(buffer, "AES-CCM Authentication check fail", max);
  211. break;
  212. case CAVIUM_INIT_E:
  213. XSTRNCPY(buffer, "Cavium Init type error", max);
  214. break;
  215. default:
  216. XSTRNCPY(buffer, "unknown error number", max);
  217. }
  218. #endif /* NO_ERROR_STRINGS */
  219. }