From 7ed45bc0da169349ae42450e07a4f2c07be5af14 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sat, 28 Nov 2020 07:23:51 -0500 Subject: Make scan_name.h, cpuid.h and http_util.h internal --- src/cli/speed.cpp | 2 +- src/cli/utils.cpp | 4 +- src/lib/base/info.txt | 1 - src/lib/base/scan_name.cpp | 154 ----------------------- src/lib/base/scan_name.h | 125 ------------------ src/lib/block/aes/aes.cpp | 2 +- src/lib/block/aes/aes_power8/aes_power8.cpp | 2 +- src/lib/block/aria/aria.cpp | 2 +- src/lib/block/block_cipher.cpp | 2 +- src/lib/block/idea/idea.cpp | 2 +- src/lib/block/noekeon/noekeon.cpp | 2 +- src/lib/block/serpent/serpent.cpp | 2 +- src/lib/block/shacal2/shacal2.cpp | 2 +- src/lib/block/sm4/sm4.cpp | 2 +- src/lib/block/threefish_512/threefish_512.cpp | 2 +- src/lib/entropy/rdseed/rdseed.cpp | 2 +- src/lib/hash/hash.cpp | 2 +- src/lib/hash/sha1/sha160.cpp | 2 +- src/lib/hash/sha2_32/sha2_32.cpp | 2 +- src/lib/hash/sha2_64/sha2_64.cpp | 2 +- src/lib/hash/sha3/sha3.cpp | 2 +- src/lib/kdf/kdf.cpp | 2 +- src/lib/kdf/sp800_56a/sp800_56a.cpp | 2 +- src/lib/mac/mac.cpp | 2 +- src/lib/modes/aead/aead.cpp | 2 +- src/lib/modes/cipher_mode.cpp | 2 +- src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.h | 2 +- src/lib/pbkdf/pbkdf.cpp | 2 +- src/lib/pbkdf/pwdhash.cpp | 2 +- src/lib/pk_pad/eme.cpp | 2 +- src/lib/pk_pad/emsa.cpp | 2 +- src/lib/prov/commoncrypto/commoncrypto_utils.cpp | 2 +- src/lib/prov/pkcs11/p11_mechanism.cpp | 2 +- src/lib/pubkey/pkcs8.cpp | 2 +- src/lib/pubkey/xmss/xmss_tools.h | 2 +- src/lib/rng/processor_rng/processor_rng.cpp | 2 +- src/lib/stream/chacha/chacha.cpp | 2 +- src/lib/stream/stream_cipher.cpp | 2 +- src/lib/utils/cpuid/cpuid.cpp | 2 +- src/lib/utils/cpuid/cpuid.h | 2 - src/lib/utils/cpuid/cpuid_arm.cpp | 2 +- src/lib/utils/cpuid/cpuid_ppc.cpp | 2 +- src/lib/utils/cpuid/cpuid_x86.cpp | 2 +- src/lib/utils/cpuid/info.txt | 4 - src/lib/utils/ghash/ghash.cpp | 2 +- src/lib/utils/http_util/http_util.cpp | 2 +- src/lib/utils/http_util/http_util.h | 2 - src/lib/utils/http_util/info.txt | 4 - src/lib/utils/info.txt | 1 + src/lib/utils/os_utils.cpp | 2 +- src/lib/utils/scan_name.cpp | 154 +++++++++++++++++++++++ src/lib/utils/scan_name.h | 123 ++++++++++++++++++ src/lib/utils/simd/simd_32.h | 2 +- src/lib/utils/uuid/uuid.h | 2 +- src/lib/x509/ocsp.cpp | 2 +- src/lib/x509/x509_ca.cpp | 2 +- src/lib/x509/x509path.cpp | 2 +- src/tests/test_runner.cpp | 2 +- src/tests/test_simd.cpp | 2 +- src/tests/test_utils.cpp | 2 +- src/tests/tests.cpp | 2 +- 61 files changed, 330 insertions(+), 344 deletions(-) delete mode 100644 src/lib/base/scan_name.cpp delete mode 100644 src/lib/base/scan_name.h create mode 100644 src/lib/utils/scan_name.cpp create mode 100644 src/lib/utils/scan_name.h (limited to 'src') diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp index f2764c353..5995fdefc 100644 --- a/src/cli/speed.cpp +++ b/src/cli/speed.cpp @@ -18,7 +18,7 @@ // Always available: #include -#include +#include #include #include #include diff --git a/src/cli/utils.cpp b/src/cli/utils.cpp index c6d013029..d55ff5878 100644 --- a/src/cli/utils.cpp +++ b/src/cli/utils.cpp @@ -8,14 +8,14 @@ #include "cli.h" #include -#include +#include #include #include #include #include #if defined(BOTAN_HAS_HTTP_UTIL) - #include + #include #endif #if defined(BOTAN_HAS_UUID) diff --git a/src/lib/base/info.txt b/src/lib/base/info.txt index 3bb3d9501..f8da0cf50 100644 --- a/src/lib/base/info.txt +++ b/src/lib/base/info.txt @@ -1,7 +1,6 @@ buf_comp.h secmem.h -scan_name.h sym_algo.h symkey.h diff --git a/src/lib/base/scan_name.cpp b/src/lib/base/scan_name.cpp deleted file mode 100644 index 4ea2f3dcd..000000000 --- a/src/lib/base/scan_name.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* -* SCAN Name Abstraction -* (C) 2008-2009,2015 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include -#include -#include - -namespace Botan { - -namespace { - -std::string make_arg(const std::vector>& name, size_t start) - { - std::string output = name[start].second; - size_t level = name[start].first; - - size_t paren_depth = 0; - - for(size_t i = start + 1; i != name.size(); ++i) - { - if(name[i].first <= name[start].first) - break; - - if(name[i].first > level) - { - output += "(" + name[i].second; - ++paren_depth; - } - else if(name[i].first < level) - { - for (size_t j = name[i].first; j < level; j++) { - output += ")"; - --paren_depth; - } - output += "," + name[i].second; - } - else - { - if(output[output.size() - 1] != '(') - output += ","; - output += name[i].second; - } - - level = name[i].first; - } - - for(size_t i = 0; i != paren_depth; ++i) - output += ")"; - - return output; - } - -} - -SCAN_Name::SCAN_Name(const char* algo_spec) : SCAN_Name(std::string(algo_spec)) - { - } - -SCAN_Name::SCAN_Name(std::string algo_spec) : m_orig_algo_spec(algo_spec), m_alg_name(), m_args(), m_mode_info() - { - if(algo_spec.size() == 0) - throw Invalid_Argument("Expected algorithm name, got empty string"); - - std::vector> name; - size_t level = 0; - std::pair accum = std::make_pair(level, ""); - - const std::string decoding_error = "Bad SCAN name '" + algo_spec + "': "; - - for(size_t i = 0; i != algo_spec.size(); ++i) - { - char c = algo_spec[i]; - - if(c == '/' || c == ',' || c == '(' || c == ')') - { - if(c == '(') - ++level; - else if(c == ')') - { - if(level == 0) - throw Decoding_Error(decoding_error + "Mismatched parens"); - --level; - } - - if(c == '/' && level > 0) - accum.second.push_back(c); - else - { - if(accum.second != "") - name.push_back(accum); - accum = std::make_pair(level, ""); - } - } - else - accum.second.push_back(c); - } - - if(accum.second != "") - name.push_back(accum); - - if(level != 0) - throw Decoding_Error(decoding_error + "Missing close paren"); - - if(name.size() == 0) - throw Decoding_Error(decoding_error + "Empty name"); - - m_alg_name = name[0].second; - - bool in_modes = false; - - for(size_t i = 1; i != name.size(); ++i) - { - if(name[i].first == 0) - { - m_mode_info.push_back(make_arg(name, i)); - in_modes = true; - } - else if(name[i].first == 1 && !in_modes) - m_args.push_back(make_arg(name, i)); - } - } - -std::string SCAN_Name::arg(size_t i) const - { - if(i >= arg_count()) - throw Invalid_Argument("SCAN_Name::arg " + std::to_string(i) + - " out of range for '" + to_string() + "'"); - return m_args[i]; - } - -std::string SCAN_Name::arg(size_t i, const std::string& def_value) const - { - if(i >= arg_count()) - return def_value; - return m_args[i]; - } - -size_t SCAN_Name::arg_as_integer(size_t i, size_t def_value) const - { - if(i >= arg_count()) - return def_value; - return to_u32bit(m_args[i]); - } - -size_t SCAN_Name::arg_as_integer(size_t i) const - { - return to_u32bit(arg(i)); - } - -} diff --git a/src/lib/base/scan_name.h b/src/lib/base/scan_name.h deleted file mode 100644 index c4b2a034f..000000000 --- a/src/lib/base/scan_name.h +++ /dev/null @@ -1,125 +0,0 @@ -/* -* SCAN Name Abstraction -* (C) 2008,2015 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_SCAN_NAME_H_ -#define BOTAN_SCAN_NAME_H_ - -#include -#include -#include - -BOTAN_FUTURE_INTERNAL_HEADER(scan_name.h) - -namespace Botan { - -/** -A class encapsulating a SCAN name (similar to JCE conventions) -http://www.users.zetnet.co.uk/hopwood/crypto/scan/ -*/ -class BOTAN_PUBLIC_API(2,0) SCAN_Name final - { - public: - /** - * Create a SCAN_Name - * @param algo_spec A SCAN-format name - */ - explicit SCAN_Name(const char* algo_spec); - - /** - * Create a SCAN_Name - * @param algo_spec A SCAN-format name - */ - explicit SCAN_Name(std::string algo_spec); - - /** - * @return original input string - */ - const std::string& to_string() const { return m_orig_algo_spec; } - - /** - * @return algorithm name - */ - const std::string& algo_name() const { return m_alg_name; } - - /** - * @return number of arguments - */ - size_t arg_count() const { return m_args.size(); } - - /** - * @param lower is the lower bound - * @param upper is the upper bound - * @return if the number of arguments is between lower and upper - */ - bool arg_count_between(size_t lower, size_t upper) const - { return ((arg_count() >= lower) && (arg_count() <= upper)); } - - /** - * @param i which argument - * @return ith argument - */ - std::string arg(size_t i) const; - - /** - * @param i which argument - * @param def_value the default value - * @return ith argument or the default value - */ - std::string arg(size_t i, const std::string& def_value) const; - - /** - * @param i which argument - * @param def_value the default value - * @return ith argument as an integer, or the default value - */ - size_t arg_as_integer(size_t i, size_t def_value) const; - - /** - * @param i which argument - * @return ith argument as an integer - */ - size_t arg_as_integer(size_t i) const; - - /** - * @return cipher mode (if any) - */ - std::string cipher_mode() const - { return (m_mode_info.size() >= 1) ? m_mode_info[0] : ""; } - - /** - * @return cipher mode padding (if any) - */ - std::string cipher_mode_pad() const - { return (m_mode_info.size() >= 2) ? m_mode_info[1] : ""; } - - private: - std::string m_orig_algo_spec; - std::string m_alg_name; - std::vector m_args; - std::vector m_mode_info; - }; - -// This is unrelated but it is convenient to stash it here -template -std::vector probe_providers_of(const std::string& algo_spec, - const std::vector& possible) - { - std::vector providers; - for(auto&& prov : possible) - { - std::unique_ptr o(T::create(algo_spec, prov)); - if(o) - { - providers.push_back(prov); // available - } - } - return providers; - } - -} - -#endif diff --git a/src/lib/block/aes/aes.cpp b/src/lib/block/aes/aes.cpp index 72acfa0c9..303154b9d 100644 --- a/src/lib/block/aes/aes.cpp +++ b/src/lib/block/aes/aes.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/lib/block/aes/aes_power8/aes_power8.cpp b/src/lib/block/aes/aes_power8/aes_power8.cpp index e05ce366e..458cef315 100644 --- a/src/lib/block/aes/aes_power8/aes_power8.cpp +++ b/src/lib/block/aes/aes_power8/aes_power8.cpp @@ -10,7 +10,7 @@ */ #include -#include +#include #include #undef vector diff --git a/src/lib/block/aria/aria.cpp b/src/lib/block/aria/aria.cpp index 565f25462..9ff324e49 100644 --- a/src/lib/block/aria/aria.cpp +++ b/src/lib/block/aria/aria.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/lib/block/block_cipher.cpp b/src/lib/block/block_cipher.cpp index 2450ead96..2e43d337a 100644 --- a/src/lib/block/block_cipher.cpp +++ b/src/lib/block/block_cipher.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #include #if defined(BOTAN_HAS_AES) diff --git a/src/lib/block/idea/idea.cpp b/src/lib/block/idea/idea.cpp index f5e15e325..dd4868c74 100644 --- a/src/lib/block/idea/idea.cpp +++ b/src/lib/block/idea/idea.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include namespace Botan { diff --git a/src/lib/block/noekeon/noekeon.cpp b/src/lib/block/noekeon/noekeon.cpp index 7586176c4..c5b347981 100644 --- a/src/lib/block/noekeon/noekeon.cpp +++ b/src/lib/block/noekeon/noekeon.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/lib/block/serpent/serpent.cpp b/src/lib/block/serpent/serpent.cpp index 412b173a5..7c4384d3d 100644 --- a/src/lib/block/serpent/serpent.cpp +++ b/src/lib/block/serpent/serpent.cpp @@ -11,7 +11,7 @@ #include #if defined(BOTAN_HAS_SERPENT_SIMD) || defined(BOTAN_HAS_SERPENT_AVX2) - #include + #include #endif namespace Botan { diff --git a/src/lib/block/shacal2/shacal2.cpp b/src/lib/block/shacal2/shacal2.cpp index 3617708e6..0c6ee28e8 100644 --- a/src/lib/block/shacal2/shacal2.cpp +++ b/src/lib/block/shacal2/shacal2.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/lib/block/sm4/sm4.cpp b/src/lib/block/sm4/sm4.cpp index 515543ed0..96246ca42 100644 --- a/src/lib/block/sm4/sm4.cpp +++ b/src/lib/block/sm4/sm4.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/lib/block/threefish_512/threefish_512.cpp b/src/lib/block/threefish_512/threefish_512.cpp index 9c202caae..590087382 100644 --- a/src/lib/block/threefish_512/threefish_512.cpp +++ b/src/lib/block/threefish_512/threefish_512.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/lib/entropy/rdseed/rdseed.cpp b/src/lib/entropy/rdseed/rdseed.cpp index 1830edf9d..fe6669ee2 100644 --- a/src/lib/entropy/rdseed/rdseed.cpp +++ b/src/lib/entropy/rdseed/rdseed.cpp @@ -7,7 +7,7 @@ */ #include -#include +#include #include diff --git a/src/lib/hash/hash.cpp b/src/lib/hash/hash.cpp index 24792e8e1..7d0d15159 100644 --- a/src/lib/hash/hash.cpp +++ b/src/lib/hash/hash.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #include #if defined(BOTAN_HAS_ADLER32) diff --git a/src/lib/hash/sha1/sha160.cpp b/src/lib/hash/sha1/sha160.cpp index c1033eaa9..70f2f55b8 100644 --- a/src/lib/hash/sha1/sha160.cpp +++ b/src/lib/hash/sha1/sha160.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/lib/hash/sha2_32/sha2_32.cpp b/src/lib/hash/sha2_32/sha2_32.cpp index 8efb8cd07..096028953 100644 --- a/src/lib/hash/sha2_32/sha2_32.cpp +++ b/src/lib/hash/sha2_32/sha2_32.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/lib/hash/sha2_64/sha2_64.cpp b/src/lib/hash/sha2_64/sha2_64.cpp index bc0900264..b34623070 100644 --- a/src/lib/hash/sha2_64/sha2_64.cpp +++ b/src/lib/hash/sha2_64/sha2_64.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/lib/hash/sha3/sha3.cpp b/src/lib/hash/sha3/sha3.cpp index 314b92ded..8ff2d06ee 100644 --- a/src/lib/hash/sha3/sha3.cpp +++ b/src/lib/hash/sha3/sha3.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/lib/kdf/kdf.cpp b/src/lib/kdf/kdf.cpp index 87a6bb5f6..3a4a7fa6e 100644 --- a/src/lib/kdf/kdf.cpp +++ b/src/lib/kdf/kdf.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #if defined(BOTAN_HAS_HKDF) diff --git a/src/lib/kdf/sp800_56a/sp800_56a.cpp b/src/lib/kdf/sp800_56a/sp800_56a.cpp index 06d724da6..bc9fec20d 100644 --- a/src/lib/kdf/sp800_56a/sp800_56a.cpp +++ b/src/lib/kdf/sp800_56a/sp800_56a.cpp @@ -7,7 +7,7 @@ */ #include -#include +#include #include namespace Botan { diff --git a/src/lib/mac/mac.cpp b/src/lib/mac/mac.cpp index 4faebb0e9..a9ccef759 100644 --- a/src/lib/mac/mac.cpp +++ b/src/lib/mac/mac.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #if defined(BOTAN_HAS_CMAC) diff --git a/src/lib/modes/aead/aead.cpp b/src/lib/modes/aead/aead.cpp index d8aa762ac..98a127866 100644 --- a/src/lib/modes/aead/aead.cpp +++ b/src/lib/modes/aead/aead.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include diff --git a/src/lib/modes/cipher_mode.cpp b/src/lib/modes/cipher_mode.cpp index b41c103e6..4d6067fbd 100644 --- a/src/lib/modes/cipher_mode.cpp +++ b/src/lib/modes/cipher_mode.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include diff --git a/src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.h b/src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.h index 0d459e8db..ab5e62288 100644 --- a/src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.h +++ b/src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.h @@ -9,7 +9,7 @@ #include -BOTAN_FUTURE_INTERNAL_HEADER(bcrypt_pbkdf.h) +//BOTAN_FUTURE_INTERNAL_HEADER(bcrypt_pbkdf.h) namespace Botan { diff --git a/src/lib/pbkdf/pbkdf.cpp b/src/lib/pbkdf/pbkdf.cpp index 1434ec183..a8df78376 100644 --- a/src/lib/pbkdf/pbkdf.cpp +++ b/src/lib/pbkdf/pbkdf.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #if defined(BOTAN_HAS_PBKDF2) #include diff --git a/src/lib/pbkdf/pwdhash.cpp b/src/lib/pbkdf/pwdhash.cpp index 718024a22..9680604b2 100644 --- a/src/lib/pbkdf/pwdhash.cpp +++ b/src/lib/pbkdf/pwdhash.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #if defined(BOTAN_HAS_PBKDF2) #include diff --git a/src/lib/pk_pad/eme.cpp b/src/lib/pk_pad/eme.cpp index cffa446e0..042db3fab 100644 --- a/src/lib/pk_pad/eme.cpp +++ b/src/lib/pk_pad/eme.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #include #include diff --git a/src/lib/pk_pad/emsa.cpp b/src/lib/pk_pad/emsa.cpp index 9394d1e18..63a0488d9 100644 --- a/src/lib/pk_pad/emsa.cpp +++ b/src/lib/pk_pad/emsa.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #if defined(BOTAN_HAS_EMSA1) diff --git a/src/lib/prov/commoncrypto/commoncrypto_utils.cpp b/src/lib/prov/commoncrypto/commoncrypto_utils.cpp index 69eb31d37..685f7aa19 100644 --- a/src/lib/prov/commoncrypto/commoncrypto_utils.cpp +++ b/src/lib/prov/commoncrypto/commoncrypto_utils.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/lib/prov/pkcs11/p11_mechanism.cpp b/src/lib/prov/pkcs11/p11_mechanism.cpp index 3d58e8772..04f347814 100644 --- a/src/lib/prov/pkcs11/p11_mechanism.cpp +++ b/src/lib/prov/pkcs11/p11_mechanism.cpp @@ -7,7 +7,7 @@ */ #include -#include +#include #include #include diff --git a/src/lib/pubkey/pkcs8.cpp b/src/lib/pubkey/pkcs8.cpp index e279bb60a..95d4bf505 100644 --- a/src/lib/pubkey/pkcs8.cpp +++ b/src/lib/pubkey/pkcs8.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #if defined(BOTAN_HAS_PKCS5_PBES2) diff --git a/src/lib/pubkey/xmss/xmss_tools.h b/src/lib/pubkey/xmss/xmss_tools.h index bbd31fd9f..2b85396a1 100644 --- a/src/lib/pubkey/xmss/xmss_tools.h +++ b/src/lib/pubkey/xmss/xmss_tools.h @@ -8,7 +8,7 @@ #ifndef BOTAN_XMSS_TOOLS_H_ #define BOTAN_XMSS_TOOLS_H_ -#include +#include #include #include #include diff --git a/src/lib/rng/processor_rng/processor_rng.cpp b/src/lib/rng/processor_rng/processor_rng.cpp index 6e9aa8680..ee54870f8 100644 --- a/src/lib/rng/processor_rng/processor_rng.cpp +++ b/src/lib/rng/processor_rng/processor_rng.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) && !defined(BOTAN_USE_GCC_INLINE_ASM) #include diff --git a/src/lib/stream/chacha/chacha.cpp b/src/lib/stream/chacha/chacha.cpp index 8f976cb1a..aa9f8c11c 100644 --- a/src/lib/stream/chacha/chacha.cpp +++ b/src/lib/stream/chacha/chacha.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/lib/stream/stream_cipher.cpp b/src/lib/stream/stream_cipher.cpp index c8e54bbe7..32ced3d4a 100644 --- a/src/lib/stream/stream_cipher.cpp +++ b/src/lib/stream/stream_cipher.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #include #if defined(BOTAN_HAS_CHACHA) diff --git a/src/lib/utils/cpuid/cpuid.cpp b/src/lib/utils/cpuid/cpuid.cpp index a85960e71..e75df3900 100644 --- a/src/lib/utils/cpuid/cpuid.cpp +++ b/src/lib/utils/cpuid/cpuid.cpp @@ -5,7 +5,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include +#include #include #include #include diff --git a/src/lib/utils/cpuid/cpuid.h b/src/lib/utils/cpuid/cpuid.h index 468b004b5..db0bfe1a9 100644 --- a/src/lib/utils/cpuid/cpuid.h +++ b/src/lib/utils/cpuid/cpuid.h @@ -13,8 +13,6 @@ #include #include -BOTAN_FUTURE_INTERNAL_HEADER(cpuid.h) - namespace Botan { /** diff --git a/src/lib/utils/cpuid/cpuid_arm.cpp b/src/lib/utils/cpuid/cpuid_arm.cpp index 0711dfdf3..ab968cb96 100644 --- a/src/lib/utils/cpuid/cpuid_arm.cpp +++ b/src/lib/utils/cpuid/cpuid_arm.cpp @@ -5,7 +5,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include +#include #if defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY) diff --git a/src/lib/utils/cpuid/cpuid_ppc.cpp b/src/lib/utils/cpuid/cpuid_ppc.cpp index 604b97947..dbaf802ad 100644 --- a/src/lib/utils/cpuid/cpuid_ppc.cpp +++ b/src/lib/utils/cpuid/cpuid_ppc.cpp @@ -5,7 +5,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include +#include #include #if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY) diff --git a/src/lib/utils/cpuid/cpuid_x86.cpp b/src/lib/utils/cpuid/cpuid_x86.cpp index 6d07ca198..b8ae54f87 100644 --- a/src/lib/utils/cpuid/cpuid_x86.cpp +++ b/src/lib/utils/cpuid/cpuid_x86.cpp @@ -5,7 +5,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include +#include #include #include diff --git a/src/lib/utils/cpuid/info.txt b/src/lib/utils/cpuid/info.txt index 987d7eae4..3dd65d76e 100644 --- a/src/lib/utils/cpuid/info.txt +++ b/src/lib/utils/cpuid/info.txt @@ -1,7 +1,3 @@ CPUID -> 20170917 - - -cpuid.h - diff --git a/src/lib/utils/ghash/ghash.cpp b/src/lib/utils/ghash/ghash.cpp index ccb83cc5f..af4f52765 100644 --- a/src/lib/utils/ghash/ghash.cpp +++ b/src/lib/utils/ghash/ghash.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include namespace Botan { diff --git a/src/lib/utils/http_util/http_util.cpp b/src/lib/utils/http_util/http_util.cpp index f2b5f3361..3d56c22bb 100644 --- a/src/lib/utils/http_util/http_util.cpp +++ b/src/lib/utils/http_util/http_util.cpp @@ -6,7 +6,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include +#include #include #include #include diff --git a/src/lib/utils/http_util/http_util.h b/src/lib/utils/http_util/http_util.h index 7ad7c5828..2a4e4955c 100644 --- a/src/lib/utils/http_util/http_util.h +++ b/src/lib/utils/http_util/http_util.h @@ -16,8 +16,6 @@ #include #include -BOTAN_FUTURE_INTERNAL_HEADER(http_util.h) - namespace Botan { namespace HTTP { diff --git a/src/lib/utils/http_util/info.txt b/src/lib/utils/http_util/info.txt index a3ebc249e..0004404ad 100644 --- a/src/lib/utils/http_util/info.txt +++ b/src/lib/utils/http_util/info.txt @@ -2,10 +2,6 @@ HTTP_UTIL -> 20171003 - -http_util.h - - socket diff --git a/src/lib/utils/info.txt b/src/lib/utils/info.txt index 5f9a06c52..43e8d335f 100644 --- a/src/lib/utils/info.txt +++ b/src/lib/utils/info.txt @@ -32,6 +32,7 @@ parsing.h rotate.h rounding.h safeint.h +scan_name.h stl_util.h timer.h diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index 4e536aa24..d76419aa4 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -7,7 +7,7 @@ */ #include -#include +#include #include #include diff --git a/src/lib/utils/scan_name.cpp b/src/lib/utils/scan_name.cpp new file mode 100644 index 000000000..56c06dcc5 --- /dev/null +++ b/src/lib/utils/scan_name.cpp @@ -0,0 +1,154 @@ +/* +* SCAN Name Abstraction +* (C) 2008-2009,2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include +#include +#include + +namespace Botan { + +namespace { + +std::string make_arg(const std::vector>& name, size_t start) + { + std::string output = name[start].second; + size_t level = name[start].first; + + size_t paren_depth = 0; + + for(size_t i = start + 1; i != name.size(); ++i) + { + if(name[i].first <= name[start].first) + break; + + if(name[i].first > level) + { + output += "(" + name[i].second; + ++paren_depth; + } + else if(name[i].first < level) + { + for (size_t j = name[i].first; j < level; j++) { + output += ")"; + --paren_depth; + } + output += "," + name[i].second; + } + else + { + if(output[output.size() - 1] != '(') + output += ","; + output += name[i].second; + } + + level = name[i].first; + } + + for(size_t i = 0; i != paren_depth; ++i) + output += ")"; + + return output; + } + +} + +SCAN_Name::SCAN_Name(const char* algo_spec) : SCAN_Name(std::string(algo_spec)) + { + } + +SCAN_Name::SCAN_Name(std::string algo_spec) : m_orig_algo_spec(algo_spec), m_alg_name(), m_args(), m_mode_info() + { + if(algo_spec.size() == 0) + throw Invalid_Argument("Expected algorithm name, got empty string"); + + std::vector> name; + size_t level = 0; + std::pair accum = std::make_pair(level, ""); + + const std::string decoding_error = "Bad SCAN name '" + algo_spec + "': "; + + for(size_t i = 0; i != algo_spec.size(); ++i) + { + char c = algo_spec[i]; + + if(c == '/' || c == ',' || c == '(' || c == ')') + { + if(c == '(') + ++level; + else if(c == ')') + { + if(level == 0) + throw Decoding_Error(decoding_error + "Mismatched parens"); + --level; + } + + if(c == '/' && level > 0) + accum.second.push_back(c); + else + { + if(accum.second != "") + name.push_back(accum); + accum = std::make_pair(level, ""); + } + } + else + accum.second.push_back(c); + } + + if(accum.second != "") + name.push_back(accum); + + if(level != 0) + throw Decoding_Error(decoding_error + "Missing close paren"); + + if(name.size() == 0) + throw Decoding_Error(decoding_error + "Empty name"); + + m_alg_name = name[0].second; + + bool in_modes = false; + + for(size_t i = 1; i != name.size(); ++i) + { + if(name[i].first == 0) + { + m_mode_info.push_back(make_arg(name, i)); + in_modes = true; + } + else if(name[i].first == 1 && !in_modes) + m_args.push_back(make_arg(name, i)); + } + } + +std::string SCAN_Name::arg(size_t i) const + { + if(i >= arg_count()) + throw Invalid_Argument("SCAN_Name::arg " + std::to_string(i) + + " out of range for '" + to_string() + "'"); + return m_args[i]; + } + +std::string SCAN_Name::arg(size_t i, const std::string& def_value) const + { + if(i >= arg_count()) + return def_value; + return m_args[i]; + } + +size_t SCAN_Name::arg_as_integer(size_t i, size_t def_value) const + { + if(i >= arg_count()) + return def_value; + return to_u32bit(m_args[i]); + } + +size_t SCAN_Name::arg_as_integer(size_t i) const + { + return to_u32bit(arg(i)); + } + +} diff --git a/src/lib/utils/scan_name.h b/src/lib/utils/scan_name.h new file mode 100644 index 000000000..ca72eec37 --- /dev/null +++ b/src/lib/utils/scan_name.h @@ -0,0 +1,123 @@ +/* +* SCAN Name Abstraction +* (C) 2008,2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_SCAN_NAME_H_ +#define BOTAN_SCAN_NAME_H_ + +#include +#include +#include + +namespace Botan { + +/** +A class encapsulating a SCAN name (similar to JCE conventions) +http://www.users.zetnet.co.uk/hopwood/crypto/scan/ +*/ +class BOTAN_PUBLIC_API(2,0) SCAN_Name final + { + public: + /** + * Create a SCAN_Name + * @param algo_spec A SCAN-format name + */ + explicit SCAN_Name(const char* algo_spec); + + /** + * Create a SCAN_Name + * @param algo_spec A SCAN-format name + */ + explicit SCAN_Name(std::string algo_spec); + + /** + * @return original input string + */ + const std::string& to_string() const { return m_orig_algo_spec; } + + /** + * @return algorithm name + */ + const std::string& algo_name() const { return m_alg_name; } + + /** + * @return number of arguments + */ + size_t arg_count() const { return m_args.size(); } + + /** + * @param lower is the lower bound + * @param upper is the upper bound + * @return if the number of arguments is between lower and upper + */ + bool arg_count_between(size_t lower, size_t upper) const + { return ((arg_count() >= lower) && (arg_count() <= upper)); } + + /** + * @param i which argument + * @return ith argument + */ + std::string arg(size_t i) const; + + /** + * @param i which argument + * @param def_value the default value + * @return ith argument or the default value + */ + std::string arg(size_t i, const std::string& def_value) const; + + /** + * @param i which argument + * @param def_value the default value + * @return ith argument as an integer, or the default value + */ + size_t arg_as_integer(size_t i, size_t def_value) const; + + /** + * @param i which argument + * @return ith argument as an integer + */ + size_t arg_as_integer(size_t i) const; + + /** + * @return cipher mode (if any) + */ + std::string cipher_mode() const + { return (m_mode_info.size() >= 1) ? m_mode_info[0] : ""; } + + /** + * @return cipher mode padding (if any) + */ + std::string cipher_mode_pad() const + { return (m_mode_info.size() >= 2) ? m_mode_info[1] : ""; } + + private: + std::string m_orig_algo_spec; + std::string m_alg_name; + std::vector m_args; + std::vector m_mode_info; + }; + +// This is unrelated but it is convenient to stash it here +template +std::vector probe_providers_of(const std::string& algo_spec, + const std::vector& possible) + { + std::vector providers; + for(auto&& prov : possible) + { + std::unique_ptr o(T::create(algo_spec, prov)); + if(o) + { + providers.push_back(prov); // available + } + } + return providers; + } + +} + +#endif diff --git a/src/lib/utils/simd/simd_32.h b/src/lib/utils/simd/simd_32.h index 58d76c277..858c23a7f 100644 --- a/src/lib/utils/simd/simd_32.h +++ b/src/lib/utils/simd/simd_32.h @@ -23,7 +23,7 @@ #define BOTAN_SIMD_USE_ALTIVEC #elif defined(BOTAN_TARGET_SUPPORTS_NEON) - #include + #include #include #define BOTAN_SIMD_USE_NEON diff --git a/src/lib/utils/uuid/uuid.h b/src/lib/utils/uuid/uuid.h index 8f95f4d67..a2b08e8cb 100644 --- a/src/lib/utils/uuid/uuid.h +++ b/src/lib/utils/uuid/uuid.h @@ -12,7 +12,7 @@ #include #include -BOTAN_FUTURE_INTERNAL_HEADER(uuid.h) +//BOTAN_FUTURE_INTERNAL_HEADER(uuid.h) namespace Botan { diff --git a/src/lib/x509/ocsp.cpp b/src/lib/x509/ocsp.cpp index 69d216ad0..ec120764a 100644 --- a/src/lib/x509/ocsp.cpp +++ b/src/lib/x509/ocsp.cpp @@ -16,7 +16,7 @@ #include #if defined(BOTAN_HAS_HTTP_UTIL) - #include + #include #endif namespace Botan { diff --git a/src/lib/x509/x509_ca.cpp b/src/lib/x509/x509_ca.cpp index 9508e9466..63207b336 100644 --- a/src/lib/x509/x509_ca.cpp +++ b/src/lib/x509/x509_ca.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/lib/x509/x509path.cpp b/src/lib/x509/x509path.cpp index 840e8f3bf..7a5ff35b1 100644 --- a/src/lib/x509/x509path.cpp +++ b/src/lib/x509/x509path.cpp @@ -20,7 +20,7 @@ #if defined(BOTAN_HAS_ONLINE_REVOCATION_CHECKS) #include - #include + #include #endif namespace Botan { diff --git a/src/tests/test_runner.cpp b/src/tests/test_runner.cpp index ed7cad8ba..3a5fa1db3 100644 --- a/src/tests/test_runner.cpp +++ b/src/tests/test_runner.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #if defined(BOTAN_HAS_THREAD_UTILS) #include diff --git a/src/tests/test_simd.cpp b/src/tests/test_simd.cpp index 8b9b44d8f..eefe77b6e 100644 --- a/src/tests/test_simd.cpp +++ b/src/tests/test_simd.cpp @@ -10,7 +10,7 @@ #include #include #include - #include + #include #include #endif diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp index 230d86ef9..d6004fb0b 100644 --- a/src/tests/test_utils.cpp +++ b/src/tests/test_utils.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index 9a8ee66f1..838d864d7 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #if defined(BOTAN_HAS_BIGINT) #include -- cgit v1.2.3