pem-info.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_cfb1, "CFB1", },
  48. { cm_cfb8, "CFB8", },
  49. { cm_ctr, "CTR", },
  50. { cm_ofb, "OFB", },
  51. { cm_stream, "STREAM", },
  52. { cm_gcm, "GCM", },
  53. };
  54. static const char *s_map_mode(enum cipher_mode mode)
  55. {
  56. size_t n;
  57. mode &= cm_modes | cm_1bit | cm_8bit;
  58. for (n = 0; n < sizeof(cipher_mode_map)/sizeof(cipher_mode_map[0]); ++n) {
  59. if (cipher_mode_map[n].mode == mode)
  60. return cipher_mode_map[n].name;
  61. }
  62. fprintf(stderr, "Error: Can't map cipher_mode %d\n", mode);
  63. exit(1);
  64. }
  65. int main(void)
  66. {
  67. unsigned long n;
  68. printf("PEM ciphers:\n\n");
  69. for (n = 0; n < pem_dek_infos_num; ++n) {
  70. char nbuf[32] = {0};
  71. size_t nlen = strlen(pem_dek_infos[n].name);
  72. memcpy(nbuf, pem_dek_infos[n].name, nlen);
  73. nbuf[nlen-1] = '}';
  74. printf("\\hline \\texttt{%-18s & %-15s & %-25ld & %-6s \\\\\n",
  75. nbuf, s_map_cipher(pem_dek_infos[n].algo),
  76. pem_dek_infos[n].keylen * 8,
  77. s_map_mode(pem_dek_infos[n].mode));
  78. }
  79. printf("\nSSH ciphers:\n\n");
  80. for (n = 0; n < ssh_ciphers_num; ++n) {
  81. char nbuf[32] = {0};
  82. size_t nlen = strlen(ssh_ciphers[n].name);
  83. memcpy(nbuf, ssh_ciphers[n].name, nlen);
  84. nbuf[nlen] = '}';
  85. printf("\\hline \\texttt{%-30s & %-16s & %-24ld & %-6s \\\\\n",
  86. nbuf, s_map_cipher(ssh_ciphers[n].algo),
  87. ssh_ciphers[n].keylen * 8,
  88. s_map_mode(ssh_ciphers[n].mode));
  89. }
  90. return 0;
  91. }
  92. #else
  93. int main(void) { return EXIT_FAILURE; }
  94. #endif