summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-05-01 07:54:08 +0000
committertb <>2023-05-01 07:54:08 +0000
commite403ec38092a02f61a4eec978529d0616b55ff00 (patch)
tree0962f0807e388b282b353e814fae1086e8689d79
parent9d1114dce6ed12953dcd612e5aec50f9607b882b (diff)
downloadopenbsd-e403ec38092a02f61a4eec978529d0616b55ff00.tar.gz
openbsd-e403ec38092a02f61a4eec978529d0616b55ff00.tar.bz2
openbsd-e403ec38092a02f61a4eec978529d0616b55ff00.zip
Clean up handling of nist_curves[]
There's no point in introducing a typedef only for two sizeof() calls. We might as well use an anonymous struct for this list. Make it const while there, drop some braces and compare strcmp() return value to 0. ok jsing
-rw-r--r--src/lib/libcrypto/ec/ec_curve.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/lib/libcrypto/ec/ec_curve.c b/src/lib/libcrypto/ec/ec_curve.c
index 898e233429..56959941f8 100644
--- a/src/lib/libcrypto/ec/ec_curve.c
+++ b/src/lib/libcrypto/ec/ec_curve.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_curve.c,v 1.27 2023/04/25 19:53:30 tb Exp $ */ 1/* $OpenBSD: ec_curve.c,v 1.28 2023/05/01 07:54:08 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -2021,16 +2021,10 @@ EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems)
2021 return curve_list_length; 2021 return curve_list_length;
2022} 2022}
2023 2023
2024/* 2024static const struct {
2025 * Functions to translate between common NIST curve names and NIDs. 2025 const char *name;
2026 */ 2026 int nid;
2027 2027} nist_curves[] = {
2028typedef struct {
2029 const char *name; /* NIST Name of curve */
2030 int nid; /* Curve NID */
2031} EC_NIST_NAME;
2032
2033static EC_NIST_NAME nist_curves[] = {
2034 { "B-163", NID_sect163r2 }, 2028 { "B-163", NID_sect163r2 },
2035 { "B-233", NID_sect233r1 }, 2029 { "B-233", NID_sect233r1 },
2036 { "B-283", NID_sect283r1 }, 2030 { "B-283", NID_sect283r1 },
@@ -2053,11 +2047,12 @@ EC_curve_nid2nist(int nid)
2053{ 2047{
2054 size_t i; 2048 size_t i;
2055 2049
2056 for (i = 0; i < sizeof(nist_curves) / sizeof(EC_NIST_NAME); i++) { 2050 for (i = 0; i < sizeof(nist_curves) / sizeof(nist_curves[0]); i++) {
2057 if (nist_curves[i].nid == nid) 2051 if (nist_curves[i].nid == nid)
2058 return (nist_curves[i].name); 2052 return nist_curves[i].name;
2059 } 2053 }
2060 return (NULL); 2054
2055 return NULL;
2061} 2056}
2062 2057
2063int 2058int
@@ -2065,9 +2060,10 @@ EC_curve_nist2nid(const char *name)
2065{ 2060{
2066 size_t i; 2061 size_t i;
2067 2062
2068 for (i = 0; i < sizeof(nist_curves) / sizeof(EC_NIST_NAME); i++) { 2063 for (i = 0; i < sizeof(nist_curves) / sizeof(nist_curves[0]); i++) {
2069 if (!strcmp(nist_curves[i].name, name)) 2064 if (strcmp(nist_curves[i].name, name) == 0)
2070 return (nist_curves[i].nid); 2065 return nist_curves[i].nid;
2071 } 2066 }
2072 return (NID_undef); 2067
2068 return NID_undef;
2073} 2069}