Skip to content

Commit 0d8f369

Browse files
committed
Create table of supported ECC curves programmatically
Related to #349 Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent ef325de commit 0d8f369

File tree

8 files changed

+119
-45
lines changed

8 files changed

+119
-45
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ openssl-enc
4242
openssl-enc.exe
4343
openssh-privkey
4444
openssh-privkey.exe
45-
pem-info
46-
pem-info.exe
45+
latex-tables
46+
latex-tables.exe
4747
sizes
4848
sizes.exe
4949
small

demos/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
option(BUILD_USEFUL_DEMOS "Build useful demos (hashsum)" FALSE)
55
option(
66
BUILD_USABLE_DEMOS
7-
"Build usable demos (aesgcm constants crypt openssh-privkey openssl-enc pem-info sizes timing)"
7+
"Build usable demos (aesgcm constants crypt openssh-privkey openssl-enc latex-tables sizes timing)"
88
FALSE
99
)
1010
option(BUILD_TEST_DEMOS "Build test demos (small tv_gen)" FALSE)
@@ -28,7 +28,7 @@ endif()
2828
#
2929
# Demos that are usable but only rarely make sense to be installed
3030
#
31-
# USEABLE_DEMOS = aesgcm constants crypt der_print_flexi openssh-privkey openssl-enc pem-info sizes timing
31+
# USEABLE_DEMOS = aesgcm constants crypt der_print_flexi latex-tables openssh-privkey openssl-enc sizes timing
3232
# -----------------------------------------------------------------------------
3333

3434
if(BUILD_USABLE_DEMOS)
@@ -39,9 +39,9 @@ if(BUILD_USABLE_DEMOS)
3939
constants
4040
crypt
4141
der_print_flexi
42+
latex-tables
4243
openssh-privkey
4344
openssl-enc
44-
pem-info
4545
sizes
4646
timing
4747
)

demos/pem-info.c renamed to demos/latex-tables.c

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,26 @@ static void LTC_NORETURN die(int status)
7474
{
7575
FILE* o = status == EXIT_SUCCESS ? stdout : stderr;
7676
fprintf(o,
77-
"Usage: pem-info [<-h>]\n\n"
78-
"Generate LaTeX tables from the supported PEM resp. SSH ciphers.\n\n"
77+
"Usage: latex-tables [<-h>]\n\n"
78+
"Generate LaTeX tables from some library internal data.\n\n"
7979
"\t-h\tThe help you're looking at.\n"
8080
);
8181
exit(status);
8282
}
8383

84+
static int s_to_lower(const char *in, char *out, unsigned long *outlen)
85+
{
86+
unsigned long n;
87+
for (n = 0; n < *outlen && in[n]; ++n) {
88+
out[n] = tolower(in[n]);
89+
}
90+
if (n == *outlen)
91+
return CRYPT_BUFFER_OVERFLOW;
92+
out[n] = '\0';
93+
*outlen = n;
94+
return CRYPT_OK;
95+
}
96+
8497
int main(int argc, char **argv)
8598
{
8699
unsigned long n;
@@ -110,6 +123,50 @@ int main(int argc, char **argv)
110123
s_map_mode(ssh_ciphers[n].mode));
111124
}
112125

