From 04bf8dc51861bab37d6260de8b318dc71ea4bba7 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Thu, 15 Sep 2016 09:16:46 -0400 Subject: Add T::provider() to allow user to inquire about implementation used For block ciphers, stream ciphers, hashes, MACs, and cipher modes. Cipher_Mode already had it, with a slightly different usage. --- src/lib/stream/chacha/chacha.cpp | 12 ++++++++++++ src/lib/stream/chacha/chacha.h | 2 ++ src/lib/stream/stream_cipher.h | 7 +++++++ 3 files changed, 21 insertions(+) (limited to 'src/lib/stream') diff --git a/src/lib/stream/chacha/chacha.cpp b/src/lib/stream/chacha/chacha.cpp index c35363112..66d7ad90d 100644 --- a/src/lib/stream/chacha/chacha.cpp +++ b/src/lib/stream/chacha/chacha.cpp @@ -17,6 +17,18 @@ ChaCha::ChaCha(size_t rounds) : m_rounds(rounds) throw Invalid_Argument("ChaCha only supports 8, 12 or 20 rounds"); } +const char* ChaCha::provider() const + { +#if defined(BOTAN_HAS_CHACHA_SSE2) + if(CPUID::has_sse2()) + { + return "sse2"; + } +#endif + + return "base"; + } + //static void ChaCha::chacha_x4(byte output[64*4], u32bit input[16], size_t rounds) { diff --git a/src/lib/stream/chacha/chacha.h b/src/lib/stream/chacha/chacha.h index 7e9e54768..19ed6d25f 100644 --- a/src/lib/stream/chacha/chacha.h +++ b/src/lib/stream/chacha/chacha.h @@ -26,6 +26,8 @@ class BOTAN_DLL ChaCha final : public StreamCipher */ ChaCha(size_t rounds = 20); + const char* provider() const override; + void cipher(const byte in[], byte out[], size_t length) override; void set_iv(const byte iv[], size_t iv_len) override; diff --git a/src/lib/stream/stream_cipher.h b/src/lib/stream/stream_cipher.h index e08bee0ce..e41cdaa6d 100644 --- a/src/lib/stream/stream_cipher.h +++ b/src/lib/stream/stream_cipher.h @@ -86,6 +86,13 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm */ virtual void seek(u64bit offset) = 0; + /** + * @return provider information about this implementation. Default is "base", + * might also return "sse2", "avx2", "openssl", or some other arbitrary string. + * The return value is guaranteed to point to a string literal constant. + */ + virtual const char* provider() const { return "base"; } + StreamCipher(); virtual ~StreamCipher(); }; -- cgit v1.2.3