[Botan-devel] New algorithm lookup interfaces, and question about current usage

Jack Lloyd lloyd at randombit.net
Sun Nov 9 13:52:59 EST 2008


I haven't got much code for this yet but here is my conception:

Algorithm implementations (thinking about block ciphers, hashes, etc)
have both a name and (new) a provider. Provider being just a string id
such as "core" (builtin C++ versions), "core:x86", "core:x86-64",
"openssl", and so on, exposed via a virtual function in the base
classes as with name() and so on.

The library will expose these queries:

// list of providers of this algorithm (perhaps empty)
// Maybe providers_of("SHA-1") -> { "core", "core:x86-64", "core:sse2", "openssl" }
vector<string> providers_of(string algo_name);

// If provider is specified, that specific provider will be used,
// or otherwise no result (NULL)
// If provider is not set, choose any provider by some internal logic
// T == BlockCipher, StreamCipher, HashFunction, etc
T* get_algo_T(string algo_name, string provider = "");

// Benchmarks all providers of algo_name, trying to take no more time
// than specified by seconds. Returns the name of the fastest
// provider, along with estimated speed of that impl in MiB/sec.
pair<string, double>
choose_fastest(string algo_name, double seconds);

Unlike the current engine implementations, this makes it easy to
compare different implementations and choose one based on the best
performance on this particular system at runtime (or just query which
ones are available and pick one out of a static ordering, if preferred
or the overhead of runtime testing would be excessive).

Anyone have thoughts or comments on this? It seems to provide much
better flexibility, I'm thinking especially of programs like Monotone
which rely heavily on the performance of particular algorithms (SHA-1,
in Monotone's case) and would like to be able to easily choose the
fastest. (That's currently pretty hard to do with the existing engine
setup).

One feature I'm considering removing to simplify the implementation is
the ability to add/set/remove algorithm aliases at runtime. If anyone
is using and relying on this feature, it would probably be a good idea
to let me know.

-Jack



More information about the botan-devel mailing list