126+
printf("\nECC curves:\n\n");
127+
for (n = 0; ltc_ecc_curves[n].OID != NULL; ++n) {
128+
const char * const *names;
129+
char lower[32] = {0}, buf[64] = {0};
130+
unsigned long m, bufl = 0, lowerl;
131+
int err = ecc_get_curve_names(ltc_ecc_curves[n].OID, &names);
132+
if (err != CRYPT_OK) {
133+
printf("\\error: OID %s not found (%s)\n", ltc_ecc_curves[n].OID, error_to_string(err));
134+
return EXIT_FAILURE;
135+
}
136+
for (m = 1; names[m]; ++m) {
137+
const char *name = names[m];
138+
if (memcmp(name, "P-", 2) == 0 || memcmp(name, "ECC-", 4) == 0) {
139+
/* Use the original name */
140+
} else {
141+
lowerl = sizeof(lower);
142+
if ((err = s_to_lower(name, lower, &lowerl)) != CRYPT_OK) {
143+
printf("\\error: %s could not be converted to lowercase (%s)\n", name, error_to_string(err));
144+
return EXIT_FAILURE;
145+
}
146+
name = lower;
147+
}
148+
if (m == 1) {
149+
err = snprintf(buf + bufl, sizeof(buf) - bufl, "%s", name);
150+
} else {
151+
err = snprintf(buf + bufl, sizeof(buf) - bufl, ", %s", name);
152+
}
153+
if (err == -1 || (unsigned)err > sizeof(buf) - bufl) {
154+
printf("\\error: snprintf returned %d at %s\n", err, name);
155+
return EXIT_FAILURE;
156+
}
157+
bufl += err;
158+
}
159+
lower[0] = '{';
160+
lowerl = sizeof(lower) - 2;
161+
if ((err = s_to_lower(names[0], &lower[1], &lowerl)) != CRYPT_OK) {
162+
printf("\\error: %s could not be converted to lowercase (%s)\n", names[0], error_to_string(err));
163+
return EXIT_FAILURE;
164+
}
165+
lower[lowerl + 1] = '}';
166+
lower[lowerl + 2] = '\0';
167+
printf("\\hline \\texttt%-17s & %-36s & %-21s \\\\\n", lower, buf, ltc_ecc_curves[n].OID);
168+
}
169+
113170
return 0;
114171
}
115172
#else

