pem-info.c 2.9 KB

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