|
| 1 | +/* LibTomCrypt, modular cryptographic library -- Tom St Denis */ |
| 2 | +/* SPDX-License-Identifier: Unlicense */ |
| 3 | +/* print all PEM related infos */ |
| 4 | +#include "tomcrypt_private.h" |
| 5 | + |
| 6 | +#if defined(LTC_PEM_SSH) |
| 7 | +extern const struct blockcipher_info pem_dek_infos[]; |
| 8 | +extern const unsigned long pem_dek_infos_num; |
| 9 | + |
| 10 | +extern const struct blockcipher_info ssh_ciphers[]; |
| 11 | +extern const unsigned long ssh_ciphers_num; |
| 12 | + |
| 13 | +static const struct { |
| 14 | + const char *is, *should; |
| 15 | +} cipher_name_map[] = { |
| 16 | + { "", "none" }, |
| 17 | + { "aes", "AES" }, |
| 18 | + { "blowfish", "Blowfish" }, |
| 19 | + { "camellia", "Camellia" }, |
| 20 | + { "cast5", "CAST5" }, |
| 21 | + { "3des", "3DES (EDE)" }, |
| 22 | + { "des", "DES" }, |
| 23 | + { "idea", "IDEA" }, |
| 24 | + { "rc5", "RC5" }, |
| 25 | + { "rc2", "RC2" }, |
| 26 | + { "seed", "SEED" }, |
| 27 | + { "serpent", "Serpent" }, |
| 28 | + { "twofish", "Twofish" }, |
| 29 | +}; |
| 30 | + |
| 31 | +static const char *s_map_cipher(const char *name) |
| 32 | +{ |
| 33 | + unsigned long n; |
| 34 | + for (n = 0; n < sizeof(cipher_name_map)/sizeof(cipher_name_map[0]); ++n) { |
| 35 | + if (strcmp(name, cipher_name_map[n].is) == 0) |
| 36 | + return cipher_name_map[n].should; |
| 37 | + } |
| 38 | + fprintf(stderr, "Error: Can't map %s\n", name); |
| 39 | + exit(1); |
| 40 | +} |
| 41 | + |
| 42 | +static const char *cipher_mode_map[] = { |
| 43 | + "none", "CBC", "CFB", "CTR", "OFB", "STREAM", "GCM" |
| 44 | +}; |
| 45 | + |
| 46 | +static const char *s_map_mode(enum cipher_mode mode) |
| 47 | +{ |
| 48 | + if (mode >= 0 && mode <= sizeof(cipher_mode_map)/sizeof(cipher_mode_map[0])) |
| 49 | + return cipher_mode_map[mode]; |
| 50 | + fprintf(stderr, "Error: Can't map cipher_mode %d\n", mode); |
| 51 | + exit(1); |
| 52 | +} |
| 53 | + |
| 54 | +int main(void) |
| 55 | +{ |
| 56 | + unsigned long n; |
| 57 | + printf("PEM ciphers:\n\n"); |
| 58 | + for (n = 0; n < pem_dek_infos_num; ++n) { |
| 59 | + char nbuf[20] = {0}; |
| 60 | + size_t nlen = strlen(pem_dek_infos[n].name); |
| 61 | + memcpy(nbuf, pem_dek_infos[n].name, nlen); |
| 62 | + nbuf[nlen-1] = '}'; |
| 63 | + printf("\\hline \\texttt{%-18s & %-15s & %-25ld & %s \\\\\n", |
| 64 | + nbuf, s_map_cipher(pem_dek_infos[n].algo), |
| 65 | + pem_dek_infos[n].keylen * 8, |
| 66 | + s_map_mode(pem_dek_infos[n].mode)); |
| 67 | + } |
| 68 | + |
| 69 | + printf("\nSSH ciphers:\n\n"); |
| 70 | + for (n = 0; n < ssh_ciphers_num; ++n) { |
| 71 | + char nbuf[20] = {0}; |
| 72 | + size_t nlen = strlen(ssh_ciphers[n].name); |
| 73 | + memcpy(nbuf, ssh_ciphers[n].name, nlen); |
| 74 | + nbuf[nlen] = '}'; |
| 75 | + printf("\\hline \\texttt{%-18s & %-15s & %-25ld & %-4s \\\\\n", |
| 76 | + nbuf, s_map_cipher(ssh_ciphers[n].algo), |
| 77 | + ssh_ciphers[n].keylen * 8, |
| 78 | + s_map_mode(ssh_ciphers[n].mode)); |
| 79 | + } |
| 80 | + |
| 81 | + return 0; |
| 82 | +} |
| 83 | +#else |
| 84 | +int main(void) { return EXIT_FAILURE; } |
| 85 | +#endif |
0 commit comments