diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-07-29 20:36:11 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-07-29 20:49:28 +0200 |
commit | 4cc57b4aca65ea86f4e42ddaeadfa796db239719 (patch) | |
tree | 93b57d9d695b608cf7b95e9308925c19ffd73d7e /src/node_crypto_groups.h | |
parent | 8111ca2f9fd89772581c1ec8c0ee8005269f59ff (diff) | |
download | node-new-4cc57b4aca65ea86f4e42ddaeadfa796db239719.tar.gz |
crypto: simplify DH modp group name matcher
* Use ARRAY_SIZE() rather than scanning until we hit a NULL entry.
* Fix `-fsigned-char -Wnarrowing` compiler warnings. Harmless but
numerous and annoying.
* Static-ify the modp_group and mod_groups arrays.
* Const-ify the modp_groups array.
Diffstat (limited to 'src/node_crypto_groups.h')
-rw-r--r-- | src/node_crypto_groups.h | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/node_crypto_groups.h b/src/node_crypto_groups.h index 5e8d0d516f..86ddd2ddaf 100644 --- a/src/node_crypto_groups.h +++ b/src/node_crypto_groups.h @@ -7,9 +7,9 @@ */ -const char two_generator[] = { 2 }; +static const unsigned char two_generator[] = { 2 }; -const char group_modp1[] = { +static const unsigned char group_modp1[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, @@ -21,7 +21,7 @@ const char group_modp1[] = { 0xf4, 0x4c, 0x42, 0xe9, 0xa6, 0x3a, 0x36, 0x20, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -const char group_modp2[] = { +static const unsigned char group_modp2[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, @@ -36,7 +36,7 @@ const char group_modp2[] = { 0x1f, 0xe6, 0x49, 0x28, 0x66, 0x51, 0xec, 0xe6, 0x53, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -const char group_modp5[] = { +static const unsigned char group_modp5[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, @@ -58,7 +58,7 @@ const char group_modp5[] = { 0xca, 0x23, 0x73, 0x27, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -const char group_modp14[] = { +static const unsigned char group_modp14[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, @@ -86,7 +86,7 @@ const char group_modp14[] = { 0x15, 0x72, 0x8e, 0x5a, 0x8a, 0xac, 0xaa, 0x68, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -const char group_modp15[] = { +static const unsigned char group_modp15[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, @@ -127,7 +127,7 @@ const char group_modp15[] = { 0xd1, 0x20, 0xa9, 0x3a, 0xd2, 0xca, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -const char group_modp16[] = { +static const unsigned char group_modp16[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, @@ -181,7 +181,7 @@ const char group_modp16[] = { 0x34, 0x06, 0x31, 0x99, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -const char group_modp17[] = { +static const unsigned char group_modp17[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, @@ -260,7 +260,7 @@ const char group_modp17[] = { 0x74, 0xd6, 0xe6, 0x94, 0xf9, 0x1e, 0x6d, 0xcc, 0x40, 0x24, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -const char group_modp18[] = { +static const unsigned char group_modp18[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, @@ -368,19 +368,20 @@ const char group_modp18[] = { typedef struct { const char* name; const char* prime; - int prime_size; + unsigned int prime_size; const char* gen; - int gen_size; + unsigned int gen_size; } modp_group; -modp_group modp_groups[] = { - { "modp1", group_modp1, sizeof(group_modp1) / sizeof(group_modp1[0]), two_generator, 1 }, - { "modp2", group_modp2, sizeof(group_modp2) / sizeof(group_modp2[0]), two_generator, 1 }, - { "modp5", group_modp5, sizeof(group_modp5) / sizeof(group_modp5[0]), two_generator, 1 }, - { "modp14", group_modp14, sizeof(group_modp14) / sizeof(group_modp14[0]), two_generator, 1 }, - { "modp15", group_modp15, sizeof(group_modp15) / sizeof(group_modp15[0]), two_generator, 1 }, - { "modp16", group_modp16, sizeof(group_modp16) / sizeof(group_modp16[0]), two_generator, 1 }, - { "modp17", group_modp17, sizeof(group_modp17) / sizeof(group_modp17[0]), two_generator, 1 }, - { "modp18", group_modp18, sizeof(group_modp18) / sizeof(group_modp18[0]), two_generator, 1 }, - { NULL, NULL, 0, NULL, 0 } +static const modp_group modp_groups[] = { +#define V(var) reinterpret_cast<const char*>(var) + { "modp1", V(group_modp1), sizeof(group_modp1), V(two_generator), 1 }, + { "modp2", V(group_modp2), sizeof(group_modp2), V(two_generator), 1 }, + { "modp5", V(group_modp5), sizeof(group_modp5), V(two_generator), 1 }, + { "modp14", V(group_modp14), sizeof(group_modp14), V(two_generator), 1 }, + { "modp15", V(group_modp15), sizeof(group_modp15), V(two_generator), 1 }, + { "modp16", V(group_modp16), sizeof(group_modp16), V(two_generator), 1 }, + { "modp17", V(group_modp17), sizeof(group_modp17), V(two_generator), 1 }, + { "modp18", V(group_modp18), sizeof(group_modp18), V(two_generator), 1 } +#undef V }; |