Skip to content

Commit 65e05bf

Browse files
committed
Update docs
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 9579022 commit 65e05bf

File tree

9 files changed

+269
-70
lines changed

9 files changed

+269
-70
lines changed

.ci/meta_builds.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ fi
2222
function run_gcc() {
2323
bash .ci/check_source.sh "CHECK_SOURCES" "$2" "$3" "$4" "$5"
2424

25+
make -j$(nproc) pem-info V=0
26+
27+
echo "verify docs..."
28+
while read -r line; do
29+
grep -q -e "$line" doc/crypt.tex || { echo "Failed to find \"$line\" in doc/crypt.tex"; exit 1; }
30+
done < <(./pem-info | grep '^\\' | sed 's@\\@\\\\@g')
31+
echo "docs OK"
32+
2533
make clean &>/dev/null
2634

2735
echo

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ openssl-enc
3636
openssl-enc.exe
3737
openssh-privkey
3838
openssh-privkey.exe
39+
pem-info
40+
pem-info.exe
3941
sizes
4042
sizes.exe
4143
small

demos/pem-info.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

Comments
 (0)