Mercurial > dropbear
comparison strings.c @ 0:d7da3b1e1540 libtomcrypt
put back the 0.95 makefile which was inadvertently merged over
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 31 May 2004 18:21:40 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d7da3b1e1540 |
---|---|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
2 * | |
3 * LibTomCrypt is a library that provides various cryptographic | |
4 * algorithms in a highly modular and flexible manner. | |
5 * | |
6 * The library is free for all purposes without any express | |
7 * guarantee it works. | |
8 * | |
9 * Tom St Denis, [email protected], http://libtomcrypt.org | |
10 */ | |
11 | |
12 /* Future releases will make use of this */ | |
13 #include "mycrypt.h" | |
14 | |
15 static const char *err_2_str[] = | |
16 { | |
17 "CRYPT_OK", | |
18 "CRYPT_ERROR", | |
19 "Non-fatal 'no-operation' requested.", | |
20 | |
21 "Invalid keysize for block cipher.", | |
22 "Invalid number of rounds for block cipher.", | |
23 "Algorithm failed test vectors.", | |
24 | |
25 "Buffer overflow.", | |
26 "Invalid input packet.", | |
27 | |
28 "Invalid number of bits for a PRNG.", | |
29 "Error reading the PRNG.", | |
30 | |
31 "Invalid cipher specified.", | |
32 "Invalid hash specified.", | |
33 "Invalid PRNG specified.", | |
34 | |
35 "Out of memory.", | |
36 | |
37 "Invalid PK key or key type specified for function.", | |
38 "A private PK key is required.", | |
39 | |
40 "Invalid argument provided.", | |
41 "File Not Found", | |
42 | |
43 "Invalid PK type.", | |
44 "Invalid PK system.", | |
45 "Duplicate PK key found on keyring.", | |
46 "Key not found in keyring.", | |
47 "Invalid sized parameter.", | |
48 | |
49 "Invalid size for prime.", | |
50 | |
51 }; | |
52 | |
53 #ifdef MPI | |
54 static const struct { | |
55 int mpi_code, ltc_code; | |
56 } mpi_to_ltc_codes[] = { | |
57 { MP_OKAY , CRYPT_OK}, | |
58 { MP_MEM , CRYPT_MEM}, | |
59 { MP_VAL , CRYPT_INVALID_ARG}, | |
60 }; | |
61 #endif | |
62 | |
63 const char *error_to_string(int err) | |
64 { | |
65 if (err < 0 || err >= (int)(sizeof(err_2_str)/sizeof(err_2_str[0]))) { | |
66 return "Invalid error code."; | |
67 } else { | |
68 return err_2_str[err]; | |
69 } | |
70 } | |
71 | |
72 #ifdef MPI | |
73 /* convert a MPI error to a LTC error (Possibly the most powerful function ever! Oh wait... no) */ | |
74 int mpi_to_ltc_error(int err) | |
75 { | |
76 int x; | |
77 | |
78 for (x = 0; x < (int)(sizeof(mpi_to_ltc_codes)/sizeof(mpi_to_ltc_codes[0])); x++) { | |
79 if (err == mpi_to_ltc_codes[x].mpi_code) { | |
80 return mpi_to_ltc_codes[x].ltc_code; | |
81 } | |
82 } | |
83 return CRYPT_ERROR; | |
84 } | |
85 #endif | |
86 |