blob: 9244249295ad419578aeac5a13d3e2cfb4235b95 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/**
2 * \file error.h
3 *
4 * \brief Error to string translation
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakker9d781402011-05-09 16:17:09 +00007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker9d781402011-05-09 16:17:09 +00009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_ERROR_H
25#define MBEDTLS_ERROR_H
Paul Bakker9d781402011-05-09 16:17:09 +000026
Rich Evans00ab4702015-02-06 13:43:58 +000027#include <stddef.h>
Paul Bakker3c2122f2013-06-24 19:03:14 +020028
Paul Bakker9d781402011-05-09 16:17:09 +000029/**
30 * Error code layout.
31 *
32 * Currently we try to keep all error codes within the negative space of 16
33 * bytes signed integers to support all platforms (-0x0000 - -0x8000). In
34 * addition we'd like to give two layers of information on the error if
35 * possible.
36 *
37 * For that purpose the error codes are segmented in the following manner:
38 *
39 * 16 bit error code bit-segmentation
40 *
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010041 * 1 bit - Sign bit
Paul Bakker9d781402011-05-09 16:17:09 +000042 * 3 bits - High level module ID
43 * 5 bits - Module-dependent error code
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010044 * 7 bits - Low level module errors
Paul Bakker9d781402011-05-09 16:17:09 +000045 *
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010046 * For historical reasons, low-level error codes are divided in even and odd,
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +010047 * even codes were assigned first, and -1 is reserved for other errors.
Paul Bakker9d781402011-05-09 16:17:09 +000048 *
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +010049 * Low-level module errors (0x0002-0x007E, 0x0003-0x007F)
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010050 *
51 * Module Nr Codes assigned
Paul Bakker69e095c2011-12-10 21:55:01 +000052 * MPI 7 0x0002-0x0010
Paul Bakkerd8ef1672012-04-18 14:17:32 +000053 * GCM 2 0x0012-0x0014
Paul Bakkera9379c02012-07-04 11:02:11 +000054 * BLOWFISH 2 0x0016-0x0018
Paul Bakker2466d932013-09-28 14:40:38 +020055 * THREADING 3 0x001A-0x001E
Paul Bakker9d781402011-05-09 16:17:09 +000056 * AES 2 0x0020-0x0022
57 * CAMELLIA 2 0x0024-0x0026
58 * XTEA 1 0x0028-0x0028
Paul Bakker69e095c2011-12-10 21:55:01 +000059 * BASE64 2 0x002A-0x002C
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +010060 * OID 1 0x002E-0x002E 0x000B-0x000B
Paul Bakker9d781402011-05-09 16:17:09 +000061 * PADLOCK 1 0x0030-0x0030
62 * DES 1 0x0032-0x0032
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010063 * CTR_DBRG 4 0x0034-0x003A
Paul Bakker43655f42011-12-15 20:11:16 +000064 * ENTROPY 3 0x003C-0x0040
Manuel Pégourié-Gonnard0b104b02015-05-14 21:52:40 +020065 * NET 9 0x0042-0x0052 0x0043-0x0043
Paul Bakker66ff70d2014-03-26 11:54:05 +010066 * ENTROPY 1 0x0058-0x0058
Paul Bakkerbdb912d2012-02-13 23:11:30 +000067 * ASN1 7 0x0060-0x006C
Paul Bakkerf518b162012-08-23 13:03:18 +000068 * PBKDF2 1 0x007C-0x007C
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +010069 * HMAC_DRBG 4 0x0003-0x0009
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020070 * CCM 2 0x000D-0x000F
Paul Bakker9d781402011-05-09 16:17:09 +000071 *
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +010072 * High-level module nr (3 bits - 0x0...-0x7...)
Paul Bakker0e06c0f2013-08-25 11:21:30 +020073 * Name ID Nr of Errors
74 * PEM 1 9
75 * PKCS#12 1 4 (Started from top)
Paul Bakker1a7550a2013-09-15 13:01:22 +020076 * X509 2 18
Manuel Pégourié-Gonnardeed55a42015-04-09 17:31:59 +020077 * PKCS5 2 4 (Started from top)
Paul Bakker40ce79f2013-09-15 17:43:54 +020078 * DHM 3 9
Manuel Pégourié-Gonnardeed55a42015-04-09 17:31:59 +020079 * PK 3 14 (Started from top)
Paul Bakker0e06c0f2013-08-25 11:21:30 +020080 * RSA 4 9
Manuel Pégourié-Gonnard35e95dd2014-04-08 12:17:41 +020081 * ECP 4 8 (Started from top)
Paul Bakker0e06c0f2013-08-25 11:21:30 +020082 * MD 5 4
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +020083 * CIPHER 6 6
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +010084 * SSL 6 16 (Started from top)
Paul Bakker0e06c0f2013-08-25 11:21:30 +020085 * SSL 7 31
Paul Bakker9d781402011-05-09 16:17:09 +000086 *
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010087 * Module dependent error code (5 bits 0x.00.-0x.F8.)
Paul Bakker9d781402011-05-09 16:17:09 +000088 */
89
Paul Bakkerbcd5db42011-05-20 12:30:59 +000090#ifdef __cplusplus
91extern "C" {
92#endif
93
Paul Bakker9d781402011-05-09 16:17:09 +000094/**
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +000095 * \brief Translate a mbed TLS error code into a string representation,
Paul Bakker9d781402011-05-09 16:17:09 +000096 * Result is truncated if necessary and always includes a terminating
97 * null byte.
98 *
99 * \param errnum error code
100 * \param buffer buffer to place representation in
101 * \param buflen length of the buffer
102 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103void mbedtls_strerror( int errnum, char *buffer, size_t buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200104
Paul Bakkerbcd5db42011-05-20 12:30:59 +0000105#ifdef __cplusplus
106}
107#endif
108
Paul Bakker9d781402011-05-09 16:17:09 +0000109#endif /* error.h */