Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Error message information |
| 3 | * |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | * not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 18 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 19 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 22 | #if !defined(MBEDTLS_CONFIG_FILE) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 23 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 24 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 25 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 26 | #endif |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 27 | |
Janos Follath | df587ee | 2019-12-18 13:16:46 +0000 | [diff] [blame] | 28 | #if defined(MBEDTLS_ERROR_STRERROR_DUMMY) |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 29 | #include <string.h> |
Manuel Pégourié-Gonnard | bee8ded | 2014-06-25 12:22:59 +0200 | [diff] [blame] | 30 | #endif |
| 31 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 32 | #if defined(MBEDTLS_PLATFORM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 33 | #include "mbedtls/platform.h" |
Manuel Pégourié-Gonnard | 0928640 | 2015-02-13 15:18:33 +0000 | [diff] [blame] | 34 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 35 | #define mbedtls_snprintf snprintf |
-~- redtangent ~-~ | 9fa2e86 | 2016-05-26 10:07:49 +0100 | [diff] [blame] | 36 | #define mbedtls_time_t time_t |
Manuel Pégourié-Gonnard | bee8ded | 2014-06-25 12:22:59 +0200 | [diff] [blame] | 37 | #endif |
| 38 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 39 | #if defined(MBEDTLS_ERROR_C) |
Paul Bakker | 3c2122f | 2013-06-24 19:03:14 +0200 | [diff] [blame] | 40 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 41 | #include <stdio.h> |
| 42 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 43 | #if defined(MBEDTLS_AES_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 44 | #include "mbedtls/aes.h" |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 45 | #endif |
| 46 | |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 47 | #if defined(MBEDTLS_ARC4_C) |
| 48 | #include "mbedtls/arc4.h" |
| 49 | #endif |
| 50 | |
Markku-Juhani O. Saarinen | 07478d6 | 2017-12-01 16:20:15 +0000 | [diff] [blame] | 51 | #if defined(MBEDTLS_ARIA_C) |
| 52 | #include "mbedtls/aria.h" |
| 53 | #endif |
| 54 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 55 | #if defined(MBEDTLS_BASE64_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 56 | #include "mbedtls/base64.h" |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 57 | #endif |
| 58 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 59 | #if defined(MBEDTLS_BIGNUM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 60 | #include "mbedtls/bignum.h" |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 61 | #endif |
| 62 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 63 | #if defined(MBEDTLS_BLOWFISH_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 64 | #include "mbedtls/blowfish.h" |
Paul Bakker | 83f00bb | 2012-07-04 11:08:50 +0000 | [diff] [blame] | 65 | #endif |
| 66 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 67 | #if defined(MBEDTLS_CAMELLIA_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 68 | #include "mbedtls/camellia.h" |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 69 | #endif |
| 70 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 71 | #if defined(MBEDTLS_CCM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 72 | #include "mbedtls/ccm.h" |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 73 | #endif |
| 74 | |
Daniel King | 34b822c | 2016-05-15 17:28:08 -0300 | [diff] [blame] | 75 | #if defined(MBEDTLS_CHACHA20_C) |
| 76 | #include "mbedtls/chacha20.h" |
| 77 | #endif |
| 78 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 79 | #if defined(MBEDTLS_CHACHAPOLY_C) |
| 80 | #include "mbedtls/chachapoly.h" |
| 81 | #endif |
| 82 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 83 | #if defined(MBEDTLS_CIPHER_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 84 | #include "mbedtls/cipher.h" |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 85 | #endif |
| 86 | |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 87 | #if defined(MBEDTLS_CMAC_C) |
| 88 | #include "mbedtls/cmac.h" |
| 89 | #endif |
| 90 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 91 | #if defined(MBEDTLS_CTR_DRBG_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 92 | #include "mbedtls/ctr_drbg.h" |
Paul Bakker | 880ac7e | 2011-11-27 14:50:49 +0000 | [diff] [blame] | 93 | #endif |
| 94 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 95 | #if defined(MBEDTLS_DES_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 96 | #include "mbedtls/des.h" |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 97 | #endif |
| 98 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 99 | #if defined(MBEDTLS_DHM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 100 | #include "mbedtls/dhm.h" |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 101 | #endif |
| 102 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 103 | #if defined(MBEDTLS_ECP_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 104 | #include "mbedtls/ecp.h" |
Paul Bakker | cf4365f | 2013-01-16 17:00:43 +0100 | [diff] [blame] | 105 | #endif |
| 106 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 107 | #if defined(MBEDTLS_ENTROPY_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 108 | #include "mbedtls/entropy.h" |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 109 | #endif |
| 110 | |
Janos Follath | 60f6b64 | 2019-12-03 15:55:56 +0000 | [diff] [blame] | 111 | #if defined(MBEDTLS_ERROR_C) |
| 112 | #include "mbedtls/error.h" |
| 113 | #endif |
| 114 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 115 | #if defined(MBEDTLS_GCM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 116 | #include "mbedtls/gcm.h" |
Paul Bakker | 030277a | 2012-04-17 12:24:26 +0000 | [diff] [blame] | 117 | #endif |
| 118 | |
Thomas Fossati | 656864b | 2016-07-17 08:51:22 +0100 | [diff] [blame] | 119 | #if defined(MBEDTLS_HKDF_C) |
| 120 | #include "mbedtls/hkdf.h" |
| 121 | #endif |
| 122 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 123 | #if defined(MBEDTLS_HMAC_DRBG_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 124 | #include "mbedtls/hmac_drbg.h" |
Manuel Pégourié-Gonnard | cf38367 | 2014-02-01 10:22:21 +0100 | [diff] [blame] | 125 | #endif |
| 126 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 127 | #if defined(MBEDTLS_MD_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 128 | #include "mbedtls/md.h" |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 129 | #endif |
| 130 | |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 131 | #if defined(MBEDTLS_MD2_C) |
| 132 | #include "mbedtls/md2.h" |
| 133 | #endif |
| 134 | |
| 135 | #if defined(MBEDTLS_MD4_C) |
| 136 | #include "mbedtls/md4.h" |
| 137 | #endif |
| 138 | |
| 139 | #if defined(MBEDTLS_MD5_C) |
| 140 | #include "mbedtls/md5.h" |
| 141 | #endif |
| 142 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 143 | #if defined(MBEDTLS_OID_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 144 | #include "mbedtls/oid.h" |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 145 | #endif |
| 146 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 147 | #if defined(MBEDTLS_PADLOCK_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 148 | #include "mbedtls/padlock.h" |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 149 | #endif |
| 150 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 151 | #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 152 | #include "mbedtls/pem.h" |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 153 | #endif |
| 154 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 155 | #if defined(MBEDTLS_PK_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 156 | #include "mbedtls/pk.h" |
Manuel Pégourié-Gonnard | 7a6c946 | 2013-07-09 10:04:07 +0200 | [diff] [blame] | 157 | #endif |
| 158 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 159 | #if defined(MBEDTLS_PKCS12_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 160 | #include "mbedtls/pkcs12.h" |
Paul Bakker | f1f21fe | 2013-06-24 19:17:19 +0200 | [diff] [blame] | 161 | #endif |
| 162 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 163 | #if defined(MBEDTLS_PKCS5_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 164 | #include "mbedtls/pkcs5.h" |
Paul Bakker | b0c19a4 | 2013-06-24 19:26:38 +0200 | [diff] [blame] | 165 | #endif |
| 166 | |
Ron Eldor | 0ff4e0b | 2018-08-29 18:53:20 +0300 | [diff] [blame] | 167 | #if defined(MBEDTLS_PLATFORM_C) |
| 168 | #include "mbedtls/platform.h" |
| 169 | #endif |
| 170 | |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 171 | #if defined(MBEDTLS_POLY1305_C) |
| 172 | #include "mbedtls/poly1305.h" |
| 173 | #endif |
| 174 | |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 175 | #if defined(MBEDTLS_RIPEMD160_C) |
| 176 | #include "mbedtls/ripemd160.h" |
| 177 | #endif |
| 178 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 179 | #if defined(MBEDTLS_RSA_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 180 | #include "mbedtls/rsa.h" |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 181 | #endif |
| 182 | |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 183 | #if defined(MBEDTLS_SHA1_C) |
| 184 | #include "mbedtls/sha1.h" |
| 185 | #endif |
| 186 | |
| 187 | #if defined(MBEDTLS_SHA256_C) |
| 188 | #include "mbedtls/sha256.h" |
| 189 | #endif |
| 190 | |
| 191 | #if defined(MBEDTLS_SHA512_C) |
| 192 | #include "mbedtls/sha512.h" |
| 193 | #endif |
| 194 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 195 | #if defined(MBEDTLS_THREADING_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 196 | #include "mbedtls/threading.h" |
Paul Bakker | 2466d93 | 2013-09-28 14:40:38 +0200 | [diff] [blame] | 197 | #endif |
| 198 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 199 | #if defined(MBEDTLS_XTEA_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 200 | #include "mbedtls/xtea.h" |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 201 | #endif |
| 202 | |
Paul Bakker | dceecd8 | 2011-11-15 16:38:34 +0000 | [diff] [blame] | 203 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 204 | void mbedtls_strerror( int ret, char *buf, size_t buflen ) |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 205 | { |
| 206 | size_t len; |
| 207 | int use_ret; |
| 208 | |
Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 209 | if( buflen == 0 ) |
| 210 | return; |
| 211 | |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 212 | memset( buf, 0x00, buflen ); |
Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 213 | |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 214 | if( ret < 0 ) |
| 215 | ret = -ret; |
| 216 | |
| 217 | if( ret & 0xFF80 ) |
| 218 | { |
| 219 | use_ret = ret & 0xFF80; |
| 220 | |
| 221 | // High level error codes |
| 222 | // |
Manuel Pégourié-Gonnard | fe671f4 | 2014-04-11 18:06:44 +0200 | [diff] [blame] | 223 | // BEGIN generated code |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 224 | #if defined(MBEDTLS_CIPHER_C) |
| 225 | if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) ) |
| 226 | mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" ); |
| 227 | if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) ) |
Rose Zadik | 9ba6b62 | 2018-01-24 12:59:19 +0000 | [diff] [blame] | 228 | mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 229 | if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) ) |
| 230 | mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" ); |
| 231 | if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) ) |
| 232 | mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" ); |
| 233 | if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) ) |
| 234 | mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" ); |
| 235 | if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) ) |
| 236 | mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" ); |
Janos Follath | 98e28a7 | 2016-05-31 14:03:54 +0100 | [diff] [blame] | 237 | if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) ) |
Rose Zadik | 9ba6b62 | 2018-01-24 12:59:19 +0000 | [diff] [blame] | 238 | mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid. For example, because it was freed" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 239 | if( use_ret == -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED) ) |
| 240 | mbedtls_snprintf( buf, buflen, "CIPHER - Cipher hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 241 | #endif /* MBEDTLS_CIPHER_C */ |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 242 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 243 | #if defined(MBEDTLS_DHM_C) |
| 244 | if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) ) |
Rose Zadik | 41ad082 | 2018-01-26 10:54:57 +0000 | [diff] [blame] | 245 | mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 246 | if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) ) |
| 247 | mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" ); |
| 248 | if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) ) |
| 249 | mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" ); |
| 250 | if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) ) |
| 251 | mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" ); |
| 252 | if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) ) |
| 253 | mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" ); |
| 254 | if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) ) |
| 255 | mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" ); |
| 256 | if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) ) |
| 257 | mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" ); |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 258 | if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 259 | mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" ); |
| 260 | if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) ) |
Rose Zadik | 41ad082 | 2018-01-26 10:54:57 +0000 | [diff] [blame] | 261 | mbedtls_snprintf( buf, buflen, "DHM - Read or write of file failed" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 262 | if( use_ret == -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED) ) |
| 263 | mbedtls_snprintf( buf, buflen, "DHM - DHM hardware accelerator failed" ); |
Hanno Becker | a6dd90d | 2017-10-04 13:15:54 +0100 | [diff] [blame] | 264 | if( use_ret == -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED) ) |
Jaeden Amero | 784de59 | 2018-01-26 17:52:01 +0000 | [diff] [blame] | 265 | mbedtls_snprintf( buf, buflen, "DHM - Setting the modulus and generator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 266 | #endif /* MBEDTLS_DHM_C */ |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 267 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 268 | #if defined(MBEDTLS_ECP_C) |
| 269 | if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) ) |
| 270 | mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" ); |
| 271 | if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) ) |
| 272 | mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" ); |
| 273 | if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) ) |
Jaeden Amero | 3dd8abd | 2018-04-24 10:56:55 +0100 | [diff] [blame] | 274 | mbedtls_snprintf( buf, buflen, "ECP - The requested feature is not available, for example, the requested curve is not supported" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 275 | if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) ) |
| 276 | mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" ); |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 277 | if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 278 | mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" ); |
| 279 | if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) ) |
Jaeden Amero | 3dd8abd | 2018-04-24 10:56:55 +0100 | [diff] [blame] | 280 | mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as ephemeral key, failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 281 | if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) ) |
| 282 | mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" ); |
| 283 | if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) ) |
Gilles Peskine | cc78ac4 | 2018-03-30 18:52:10 +0200 | [diff] [blame] | 284 | mbedtls_snprintf( buf, buflen, "ECP - The buffer contains a valid signature followed by more data" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 285 | if( use_ret == -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED) ) |
Jaeden Amero | 3dd8abd | 2018-04-24 10:56:55 +0100 | [diff] [blame] | 286 | mbedtls_snprintf( buf, buflen, "ECP - The ECP hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 5e3c62f | 2017-03-08 10:14:11 +0100 | [diff] [blame] | 287 | if( use_ret == -(MBEDTLS_ERR_ECP_IN_PROGRESS) ) |
Manuel Pégourié-Gonnard | f0bbd7e | 2018-10-15 13:22:41 +0200 | [diff] [blame] | 288 | mbedtls_snprintf( buf, buflen, "ECP - Operation in progress, call again with the same parameters to continue" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 289 | #endif /* MBEDTLS_ECP_C */ |
Paul Bakker | cf4365f | 2013-01-16 17:00:43 +0100 | [diff] [blame] | 290 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 291 | #if defined(MBEDTLS_MD_C) |
| 292 | if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) ) |
| 293 | mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" ); |
| 294 | if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) ) |
| 295 | mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" ); |
| 296 | if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) ) |
| 297 | mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" ); |
| 298 | if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) ) |
| 299 | mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 300 | if( use_ret == -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED) ) |
| 301 | mbedtls_snprintf( buf, buflen, "MD - MD hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 302 | #endif /* MBEDTLS_MD_C */ |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 303 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 304 | #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) |
| 305 | if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) ) |
| 306 | mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" ); |
| 307 | if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) ) |
| 308 | mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" ); |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 309 | if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 310 | mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" ); |
| 311 | if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) ) |
| 312 | mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" ); |
| 313 | if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) ) |
| 314 | mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" ); |
| 315 | if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) ) |
| 316 | mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" ); |
| 317 | if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) ) |
| 318 | mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" ); |
| 319 | if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) ) |
| 320 | mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" ); |
| 321 | if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) ) |
| 322 | mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" ); |
| 323 | #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */ |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 324 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 325 | #if defined(MBEDTLS_PK_C) |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 326 | if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) ) |
Manuel Pégourié-Gonnard | 41b9c2b | 2015-05-28 14:56:20 +0200 | [diff] [blame] | 327 | mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 328 | if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) ) |
| 329 | mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" ); |
| 330 | if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) ) |
| 331 | mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" ); |
| 332 | if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) ) |
| 333 | mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" ); |
| 334 | if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) ) |
| 335 | mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" ); |
| 336 | if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) ) |
| 337 | mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" ); |
| 338 | if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) ) |
| 339 | mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" ); |
| 340 | if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) ) |
| 341 | mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" ); |
| 342 | if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) ) |
| 343 | mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" ); |
| 344 | if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) ) |
| 345 | mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" ); |
| 346 | if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) ) |
| 347 | mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" ); |
| 348 | if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) ) |
| 349 | mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" ); |
| 350 | if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) ) |
| 351 | mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" ); |
| 352 | if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) ) |
Gilles Peskine | cc78ac4 | 2018-03-30 18:52:10 +0200 | [diff] [blame] | 353 | mbedtls_snprintf( buf, buflen, "PK - The buffer contains a valid signature followed by more data" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 354 | if( use_ret == -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED) ) |
| 355 | mbedtls_snprintf( buf, buflen, "PK - PK hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 356 | #endif /* MBEDTLS_PK_C */ |
Manuel Pégourié-Gonnard | 7a6c946 | 2013-07-09 10:04:07 +0200 | [diff] [blame] | 357 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 358 | #if defined(MBEDTLS_PKCS12_C) |
| 359 | if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) ) |
| 360 | mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" ); |
| 361 | if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) ) |
| 362 | mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" ); |
| 363 | if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) ) |
| 364 | mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" ); |
| 365 | if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) ) |
| 366 | mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" ); |
| 367 | #endif /* MBEDTLS_PKCS12_C */ |
Paul Bakker | f1f21fe | 2013-06-24 19:17:19 +0200 | [diff] [blame] | 368 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 369 | #if defined(MBEDTLS_PKCS5_C) |
| 370 | if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) ) |
| 371 | mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" ); |
| 372 | if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) ) |
| 373 | mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" ); |
| 374 | if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) ) |
| 375 | mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" ); |
| 376 | if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) ) |
| 377 | mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" ); |
| 378 | #endif /* MBEDTLS_PKCS5_C */ |
Paul Bakker | 28144de | 2013-06-24 19:28:55 +0200 | [diff] [blame] | 379 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 380 | #if defined(MBEDTLS_RSA_C) |
| 381 | if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) ) |
| 382 | mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" ); |
| 383 | if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) ) |
| 384 | mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" ); |
| 385 | if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) ) |
| 386 | mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" ); |
| 387 | if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) ) |
Rose Zadik | 042e97f | 2018-01-26 16:35:10 +0000 | [diff] [blame] | 388 | mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the validity check of the library" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 389 | if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) ) |
| 390 | mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" ); |
| 391 | if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) ) |
| 392 | mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" ); |
| 393 | if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) ) |
| 394 | mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" ); |
| 395 | if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) ) |
| 396 | mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" ); |
| 397 | if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) ) |
| 398 | mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" ); |
Hanno Becker | 3cdc711 | 2017-10-05 10:09:31 +0100 | [diff] [blame] | 399 | if( use_ret == -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION) ) |
Rose Zadik | 042e97f | 2018-01-26 16:35:10 +0000 | [diff] [blame] | 400 | mbedtls_snprintf( buf, buflen, "RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 401 | if( use_ret == -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED) ) |
| 402 | mbedtls_snprintf( buf, buflen, "RSA - RSA hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 403 | #endif /* MBEDTLS_RSA_C */ |
Manuel Pégourié-Gonnard | fe671f4 | 2014-04-11 18:06:44 +0200 | [diff] [blame] | 404 | // END generated code |
Paul Bakker | 0e06c0f | 2013-08-25 11:21:30 +0200 | [diff] [blame] | 405 | |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 406 | if( strlen( buf ) == 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 407 | mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | use_ret = ret & ~0xFF80; |
| 411 | |
| 412 | if( use_ret == 0 ) |
| 413 | return; |
| 414 | |
| 415 | // If high level code is present, make a concatenation between both |
| 416 | // error strings. |
| 417 | // |
| 418 | len = strlen( buf ); |
| 419 | |
| 420 | if( len > 0 ) |
| 421 | { |
| 422 | if( buflen - len < 5 ) |
| 423 | return; |
| 424 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 425 | mbedtls_snprintf( buf + len, buflen - len, " : " ); |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 426 | |
| 427 | buf += len + 3; |
| 428 | buflen -= len + 3; |
| 429 | } |
| 430 | |
| 431 | // Low level error codes |
| 432 | // |
Manuel Pégourié-Gonnard | fe671f4 | 2014-04-11 18:06:44 +0200 | [diff] [blame] | 433 | // BEGIN generated code |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 434 | #if defined(MBEDTLS_AES_C) |
| 435 | if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) ) |
| 436 | mbedtls_snprintf( buf, buflen, "AES - Invalid key length" ); |
| 437 | if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) ) |
| 438 | mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" ); |
Mohammad Azim Khan | e5b5bd7 | 2017-11-24 10:52:51 +0000 | [diff] [blame] | 439 | if( use_ret == -(MBEDTLS_ERR_AES_BAD_INPUT_DATA) ) |
| 440 | mbedtls_snprintf( buf, buflen, "AES - Invalid input data" ); |
Andres Amaya Garcia | fd48739 | 2017-06-14 16:19:12 +0100 | [diff] [blame] | 441 | if( use_ret == -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE) ) |
Rose Zadik | 7f44127 | 2018-01-22 11:48:23 +0000 | [diff] [blame] | 442 | mbedtls_snprintf( buf, buflen, "AES - Feature not available. For example, an unsupported AES key size" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 443 | if( use_ret == -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED) ) |
| 444 | mbedtls_snprintf( buf, buflen, "AES - AES hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 445 | #endif /* MBEDTLS_AES_C */ |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 446 | |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 447 | #if defined(MBEDTLS_ARC4_C) |
| 448 | if( use_ret == -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED) ) |
| 449 | mbedtls_snprintf( buf, buflen, "ARC4 - ARC4 hardware accelerator failed" ); |
| 450 | #endif /* MBEDTLS_ARC4_C */ |
| 451 | |
Markku-Juhani O. Saarinen | 07478d6 | 2017-12-01 16:20:15 +0000 | [diff] [blame] | 452 | #if defined(MBEDTLS_ARIA_C) |
Hanno Becker | 3214215 | 2018-12-17 13:25:58 +0000 | [diff] [blame] | 453 | if( use_ret == -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA) ) |
| 454 | mbedtls_snprintf( buf, buflen, "ARIA - Bad input data" ); |
Hanno Becker | a034369 | 2018-12-18 09:42:58 +0000 | [diff] [blame] | 455 | if( use_ret == -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH) ) |
| 456 | mbedtls_snprintf( buf, buflen, "ARIA - Invalid data input length" ); |
Manuel Pégourié-Gonnard | 3c80009 | 2018-03-01 09:02:16 +0100 | [diff] [blame] | 457 | if( use_ret == -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE) ) |
| 458 | mbedtls_snprintf( buf, buflen, "ARIA - Feature not available. For example, an unsupported ARIA key size" ); |
| 459 | if( use_ret == -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED) ) |
| 460 | mbedtls_snprintf( buf, buflen, "ARIA - ARIA hardware accelerator failed" ); |
Markku-Juhani O. Saarinen | 07478d6 | 2017-12-01 16:20:15 +0000 | [diff] [blame] | 461 | #endif /* MBEDTLS_ARIA_C */ |
| 462 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 463 | #if defined(MBEDTLS_ASN1_PARSE_C) |
| 464 | if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) ) |
| 465 | mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" ); |
| 466 | if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) ) |
| 467 | mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" ); |
| 468 | if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) ) |
| 469 | mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" ); |
| 470 | if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) ) |
| 471 | mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" ); |
| 472 | if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) ) |
Gilles Peskine | aac3853 | 2019-09-11 16:52:01 +0200 | [diff] [blame] | 473 | mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid" ); |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 474 | if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 475 | mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" ); |
| 476 | if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) ) |
| 477 | mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" ); |
| 478 | #endif /* MBEDTLS_ASN1_PARSE_C */ |
Paul Bakker | dceecd8 | 2011-11-15 16:38:34 +0000 | [diff] [blame] | 479 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 480 | #if defined(MBEDTLS_BASE64_C) |
| 481 | if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) ) |
| 482 | mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" ); |
| 483 | if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) ) |
| 484 | mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" ); |
| 485 | #endif /* MBEDTLS_BASE64_C */ |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 486 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 487 | #if defined(MBEDTLS_BIGNUM_C) |
| 488 | if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) ) |
| 489 | mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" ); |
| 490 | if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) ) |
| 491 | mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" ); |
| 492 | if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) ) |
| 493 | mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" ); |
| 494 | if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) ) |
| 495 | mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" ); |
| 496 | if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) ) |
| 497 | mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" ); |
| 498 | if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) ) |
| 499 | mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" ); |
| 500 | if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) ) |
| 501 | mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" ); |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 502 | if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 503 | mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" ); |
| 504 | #endif /* MBEDTLS_BIGNUM_C */ |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 505 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 506 | #if defined(MBEDTLS_BLOWFISH_C) |
Hanno Becker | 3214215 | 2018-12-17 13:25:58 +0000 | [diff] [blame] | 507 | if( use_ret == -(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA) ) |
| 508 | mbedtls_snprintf( buf, buflen, "BLOWFISH - Bad input data" ); |
Hanno Becker | 6640b0d | 2018-12-18 09:45:17 +0000 | [diff] [blame] | 509 | if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) ) |
| 510 | mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 511 | if( use_ret == -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED) ) |
| 512 | mbedtls_snprintf( buf, buflen, "BLOWFISH - Blowfish hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 513 | #endif /* MBEDTLS_BLOWFISH_C */ |
Paul Bakker | 83f00bb | 2012-07-04 11:08:50 +0000 | [diff] [blame] | 514 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 515 | #if defined(MBEDTLS_CAMELLIA_C) |
Hanno Becker | 3214215 | 2018-12-17 13:25:58 +0000 | [diff] [blame] | 516 | if( use_ret == -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA) ) |
| 517 | mbedtls_snprintf( buf, buflen, "CAMELLIA - Bad input data" ); |
Hanno Becker | 938f9e9 | 2018-12-18 09:40:25 +0000 | [diff] [blame] | 518 | if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) ) |
| 519 | mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 520 | if( use_ret == -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED) ) |
| 521 | mbedtls_snprintf( buf, buflen, "CAMELLIA - Camellia hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 522 | #endif /* MBEDTLS_CAMELLIA_C */ |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 523 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 524 | #if defined(MBEDTLS_CCM_C) |
| 525 | if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) ) |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 526 | mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to the function" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 527 | if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) ) |
| 528 | mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 529 | if( use_ret == -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED) ) |
| 530 | mbedtls_snprintf( buf, buflen, "CCM - CCM hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 531 | #endif /* MBEDTLS_CCM_C */ |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 532 | |
Daniel King | 34b822c | 2016-05-15 17:28:08 -0300 | [diff] [blame] | 533 | #if defined(MBEDTLS_CHACHA20_C) |
| 534 | if( use_ret == -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA) ) |
| 535 | mbedtls_snprintf( buf, buflen, "CHACHA20 - Invalid input parameter(s)" ); |
Manuel Pégourié-Gonnard | b8bd80a | 2018-05-09 09:54:51 +0200 | [diff] [blame] | 536 | if( use_ret == -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE) ) |
| 537 | mbedtls_snprintf( buf, buflen, "CHACHA20 - Feature not available. For example, s part of the API is not implemented" ); |
Manuel Pégourié-Gonnard | 3798b6b | 2018-05-24 13:27:45 +0200 | [diff] [blame] | 538 | if( use_ret == -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED) ) |
| 539 | mbedtls_snprintf( buf, buflen, "CHACHA20 - Chacha20 hardware accelerator failed" ); |
Daniel King | 34b822c | 2016-05-15 17:28:08 -0300 | [diff] [blame] | 540 | #endif /* MBEDTLS_CHACHA20_C */ |
| 541 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 542 | #if defined(MBEDTLS_CHACHAPOLY_C) |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 543 | if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE) ) |
| 544 | mbedtls_snprintf( buf, buflen, "CHACHAPOLY - The requested operation is not permitted in the current state" ); |
Manuel Pégourié-Gonnard | b8bd80a | 2018-05-09 09:54:51 +0200 | [diff] [blame] | 545 | if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED) ) |
| 546 | mbedtls_snprintf( buf, buflen, "CHACHAPOLY - Authenticated decryption failed: data was not authentic" ); |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 547 | #endif /* MBEDTLS_CHACHAPOLY_C */ |
| 548 | |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 549 | #if defined(MBEDTLS_CMAC_C) |
| 550 | if( use_ret == -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED) ) |
| 551 | mbedtls_snprintf( buf, buflen, "CMAC - CMAC hardware accelerator failed" ); |
| 552 | #endif /* MBEDTLS_CMAC_C */ |
| 553 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 554 | #if defined(MBEDTLS_CTR_DRBG_C) |
| 555 | if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) ) |
| 556 | mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" ); |
| 557 | if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) ) |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 558 | mbedtls_snprintf( buf, buflen, "CTR_DRBG - The requested random buffer length is too big" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 559 | if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) ) |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 560 | mbedtls_snprintf( buf, buflen, "CTR_DRBG - The input (entropy + additional data) is too large" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 561 | if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) ) |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 562 | mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read or write error in file" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 563 | #endif /* MBEDTLS_CTR_DRBG_C */ |
Paul Bakker | 880ac7e | 2011-11-27 14:50:49 +0000 | [diff] [blame] | 564 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 565 | #if defined(MBEDTLS_DES_C) |
| 566 | if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) ) |
| 567 | mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 568 | if( use_ret == -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED) ) |
| 569 | mbedtls_snprintf( buf, buflen, "DES - DES hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 570 | #endif /* MBEDTLS_DES_C */ |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 571 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 572 | #if defined(MBEDTLS_ENTROPY_C) |
| 573 | if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) ) |
| 574 | mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" ); |
| 575 | if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) ) |
| 576 | mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" ); |
| 577 | if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) ) |
| 578 | mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" ); |
Manuel Pégourié-Gonnard | f9cbd73 | 2015-06-22 12:06:50 +0200 | [diff] [blame] | 579 | if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) ) |
| 580 | mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 581 | if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) ) |
| 582 | mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" ); |
| 583 | #endif /* MBEDTLS_ENTROPY_C */ |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame] | 584 | |
Janos Follath | 60f6b64 | 2019-12-03 15:55:56 +0000 | [diff] [blame] | 585 | #if defined(MBEDTLS_ERROR_C) |
| 586 | if( use_ret == -(MBEDTLS_ERR_ERROR_GENERIC_ERROR) ) |
| 587 | mbedtls_snprintf( buf, buflen, "ERROR - Generic error" ); |
| 588 | if( use_ret == -(MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED) ) |
| 589 | mbedtls_snprintf( buf, buflen, "ERROR - This is a bug in the library" ); |
| 590 | #endif /* MBEDTLS_ERROR_C */ |
| 591 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 592 | #if defined(MBEDTLS_GCM_C) |
| 593 | if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) ) |
| 594 | mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 595 | if( use_ret == -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED) ) |
| 596 | mbedtls_snprintf( buf, buflen, "GCM - GCM hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 597 | if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) ) |
| 598 | mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" ); |
| 599 | #endif /* MBEDTLS_GCM_C */ |
Paul Bakker | 030277a | 2012-04-17 12:24:26 +0000 | [diff] [blame] | 600 | |
Thomas Fossati | 656864b | 2016-07-17 08:51:22 +0100 | [diff] [blame] | 601 | #if defined(MBEDTLS_HKDF_C) |
| 602 | if( use_ret == -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA) ) |
| 603 | mbedtls_snprintf( buf, buflen, "HKDF - Bad input parameters to function" ); |
| 604 | #endif /* MBEDTLS_HKDF_C */ |
| 605 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 606 | #if defined(MBEDTLS_HMAC_DRBG_C) |
| 607 | if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) ) |
| 608 | mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" ); |
| 609 | if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) ) |
| 610 | mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" ); |
| 611 | if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) ) |
| 612 | mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" ); |
| 613 | if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) ) |
| 614 | mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" ); |
| 615 | #endif /* MBEDTLS_HMAC_DRBG_C */ |
Manuel Pégourié-Gonnard | cf38367 | 2014-02-01 10:22:21 +0100 | [diff] [blame] | 616 | |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 617 | #if defined(MBEDTLS_MD2_C) |
| 618 | if( use_ret == -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED) ) |
| 619 | mbedtls_snprintf( buf, buflen, "MD2 - MD2 hardware accelerator failed" ); |
| 620 | #endif /* MBEDTLS_MD2_C */ |
| 621 | |
| 622 | #if defined(MBEDTLS_MD4_C) |
| 623 | if( use_ret == -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED) ) |
| 624 | mbedtls_snprintf( buf, buflen, "MD4 - MD4 hardware accelerator failed" ); |
| 625 | #endif /* MBEDTLS_MD4_C */ |
| 626 | |
| 627 | #if defined(MBEDTLS_MD5_C) |
| 628 | if( use_ret == -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED) ) |
| 629 | mbedtls_snprintf( buf, buflen, "MD5 - MD5 hardware accelerator failed" ); |
| 630 | #endif /* MBEDTLS_MD5_C */ |
| 631 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 632 | #if defined(MBEDTLS_OID_C) |
| 633 | if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) ) |
| 634 | mbedtls_snprintf( buf, buflen, "OID - OID is not found" ); |
| 635 | if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) ) |
| 636 | mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" ); |
| 637 | #endif /* MBEDTLS_OID_C */ |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 638 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 639 | #if defined(MBEDTLS_PADLOCK_C) |
| 640 | if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) ) |
| 641 | mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" ); |
| 642 | #endif /* MBEDTLS_PADLOCK_C */ |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 643 | |
Ron Eldor | 0ff4e0b | 2018-08-29 18:53:20 +0300 | [diff] [blame] | 644 | #if defined(MBEDTLS_PLATFORM_C) |
Ron Eldor | a27190b | 2018-10-15 16:33:43 +0300 | [diff] [blame] | 645 | if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED) ) |
Ron Eldor | 5267b62 | 2018-10-15 18:44:42 +0300 | [diff] [blame] | 646 | mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware accelerator failed" ); |
Ron Eldor | bcca58c | 2018-10-03 16:33:21 +0300 | [diff] [blame] | 647 | if( use_ret == -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) ) |
| 648 | mbedtls_snprintf( buf, buflen, "PLATFORM - The requested feature is not supported by the platform" ); |
Ron Eldor | 0ff4e0b | 2018-08-29 18:53:20 +0300 | [diff] [blame] | 649 | #endif /* MBEDTLS_PLATFORM_C */ |
| 650 | |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 651 | #if defined(MBEDTLS_POLY1305_C) |
| 652 | if( use_ret == -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA) ) |
| 653 | mbedtls_snprintf( buf, buflen, "POLY1305 - Invalid input parameter(s)" ); |
Manuel Pégourié-Gonnard | b8bd80a | 2018-05-09 09:54:51 +0200 | [diff] [blame] | 654 | if( use_ret == -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE) ) |
| 655 | mbedtls_snprintf( buf, buflen, "POLY1305 - Feature not available. For example, s part of the API is not implemented" ); |
Manuel Pégourié-Gonnard | 3798b6b | 2018-05-24 13:27:45 +0200 | [diff] [blame] | 656 | if( use_ret == -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED) ) |
| 657 | mbedtls_snprintf( buf, buflen, "POLY1305 - Poly1305 hardware accelerator failed" ); |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 658 | #endif /* MBEDTLS_POLY1305_C */ |
| 659 | |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 660 | #if defined(MBEDTLS_RIPEMD160_C) |
| 661 | if( use_ret == -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED) ) |
| 662 | mbedtls_snprintf( buf, buflen, "RIPEMD160 - RIPEMD160 hardware accelerator failed" ); |
| 663 | #endif /* MBEDTLS_RIPEMD160_C */ |
| 664 | |
| 665 | #if defined(MBEDTLS_SHA1_C) |
| 666 | if( use_ret == -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED) ) |
| 667 | mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 hardware accelerator failed" ); |
Andres Amaya Garcia | a685d4f | 2018-12-09 19:13:01 +0000 | [diff] [blame] | 668 | if( use_ret == -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA) ) |
Hanno Becker | 859522a | 2018-12-19 09:54:14 +0000 | [diff] [blame] | 669 | mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 input data was malformed" ); |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 670 | #endif /* MBEDTLS_SHA1_C */ |
| 671 | |
| 672 | #if defined(MBEDTLS_SHA256_C) |
| 673 | if( use_ret == -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED) ) |
| 674 | mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 hardware accelerator failed" ); |
Andres Amaya Garcia | 9e76c0e | 2018-12-09 20:42:05 +0000 | [diff] [blame] | 675 | if( use_ret == -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA) ) |
Hanno Becker | d8e4f4a | 2018-12-19 09:54:55 +0000 | [diff] [blame] | 676 | mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 input data was malformed" ); |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 677 | #endif /* MBEDTLS_SHA256_C */ |
| 678 | |
| 679 | #if defined(MBEDTLS_SHA512_C) |
| 680 | if( use_ret == -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED) ) |
| 681 | mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 hardware accelerator failed" ); |
Andres Amaya Garcia | 863d483 | 2018-12-09 20:58:52 +0000 | [diff] [blame] | 682 | if( use_ret == -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA) ) |
Hanno Becker | 9994e0d | 2018-12-19 09:55:40 +0000 | [diff] [blame] | 683 | mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 input data was malformed" ); |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 684 | #endif /* MBEDTLS_SHA512_C */ |
| 685 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 686 | #if defined(MBEDTLS_THREADING_C) |
| 687 | if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) ) |
| 688 | mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" ); |
| 689 | if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) ) |
| 690 | mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" ); |
| 691 | if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) ) |
| 692 | mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" ); |
| 693 | #endif /* MBEDTLS_THREADING_C */ |
Paul Bakker | 2466d93 | 2013-09-28 14:40:38 +0200 | [diff] [blame] | 694 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 695 | #if defined(MBEDTLS_XTEA_C) |
| 696 | if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) ) |
| 697 | mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" ); |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 698 | if( use_ret == -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED) ) |
| 699 | mbedtls_snprintf( buf, buflen, "XTEA - XTEA hardware accelerator failed" ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 700 | #endif /* MBEDTLS_XTEA_C */ |
Manuel Pégourié-Gonnard | fe671f4 | 2014-04-11 18:06:44 +0200 | [diff] [blame] | 701 | // END generated code |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 702 | |
| 703 | if( strlen( buf ) != 0 ) |
| 704 | return; |
| 705 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 706 | mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 709 | #else /* MBEDTLS_ERROR_C */ |
Paul Bakker | 8fe40dc | 2013-02-02 12:43:08 +0100 | [diff] [blame] | 710 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 711 | #if defined(MBEDTLS_ERROR_STRERROR_DUMMY) |
Paul Bakker | 8fe40dc | 2013-02-02 12:43:08 +0100 | [diff] [blame] | 712 | |
Paul Bakker | 8fe40dc | 2013-02-02 12:43:08 +0100 | [diff] [blame] | 713 | /* |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 714 | * Provide an non-function in case MBEDTLS_ERROR_C is not defined |
Paul Bakker | 8fe40dc | 2013-02-02 12:43:08 +0100 | [diff] [blame] | 715 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 716 | void mbedtls_strerror( int ret, char *buf, size_t buflen ) |
Paul Bakker | 8fe40dc | 2013-02-02 12:43:08 +0100 | [diff] [blame] | 717 | { |
| 718 | ((void) ret); |
| 719 | |
| 720 | if( buflen > 0 ) |
| 721 | buf[0] = '\0'; |
| 722 | } |
| 723 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 724 | #endif /* MBEDTLS_ERROR_STRERROR_DUMMY */ |
Paul Bakker | e2ab84f | 2013-06-29 18:24:32 +0200 | [diff] [blame] | 725 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 726 | #endif /* MBEDTLS_ERROR_C */ |