blob: c3b0b1573bed1a8cb753db07ccad6ee9a11371dc [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é-Gonnard88369942015-05-06 16:19:31 +010065 * NET 9 0x0042-0x0052
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 Bakker69e095c2011-12-10 21:55:01 +000068 * MD2 1 0x0070-0x0070
69 * MD4 1 0x0072-0x0072
70 * MD5 1 0x0074-0x0074
71 * SHA1 1 0x0076-0x0076
Paul Bakker9e36f042013-06-30 14:34:05 +020072 * SHA256 1 0x0078-0x0078
73 * SHA512 1 0x007A-0x007A
Paul Bakkerf518b162012-08-23 13:03:18 +000074 * PBKDF2 1 0x007C-0x007C
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010075 * RIPEMD160 1 0x007E-0x007E
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +010076 * HMAC_DRBG 4 0x0003-0x0009
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020077 * CCM 2 0x000D-0x000F
Paul Bakker9d781402011-05-09 16:17:09 +000078 *
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +010079 * High-level module nr (3 bits - 0x0...-0x7...)
Paul Bakker0e06c0f2013-08-25 11:21:30 +020080 * Name ID Nr of Errors
81 * PEM 1 9
82 * PKCS#12 1 4 (Started from top)
Paul Bakker1a7550a2013-09-15 13:01:22 +020083 * X509 2 18
Manuel Pégourié-Gonnardeed55a42015-04-09 17:31:59 +020084 * PKCS5 2 4 (Started from top)
Paul Bakker40ce79f2013-09-15 17:43:54 +020085 * DHM 3 9
Manuel Pégourié-Gonnardeed55a42015-04-09 17:31:59 +020086 * PK 3 14 (Started from top)
Paul Bakker0e06c0f2013-08-25 11:21:30 +020087 * RSA 4 9
Manuel Pégourié-Gonnard35e95dd2014-04-08 12:17:41 +020088 * ECP 4 8 (Started from top)
Paul Bakker0e06c0f2013-08-25 11:21:30 +020089 * MD 5 4
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +020090 * CIPHER 6 6
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +010091 * SSL 6 16 (Started from top)
Paul Bakker0e06c0f2013-08-25 11:21:30 +020092 * SSL 7 31
Paul Bakker9d781402011-05-09 16:17:09 +000093 *
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010094 * Module dependent error code (5 bits 0x.00.-0x.F8.)
Paul Bakker9d781402011-05-09 16:17:09 +000095 */
96
Paul Bakkerbcd5db42011-05-20 12:30:59 +000097#ifdef __cplusplus
98extern "C" {
99#endif
100
Paul Bakker9d781402011-05-09 16:17:09 +0000101/**
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +0000102 * \brief Translate a mbed TLS error code into a string representation,
Paul Bakker9d781402011-05-09 16:17:09 +0000103 * Result is truncated if necessary and always includes a terminating
104 * null byte.
105 *
106 * \param errnum error code
107 * \param buffer buffer to place representation in
108 * \param buflen length of the buffer
109 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110void mbedtls_strerror( int errnum, char *buffer, size_t buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200111
Paul Bakkerbcd5db42011-05-20 12:30:59 +0000112#ifdef __cplusplus
113}
114#endif
115
Paul Bakker9d781402011-05-09 16:17:09 +0000116#endif /* error.h */