1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 *
4 * LibTomCrypt is a library that provides various cryptographic
5 * algorithms in a highly modular and flexible manner.
6 *
7 * The library is free for all purposes without any express
8 * guarantee it works.
9 */
10
11 #include "tomcrypt_private.h"
12
13 /**
14 @file error_to_string.c
15 Convert error codes to ASCII strings, Tom St Denis
16 */
17
18 static const char * const err_2_str[] =
19 {
20 "CRYPT_OK",
21 "CRYPT_ERROR",
22 "Non-fatal 'no-operation' requested.",
23
24 "Invalid key size.",
25 "Invalid number of rounds for block cipher.",
26 "Algorithm failed test vectors.",
27
28 "Buffer overflow.",
29 "Invalid input packet.",
30
31 "Invalid number of bits for a PRNG.",
32 "Error reading the PRNG.",
33
34 "Invalid cipher specified.",
35 "Invalid hash specified.",
36 "Invalid PRNG specified.",
37
38 "Out of memory.",
39
40 "Invalid PK key or key type specified for function.",
41 "A private PK key is required.",
42
43 "Invalid argument provided.",
44 "File Not Found",
45
46 "Invalid PK type.",
47
48 "An overflow of a value was detected/prevented.",
49
50 "An ASN.1 decoding error occurred.",
51
52 "The input was longer than expected.",
53
54 "Invalid sized parameter.",
55
56 "Invalid size for prime.",
57
58 "Invalid padding.",
59
60 "Hash applied to too many bits.",
61 };
62
63 /**
64 Convert an LTC error code to ASCII
65 @param err The error code
66 @return A pointer to the ASCII NUL terminated string for the error or "Invalid error code." if the err code was not valid.
67 */
error_to_string(int err)68 const char *error_to_string(int err)
69 {
70 if (err < 0 || err >= (int)(sizeof(err_2_str)/sizeof(err_2_str[0]))) {
71 return "Invalid error code.";
72 }
73 return err_2_str[err];
74 }
75
76
77 /* ref: $Format:%D$ */
78 /* git commit: $Format:%H$ */
79 /* commit time: $Format:%ai$ */
80