| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 1 | /** | 
|  | 2 | * \file error.h | 
|  | 3 | * | 
|  | 4 | * \brief Error to string translation | 
|  | 5 | * | 
| Paul Bakker | cf4365f | 2013-01-16 17:00:43 +0100 | [diff] [blame] | 6 | *  Copyright (C) 2006-2013, Brainspark B.V. | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 7 | * | 
|  | 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 Bakker | 3c2122f | 2013-06-24 19:03:14 +0200 | [diff] [blame] | 30 | #include <string.h> | 
|  | 31 |  | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 32 | /** | 
|  | 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é-Gonnard | cf38367 | 2014-02-01 10:22:21 +0100 | [diff] [blame] | 44 | * 1 bit  - Sign bit | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 45 | * 3 bits - High level module ID | 
|  | 46 | * 5 bits - Module-dependent error code | 
| Manuel Pégourié-Gonnard | cf38367 | 2014-02-01 10:22:21 +0100 | [diff] [blame] | 47 | * 7 bits - Low level module errors | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 48 | * | 
| Manuel Pégourié-Gonnard | cf38367 | 2014-02-01 10:22:21 +0100 | [diff] [blame] | 49 | * For historical reasons, low-level error codes are divided in even and odd, | 
| Manuel Pégourié-Gonnard | 9a6e93e | 2014-03-11 09:34:02 +0100 | [diff] [blame] | 50 | * even codes were assigned first, and -1 is reserved for other errors. | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 51 | * | 
| Manuel Pégourié-Gonnard | 9a6e93e | 2014-03-11 09:34:02 +0100 | [diff] [blame] | 52 | * Low-level module errors (0x0002-0x007E, 0x0003-0x007F) | 
| Manuel Pégourié-Gonnard | cf38367 | 2014-02-01 10:22:21 +0100 | [diff] [blame] | 53 | * | 
|  | 54 | * Module   Nr  Codes assigned | 
| Paul Bakker | 69e095c | 2011-12-10 21:55:01 +0000 | [diff] [blame] | 55 | * MPI       7  0x0002-0x0010 | 
| Paul Bakker | d8ef167 | 2012-04-18 14:17:32 +0000 | [diff] [blame] | 56 | * GCM       2  0x0012-0x0014 | 
| Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 57 | * BLOWFISH  2  0x0016-0x0018 | 
| Paul Bakker | 2466d93 | 2013-09-28 14:40:38 +0200 | [diff] [blame] | 58 | * THREADING 3  0x001A-0x001E | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 59 | * AES       2  0x0020-0x0022 | 
|  | 60 | * CAMELLIA  2  0x0024-0x0026 | 
|  | 61 | * XTEA      1  0x0028-0x0028 | 
| Paul Bakker | 69e095c | 2011-12-10 21:55:01 +0000 | [diff] [blame] | 62 | * BASE64    2  0x002A-0x002C | 
| Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 63 | * OID       1  0x002E-0x002E   0x000B-0x000B | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 64 | * PADLOCK   1  0x0030-0x0030 | 
|  | 65 | * DES       1  0x0032-0x0032 | 
| Manuel Pégourié-Gonnard | cf38367 | 2014-02-01 10:22:21 +0100 | [diff] [blame] | 66 | * CTR_DBRG  4  0x0034-0x003A | 
| Paul Bakker | 43655f4 | 2011-12-15 20:11:16 +0000 | [diff] [blame] | 67 | * ENTROPY   3  0x003C-0x0040 | 
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 68 | * NET      11  0x0042-0x0056 | 
| Paul Bakker | 66ff70d | 2014-03-26 11:54:05 +0100 | [diff] [blame] | 69 | * ENTROPY   1  0x0058-0x0058 | 
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 70 | * ASN1      7  0x0060-0x006C | 
| Paul Bakker | 69e095c | 2011-12-10 21:55:01 +0000 | [diff] [blame] | 71 | * MD2       1  0x0070-0x0070 | 
|  | 72 | * MD4       1  0x0072-0x0072 | 
|  | 73 | * MD5       1  0x0074-0x0074 | 
|  | 74 | * SHA1      1  0x0076-0x0076 | 
| Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 75 | * SHA256    1  0x0078-0x0078 | 
|  | 76 | * SHA512    1  0x007A-0x007A | 
| Paul Bakker | f518b16 | 2012-08-23 13:03:18 +0000 | [diff] [blame] | 77 | * PBKDF2    1  0x007C-0x007C | 
| Manuel Pégourié-Gonnard | cf38367 | 2014-02-01 10:22:21 +0100 | [diff] [blame] | 78 | * RIPEMD160 1  0x007E-0x007E | 
| Manuel Pégourié-Gonnard | 9a6e93e | 2014-03-11 09:34:02 +0100 | [diff] [blame] | 79 | * HMAC_DRBG 4  0x0003-0x0009 | 
| Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 80 | * CCM       2                  0x000D-0x000F | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 81 | * | 
| Manuel Pégourié-Gonnard | 9a6e93e | 2014-03-11 09:34:02 +0100 | [diff] [blame] | 82 | * High-level module nr (3 bits - 0x0...-0x7...) | 
| Paul Bakker | 0e06c0f | 2013-08-25 11:21:30 +0200 | [diff] [blame] | 83 | * Name      ID  Nr of Errors | 
|  | 84 | * PEM       1   9 | 
|  | 85 | * PKCS#12   1   4 (Started from top) | 
| Paul Bakker | 1a7550a | 2013-09-15 13:01:22 +0200 | [diff] [blame] | 86 | * X509      2   18 | 
| Manuel Pégourié-Gonnard | 2abed84 | 2014-04-08 12:40:15 +0200 | [diff] [blame] | 87 | * PK        2   14 (Started from top, plus 0x2000) | 
| Paul Bakker | 40ce79f | 2013-09-15 17:43:54 +0200 | [diff] [blame] | 88 | * DHM       3   9 | 
| Paul Bakker | 0e06c0f | 2013-08-25 11:21:30 +0200 | [diff] [blame] | 89 | * PKCS5     3   4 (Started from top) | 
|  | 90 | * RSA       4   9 | 
| Manuel Pégourié-Gonnard | 35e95dd | 2014-04-08 12:17:41 +0200 | [diff] [blame] | 91 | * ECP       4   8 (Started from top) | 
| Paul Bakker | 0e06c0f | 2013-08-25 11:21:30 +0200 | [diff] [blame] | 92 | * MD        5   4 | 
| Manuel Pégourié-Gonnard | 4fee79b | 2013-09-19 18:09:14 +0200 | [diff] [blame] | 93 | * CIPHER    6   6 | 
| Manuel Pégourié-Gonnard | 83cdffc | 2014-03-10 21:20:29 +0100 | [diff] [blame] | 94 | * SSL       6   9 (Started from top) | 
| Paul Bakker | 0e06c0f | 2013-08-25 11:21:30 +0200 | [diff] [blame] | 95 | * SSL       7   31 | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 96 | * | 
| Manuel Pégourié-Gonnard | cf38367 | 2014-02-01 10:22:21 +0100 | [diff] [blame] | 97 | * Module dependent error code (5 bits 0x.00.-0x.F8.) | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 98 | */ | 
|  | 99 |  | 
| Paul Bakker | bcd5db4 | 2011-05-20 12:30:59 +0000 | [diff] [blame] | 100 | #ifdef __cplusplus | 
|  | 101 | extern "C" { | 
|  | 102 | #endif | 
|  | 103 |  | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 104 | /** | 
|  | 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 Bakker | e2ab84f | 2013-06-29 18:24:32 +0200 | [diff] [blame] | 113 | void polarssl_strerror( int errnum, char *buffer, size_t buflen ); | 
|  | 114 |  | 
|  | 115 | #if defined(POLARSSL_ERROR_STRERROR_BC) | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 116 | void error_strerror( int errnum, char *buffer, size_t buflen ); | 
| Paul Bakker | e2ab84f | 2013-06-29 18:24:32 +0200 | [diff] [blame] | 117 | #endif | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 118 |  | 
| Paul Bakker | bcd5db4 | 2011-05-20 12:30:59 +0000 | [diff] [blame] | 119 | #ifdef __cplusplus | 
|  | 120 | } | 
|  | 121 | #endif | 
|  | 122 |  | 
| Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 123 | #endif /* error.h */ |