doc/crypt.tex

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5331,42 +5331,42 @@ \chapter{Elliptic Curve Cryptography - $GF(p)$}
53315331
\begin{table}[H]
53325332
\begin{center}
53335333
\begin{tabular}{|l|l|l|l|}
5334-
\hline \textbf{Curve Name} & \textbf{Alternative Names} & \textbf{OID} \\
5335-
\hline secp112r1 & & 1.3.132.0.6 \\
5336-
\hline secp112r2 & & 1.3.132.0.7 \\
5337-
\hline secp128r1 & & 1.3.132.0.28 \\
5338-
\hline secp128r2 & & 1.3.132.0.29 \\
5339-
\hline secp160r1 & & 1.3.132.0.8 \\
5340-
\hline secp160r2 & & 1.3.132.0.30 \\
5341-
\hline secp160k1 & & 1.3.132.0.9 \\
5342-
\hline secp192r1 & nistp192, prime192v1, P-192 & 1.2.840.10045.3.1.1 \\
5343-
\hline prime192v2 & & 1.2.840.10045.3.1.2 \\
5344-
\hline prime192v3 & & 1.2.840.10045.3.1.3 \\
5345-
\hline secp192k1 & & 1.3.132.0.31 \\
5346-
\hline secp224r1 & nistp224, P-224 & 1.3.132.0.33 \\
5347-
\hline secp224k1 & & 1.3.132.0.32 \\
5348-
\hline secp256r1 & nistp256, prime256v1, P-256 & 1.2.840.10045.3.1.7 \\
5349-
\hline secp256k1 & & 1.3.132.0.10 \\
5350-
\hline secp384r1 & nistp384, P-384 & 1.3.132.0.34 \\
5351-
\hline secp521r1 & nistp521, P-521 & 1.3.132.0.35 \\
5352-
\hline prime239v1 & & 1.2.840.10045.3.1.4 \\
5353-
\hline prime239v2 & & 1.2.840.10045.3.1.5 \\
5354-
\hline prime239v3 & & 1.2.840.10045.3.1.6 \\
5355-
\hline brainpoolP160r1 & & 1.3.36.3.3.2.8.1.1.1 \\
5356-
\hline brainpoolP192r1 & & 1.3.36.3.3.2.8.1.1.3 \\
5357-
\hline brainpoolP224r1 & & 1.3.36.3.3.2.8.1.1.5 \\
5358-
\hline brainpoolP256r1 & & 1.3.36.3.3.2.8.1.1.7 \\
5359-
\hline brainpoolP320r1 & & 1.3.36.3.3.2.8.1.1.9 \\
5360-
\hline brainpoolP384r1 & & 1.3.36.3.3.2.8.1.1.11 \\
5361-
\hline brainpoolP512r1 & & 1.3.36.3.3.2.8.1.1.13 \\
5362-
\hline brainpoolP160t1 & & 1.3.36.3.3.2.8.1.1.2 \\
5363-
\hline brainpoolP192t1 & & 1.3.36.3.3.2.8.1.1.4 \\
5364-
\hline brainpoolP224t1 & & 1.3.36.3.3.2.8.1.1.6 \\
5365-
\hline brainpoolP256t1 & & 1.3.36.3.3.2.8.1.1.8 \\
5366-
\hline brainpoolP320t1 & & 1.3.36.3.3.2.8.1.1.10 \\
5367-
\hline brainpoolP384t1 & & 1.3.36.3.3.2.8.1.1.12 \\
5368-
\hline brainpoolP512t1 & & 1.3.36.3.3.2.8.1.1.14 \\
5369-
\hline
5334+
\hline \textbf{Curve Name} & \textbf{Alternative Names} & \textbf{OID} \\
5335+
\hline \texttt{secp112r1} & ECC-112 & 1.3.132.0.6 \\
5336+
\hline \texttt{secp112r2} & & 1.3.132.0.7 \\
5337+
\hline \texttt{secp128r1} & ECC-128 & 1.3.132.0.28 \\
5338+
\hline \texttt{secp128r2} & & 1.3.132.0.29 \\
5339+
\hline \texttt{secp160r1} & ECC-160 & 1.3.132.0.8 \\
5340+
\hline \texttt{secp160r2} & & 1.3.132.0.30 \\
5341+
\hline \texttt{secp160k1} & & 1.3.132.0.9 \\
5342+
\hline \texttt{secp192r1} & nistp192, prime192v1, ECC-192, P-192 & 1.2.840.10045.3.1.1 \\
5343+
\hline \texttt{prime192v2} & & 1.2.840.10045.3.1.2 \\
5344+
\hline \texttt{prime192v3} & & 1.2.840.10045.3.1.3 \\
5345+
\hline \texttt{secp192k1} & & 1.3.132.0.31 \\
5346+
\hline \texttt{secp224r1} & nistp224, ECC-224, P-224 & 1.3.132.0.33 \\
5347+
\hline \texttt{secp224k1} & & 1.3.132.0.32 \\
5348+
\hline \texttt{secp256r1} & nistp256, prime256v1, ECC-256, P-256 & 1.2.840.10045.3.1.7 \\
5349+
\hline \texttt{secp256k1} & & 1.3.132.0.10 \\
5350+
\hline \texttt{secp384r1} & nistp384, ECC-384, P-384 & 1.3.132.0.34 \\
5351+
\hline \texttt{secp521r1} & nistp521, ECC-521, P-521 & 1.3.132.0.35 \\
5352+
\hline \texttt{prime239v1} & & 1.2.840.10045.3.1.4 \\
5353+
\hline \texttt{prime239v2} & & 1.2.840.10045.3.1.5 \\
5354+
\hline \texttt{prime239v3} & & 1.2.840.10045.3.1.6 \\
5355+
\hline \texttt{brainpoolp160r1} & & 1.3.36.3.3.2.8.1.1.1 \\
5356+
\hline \texttt{brainpoolp192r1} & & 1.3.36.3.3.2.8.1.1.3 \\
5357+
\hline \texttt{brainpoolp224r1} & & 1.3.36.3.3.2.8.1.1.5 \\
5358+
\hline \texttt{brainpoolp256r1} & & 1.3.36.3.3.2.8.1.1.7 \\
5359+
\hline \texttt{brainpoolp320r1} & & 1.3.36.3.3.2.8.1.1.9 \\
5360+
\hline \texttt{brainpoolp384r1} & & 1.3.36.3.3.2.8.1.1.11 \\
5361+
\hline \texttt{brainpoolp512r1} & & 1.3.36.3.3.2.8.1.1.13 \\
5362+
\hline \texttt{brainpoolp160t1} & & 1.3.36.3.3.2.8.1.1.2 \\
5363+
\hline \texttt{brainpoolp192t1} & & 1.3.36.3.3.2.8.1.1.4 \\
5364+
\hline \texttt{brainpoolp224t1} & & 1.3.36.3.3.2.8.1.1.6 \\
5365+
\hline \texttt{brainpoolp256t1} & & 1.3.36.3.3.2.8.1.1.8 \\
5366+
\hline \texttt{brainpoolp320t1} & & 1.3.36.3.3.2.8.1.1.10 \\
5367+
\hline \texttt{brainpoolp384t1} & & 1.3.36.3.3.2.8.1.1.12 \\
5368+
\hline \texttt{brainpoolp512t1} & & 1.3.36.3.3.2.8.1.1.14 \\
5369+
\hline
53705370
\end{tabular}
53715371
\caption{Built--In Elliptic Curves over GF(p)}
53725372
\end{center}

