Comments (3)
I can absolutely understand why you'd want this. But it may not be really possible for us to provide it. Really we couldn't provide it even in the old interface with a named-class-per-algorithm; it works in your example but not for SHA-3, BLAKE, SHAKE, etc since there there is a variable output length which is parameterized at runtime.
The best approach I can see that might get you some of the way to what you're looking for would be a hypothetical API that I just made up.
enum class HashFunctionParams {
SHA_1,
SHA_256,
SHA_3(size_t), // in my imagination C++ also has sum types; we could fake this in various ways
...
};
constexpr size_t HashFunctionParams::output_length() {
switch(*this) {
case HashFunctionParams::SHA_1: return 20;
case HashFunctionParams::SHA_256: return 32;
//...
}
}
constexpr auto hash_id = HashFunctionParams::SHA_1;
auto hash = HashFunction::create_from_params(hash_id);
hash->update(whatever);
std::array<uint8_t, hash_id.output_length()> digest;
hash->final(digest.data());
This would actually be pretty nice and avoid a lot of string handling that we're otherwise stuck with during algorithm creation.
But, this isn't something that's likely to happen very soon.
from botan.
Such a thing would also be useful for some internal use cases. We did have some discussion about something similar in the context of asynchronous algorithms. And there's a ticket tracking this todo (for the record): #3706.
from botan.
Thanks for the input. I hadn't considered the case of the variable output length functions (I haven't used those).
from botan.
Related Issues (20)
- Update clang-format rules
- CI needs to test deprecated and experimental builds
- Cipher Mode : Process and Finish are Confusing HOT 2
- Fuzzers and fuzzer documentation could use some love
- Internal: load_be/le should accept a BufferSlicer
- Introduce a notion of budget to X509 path validation
- Add Limbo and BetterTLS to CI
- Use a larger sequence number window in DTLS
- Somehow load_{be,le} of integer without offset doesn't work HOT 1
- HSS test failure HOT 1
- ECDSA tests without RFC 6979 quite insufficient
- Follow-up: Introduce reduced KATs and/or ARM32 full run
- FFI: botan_cipher_get_update_granularity() returns 17 HOT 2
- How to implement TLS 1.3 session resumption? HOT 7
- Current master fails to build/link HOT 6
- Clang tidy doesn't check headers HOT 1
- MSVC 19.40 miscompilation/crash HOT 3
- Need keygen+serialization stability tests
- Somewhat regular failures of gcc sanitizer tls_proxy cli test HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from botan.