|
| 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 | + { "c20p1305", "ChaCha20Poly1305" }, |
| 20 | + { "camellia", "Camellia" }, |
| 21 | + { "cast5", "CAST5" }, |
| 22 | + { "chacha20", "ChaCha20" }, |
| 23 | + { "3des", "3DES (EDE)" }, |
| 24 | + { "des", "DES" }, |
| 25 | + { "desx", "DES-X" }, |
| 26 | + { "idea", "IDEA" }, |
| 27 | + { "rc5", "RC5" }, |
| 28 | + { "rc2", "RC2" }, |
| 29 | + { "seed", "SEED" }, |
| 30 | + { "serpent", "Serpent" }, |
| 31 | + { "twofish", "Twofish" }, |
| 32 | +}; |
| 33 | + |
| 34 | +static const char *s_map_cipher(const char *name) |
| 35 | +{ |
| 36 | + unsigned long n; |
| 37 | + for (n = 0; n < sizeof(cipher_name_map)/sizeof(cipher_name_map[0]); ++n) { |
| 38 | + if (strcmp(name, cipher_name_map[n].is) == 0) |
| 39 | + return cipher_name_map[n].should; |
| 40 | + } |
| 41 | + fprintf(stderr, "Error: Can't map %s\n", name); |
| 42 | + exit(1); |
| 43 | +} |
| 44 | + |
| 45 | +static const struct { |
| 46 | + enum cipher_mode mode; |
| 47 | + const char *name; |
| 48 | +} cipher_mode_map[] = { |
| 49 | + { cm_none, "none", }, |
| 50 | + { cm_cbc, "CBC", }, |
| 51 | + { cm_cfb, "CFB", }, |
| 52 | + { cm_ctr, "CTR", }, |
| 53 | + { cm_ofb, "OFB", }, |
| 54 | + { cm_stream, "STREAM", }, |
| 55 | + { cm_gcm, "GCM", }, |
| 56 | +}; |
| 57 | + |
| 58 | +static const char *s_map_mode(enum cipher_mode mode) |
| 59 | +{ |
| 60 | + size_t n; |
| 61 | + mode &= cm_modes; |
| 62 | + for (n = 0; n < sizeof(cipher_mode_map)/sizeof(cipher_mode_map[0]); ++n) { |
| 63 | + if (cipher_mode_map[n].mode == mode) |
| 64 | + return cipher_mode_map[n].name; |
| 65 | + } |
| 66 | + fprintf(stderr, "Error: Can't map cipher_mode %d\n", mode); |
| 67 | + exit(1); |
| 68 | +} |
| 69 | + |
| 70 | +int main(void) |
| 71 | +{ |
| 72 | + unsigned long n; |
| 73 | + printf("PEM ciphers:\n\n"); |
| 74 | + for (n = 0; n < pem_dek_infos_num; ++n) { |
| 75 | + char nbuf[32] = {0}; |
| 76 | + size_t nlen = strlen(pem_dek_infos[n].name); |
| 77 | + memcpy(nbuf, pem_dek_infos[n].name, nlen); |
| 78 | + nbuf[nlen-1] = '}'; |
| 79 | + printf("\\hline \\texttt{%-18s & %-15s & %-25ld & %-6s \\\\\n", |
| 80 | + nbuf, s_map_cipher(pem_dek_infos[n].algo), |
| 81 | + pem_dek_infos[n].keylen * 8, |
| 82 | + s_map_mode(pem_dek_infos[n].mode)); |
| 83 | + } |
| 84 | + |
| 85 | + printf("\nSSH ciphers:\n\n"); |
| 86 | + for (n = 0; n < ssh_ciphers_num; ++n) { |
| 87 | + char nbuf[32] = {0}; |
| 88 | + size_t nlen = strlen(ssh_ciphers[n].name); |
| 89 | + memcpy(nbuf, ssh_ciphers[n].name, nlen); |
| 90 | + nbuf[nlen] = '}'; |
| 91 | + printf("\\hline \\texttt{%-30s & %-16s & %-24ld & %-6s \\\\\n", |
| 92 | + nbuf, s_map_cipher(ssh_ciphers[n].algo), |
| 93 | + ssh_ciphers[n].keylen * 8, |
| 94 | + s_map_mode(ssh_ciphers[n].mode)); |
| 95 | + } |
| 96 | + |
| 97 | + return 0; |
| 98 | +} |
| 99 | +#else |
| 100 | +int main(void) { return EXIT_FAILURE; } |
| 101 | +#endif |
0 commit comments