makefile_include.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ TEST=test
174174
USEFUL_DEMOS = hashsum
175175

176176
# Demos that are usable but only rarely make sense to be installed
177-
USEABLE_DEMOS = aesgcm constants crypt der_print_flexi openssh-privkey openssl-enc pem-info sizes timing
177+
USEABLE_DEMOS = aesgcm constants crypt der_print_flexi latex-tables openssh-privkey openssl-enc sizes timing
178178

179179
# Demos that are used for testing or measuring
180180
TEST_DEMOS = small tv_gen

src/headers/tomcrypt_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ int dh_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, dh_key
465465
int ecc_set_curve_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key);
466466
int ecc_copy_curve(const ecc_key *srckey, ecc_key *key);
467467
int ecc_set_curve_by_size(int size, ecc_key *key);
468+
int ecc_get_curve_names(const char *oid, const char * const **names);
468469
int ecc_import_subject_public_key_info(const unsigned char *in, unsigned long inlen, ecc_key *key);
469470
#ifdef LTC_DER
470471
int ecc_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, ecc_key *key);

src/misc/pem/pem_ssh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const struct blockcipher_info ssh_ciphers[] =
2828
{ .name = "aes256-gcm@openssh.com", .algo = "aes", .keylen = 256 / 8, .mode = cm_gcm },
2929
{ .name = "blowfish128-cbc", .algo = "blowfish", .keylen = 128 / 8, .mode = cm_cbc },
3030
{ .name = "blowfish128-ctr", .algo = "blowfish", .keylen = 128 / 8, .mode = cm_ctr },
31-
/* The algo name doesn't matter, it's only used in pem-info */
31+
/* The algo name doesn't matter, it's only used in latex-tables */
3232
{ .name = "chacha20-poly1305@openssh.com", .algo = "c20p1305", .keylen = 256 / 8, .mode = cm_stream | cm_openssh },
3333
{ .name = "des-cbc", .algo = "des", .keylen = 64 / 8, .mode = cm_cbc },
3434
{ .name = "3des-cbc", .algo = "3des", .keylen = 192 / 8, .mode = cm_cbc },

src/pk/ecc/ecc_find_curve.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,22 @@ static int s_name_match(const char *left, const char *right)
206206
return 0;
207207
}
208208

209+
int ecc_get_curve_names(const char *oid, const char * const **names)
210+
{
211+
unsigned long i;
212+
213+
LTC_ARGCHK(oid != NULL);
214+
LTC_ARGCHK(names != NULL);
215+
216+
for (i = 0; s_curve_names[i].OID != NULL; ++i) {
217+
if (XSTRCMP(s_curve_names[i].OID, oid) == 0) {
218+
*names = s_curve_names[i].names;
219+
return CRYPT_OK;
220+
}
221+
}
222+
return CRYPT_INVALID_ARG; /* not found */
223+
}
224+
209225
int ecc_find_curve(const char *name_or_oid, const ltc_ecc_curve **cu)
210226
{
211227
int i, j;

0 commit comments

Comments
 (0)