error.h 3.23 KB
Newer Older
1 2 3 4 5
/**
 * \file error.h
 *
 * \brief Error to string translation
 *
Manuel Pégourié-Gonnard's avatar
Manuel Pégourié-Gonnard committed
6
 *  Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
7
 *
8
 *  This file is part of mbed TLS (https://tls.mbed.org)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
Manuel Pégourié-Gonnard's avatar
Manuel Pégourié-Gonnard committed
24 25
#ifndef MBEDTLS_ERROR_H
#define MBEDTLS_ERROR_H
26

27
#include <stddef.h>
28

29 30 31 32
/**
 * Error code layout.
 *
 * Currently we try to keep all error codes within the negative space of 16
33
 * bits signed integers to support all platforms (-0x0001 - -0x7FFF). In
34 35 36 37 38 39 40
 * addition we'd like to give two layers of information on the error if
 * possible.
 *
 * For that purpose the error codes are segmented in the following manner:
 *
 * 16 bit error code bit-segmentation
 *
41
 * 1 bit  - Unused (sign bit)
42 43
 * 3 bits - High level module ID
 * 5 bits - Module-dependent error code
44
 * 7 bits - Low level module errors
45
 *
46
 * For historical reasons, low-level error codes are divided in even and odd,
47
 * even codes were assigned first, and -1 is reserved for other errors.
48
 *
49
 * Low-level module errors (0x0002-0x007E, 0x0003-0x007F)
50 51
 *
 * Module   Nr  Codes assigned
52
 * MPI       7  0x0002-0x0010
Paul Bakker's avatar
Paul Bakker committed
53
 * GCM       2  0x0012-0x0014
54
 * BLOWFISH  2  0x0016-0x0018
55
 * THREADING 3  0x001A-0x001E
56 57 58
 * AES       2  0x0020-0x0022
 * CAMELLIA  2  0x0024-0x0026
 * XTEA      1  0x0028-0x0028
59
 * BASE64    2  0x002A-0x002C
60
 * OID       1  0x002E-0x002E   0x000B-0x000B
61 62
 * PADLOCK   1  0x0030-0x0030
 * DES       1  0x0032-0x0032
63
 * CTR_DBRG  4  0x0034-0x003A
64
 * ENTROPY   3  0x003C-0x0040   0x003D-0x003F
65
 * NET      11  0x0042-0x0052   0x0043-0x0045
66
 * ASN1      7  0x0060-0x006C
67
 * PBKDF2    1  0x007C-0x007C
68
 * HMAC_DRBG 4  0x0003-0x0009
69
 * CCM       2                  0x000D-0x000F
70
 *
71
 * High-level module nr (3 bits - 0x0...-0x7...)
72 73 74
 * Name      ID  Nr of Errors
 * PEM       1   9
 * PKCS#12   1   4 (Started from top)
75
 * X509      2   19
76
 * PKCS5     2   4 (Started from top)
77
 * DHM       3   9
78
 * PK        3   14 (Started from top)
79
 * RSA       4   9
80
 * ECP       4   8 (Started from top)
81
 * MD        5   4
82
 * CIPHER    6   6
83
 * SSL       6   16 (Started from top)
84
 * SSL       7   31
85
 *
86
 * Module dependent error code (5 bits 0x.00.-0x.F8.)
87 88
 */

Paul Bakker's avatar
Paul Bakker committed
89 90 91 92
#ifdef __cplusplus
extern "C" {
#endif

93
/**
94
 * \brief Translate a mbed TLS error code into a string representation,
95 96 97 98 99 100 101
 *        Result is truncated if necessary and always includes a terminating
 *        null byte.
 *
 * \param errnum    error code
 * \param buffer    buffer to place representation in
 * \param buflen    length of the buffer
 */
Manuel Pégourié-Gonnard's avatar
Manuel Pégourié-Gonnard committed
102
void mbedtls_strerror( int errnum, char *buffer, size_t buflen );
103

Paul Bakker's avatar
Paul Bakker committed
104 105 106 107
#ifdef __cplusplus
}
#endif

108
#endif /* error.h */