blob: e6ad54a04e4f86d90db2f119ca7f77ea5454c485 [file] [log] [blame] [raw]
Paul Bakker9d781402011-05-09 16:17:09 +00001/**
2 * \file error.h
3 *
4 * \brief Error to string translation
5 *
Paul Bakkercf4365f2013-01-16 17:00:43 +01006 * Copyright (C) 2006-2013, Brainspark B.V.
Paul Bakker9d781402011-05-09 16:17:09 +00007 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_ERROR_H
28#define POLARSSL_ERROR_H
29
Paul Bakker3c2122f2013-06-24 19:03:14 +020030#include <string.h>
31
Paul Bakker9d781402011-05-09 16:17:09 +000032/**
33 * Error code layout.
34 *
35 * Currently we try to keep all error codes within the negative space of 16
36 * bytes signed integers to support all platforms (-0x0000 - -0x8000). In
37 * addition we'd like to give two layers of information on the error if
38 * possible.
39 *
40 * For that purpose the error codes are segmented in the following manner:
41 *
42 * 16 bit error code bit-segmentation
43 *
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010044 * 1 bit - Sign bit
Paul Bakker9d781402011-05-09 16:17:09 +000045 * 3 bits - High level module ID
46 * 5 bits - Module-dependent error code
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010047 * 7 bits - Low level module errors
Paul Bakker9d781402011-05-09 16:17:09 +000048 *
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010049 * For historical reasons, low-level error codes are divided in even and odd,
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +010050 * even codes were assigned first, and -1 is reserved for other errors.
Paul Bakker9d781402011-05-09 16:17:09 +000051 *
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +010052 * Low-level module errors (0x0002-0x007E, 0x0003-0x007F)
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010053 *
54 * Module Nr Codes assigned
Paul Bakker69e095c2011-12-10 21:55:01 +000055 * MPI 7 0x0002-0x0010
Paul Bakkerd8ef1672012-04-18 14:17:32 +000056 * GCM 2 0x0012-0x0014
Paul Bakkera9379c02012-07-04 11:02:11 +000057 * BLOWFISH 2 0x0016-0x0018
Paul Bakker2466d932013-09-28 14:40:38 +020058 * THREADING 3 0x001A-0x001E
Paul Bakker9d781402011-05-09 16:17:09 +000059 * AES 2 0x0020-0x0022
60 * CAMELLIA 2 0x0024-0x0026
61 * XTEA 1 0x0028-0x0028
Paul Bakker69e095c2011-12-10 21:55:01 +000062 * BASE64 2 0x002A-0x002C
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +010063 * OID 1 0x002E-0x002E 0x000B-0x000B
Paul Bakker9d781402011-05-09 16:17:09 +000064 * PADLOCK 1 0x0030-0x0030
65 * DES 1 0x0032-0x0032
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010066 * CTR_DBRG 4 0x0034-0x003A
Paul Bakker43655f42011-12-15 20:11:16 +000067 * ENTROPY 3 0x003C-0x0040
Paul Bakkerbdb912d2012-02-13 23:11:30 +000068 * NET 11 0x0042-0x0056
Paul Bakker66ff70d2014-03-26 11:54:05 +010069 * ENTROPY 1 0x0058-0x0058
Paul Bakkerbdb912d2012-02-13 23:11:30 +000070 * ASN1 7 0x0060-0x006C
Paul Bakker69e095c2011-12-10 21:55:01 +000071 * MD2 1 0x0070-0x0070
72 * MD4 1 0x0072-0x0072
73 * MD5 1 0x0074-0x0074
74 * SHA1 1 0x0076-0x0076
Paul Bakker9e36f042013-06-30 14:34:05 +020075 * SHA256 1 0x0078-0x0078
76 * SHA512 1 0x007A-0x007A
Paul Bakkerf518b162012-08-23 13:03:18 +000077 * PBKDF2 1 0x007C-0x007C
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010078 * RIPEMD160 1 0x007E-0x007E
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +010079 * HMAC_DRBG 4 0x0003-0x0009
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020080 * CCM 2 0x000D-0x000F
Paul Bakker9d781402011-05-09 16:17:09 +000081 *
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +010082 * High-level module nr (3 bits - 0x0...-0x7...)
Paul Bakker0e06c0f2013-08-25 11:21:30 +020083 * Name ID Nr of Errors
84 * PEM 1 9
85 * PKCS#12 1 4 (Started from top)
Paul Bakker1a7550a2013-09-15 13:01:22 +020086 * X509 2 18
Manuel Pégourié-Gonnard2abed842014-04-08 12:40:15 +020087 * PK 2 14 (Started from top, plus 0x2000)
Paul Bakker40ce79f2013-09-15 17:43:54 +020088 * DHM 3 9
Paul Bakker0e06c0f2013-08-25 11:21:30 +020089 * PKCS5 3 4 (Started from top)
90 * RSA 4 9
Manuel Pégourié-Gonnard35e95dd2014-04-08 12:17:41 +020091 * ECP 4 8 (Started from top)
Paul Bakker0e06c0f2013-08-25 11:21:30 +020092 * MD 5 4
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +020093 * CIPHER 6 6
Manuel Pégourié-Gonnard562eb782014-07-23 23:41:53 +020094 * SSL 6 12 (Started from top)
Paul Bakker0e06c0f2013-08-25 11:21:30 +020095 * SSL 7 31
Paul Bakker9d781402011-05-09 16:17:09 +000096 *
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010097 * Module dependent error code (5 bits 0x.00.-0x.F8.)
Paul Bakker9d781402011-05-09 16:17:09 +000098 */
99
Paul Bakkerbcd5db42011-05-20 12:30:59 +0000100#ifdef __cplusplus
101extern "C" {
102#endif
103
Paul Bakker9d781402011-05-09 16:17:09 +0000104/**
105 * \brief Translate a PolarSSL error code into a string representation,
106 * Result is truncated if necessary and always includes a terminating
107 * null byte.
108 *
109 * \param errnum error code
110 * \param buffer buffer to place representation in
111 * \param buflen length of the buffer
112 */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200113void polarssl_strerror( int errnum, char *buffer, size_t buflen );
114
115#if defined(POLARSSL_ERROR_STRERROR_BC)
Paul Bakker9d781402011-05-09 16:17:09 +0000116void error_strerror( int errnum, char *buffer, size_t buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200117#endif
Paul Bakker9d781402011-05-09 16:17:09 +0000118
Paul Bakkerbcd5db42011-05-20 12:30:59 +0000119#ifdef __cplusplus
120}
121#endif
122
Paul Bakker9d781402011-05-09 16:17:09 +0000123#endif /* error.h */