From 805c391817f22681ca9f09d7b04475f7cd9d34e7 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Wed, 6 Jan 2016 13:40:23 -0500 Subject: Precompile the list of TLS ciphersuites This avoids a scan over the entire 0 - 0xFFFF space which is mostly empty, by instead keeping a second list in tls_suite_info which is exactly the keys for which the switch statement has values. This scan is only ever done once (when first needed) but removing it is sufficient to increase AFL's throuhput by 4x since it goes through a full startup on each test. --- src/scripts/tls_suite_info.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/scripts') diff --git a/src/scripts/tls_suite_info.py b/src/scripts/tls_suite_info.py index dc0468c88..6ba807d68 100755 --- a/src/scripts/tls_suite_info.py +++ b/src/scripts/tls_suite_info.py @@ -311,15 +311,33 @@ namespace Botan { namespace TLS { +std::vector Ciphersuite::all_known_ciphersuite_ids() + { + return std::vector{ +""" + + csuite_ids = {} + + for (k,v) in suites.items(): + csuite_ids[v[0]] = (k, v[1]) + + for i in sorted(csuite_ids.keys()): + suite_info += " 0x%s,\n" % (i) + + suite_info += """ }; +} + Ciphersuite Ciphersuite::by_id(u16bit suite) { switch(suite) { """ - for k in sorted(suites.keys()): - suite_info += " case 0x%s: // %s\n" % (suites[k][0], k) - suite_info += " return %s;\n\n" % (suites[k][1]) + for i in sorted(csuite_ids.keys()): + suite_name = csuite_ids[i][0] + suite_expr = csuite_ids[i][1] + suite_info += " case 0x%s: // %s\n" % (i, suite_name) + suite_info += " return %s;\n\n" % (suite_expr) suite_info += """ } -- cgit v1.2.3