GithubHelp home page GithubHelp logo

Compile-time output length about botan HOT 3 OPEN

Chaosvex avatar Chaosvex commented on June 21, 2024
Compile-time output length

from botan.

Comments (3)

randombit avatar randombit commented on June 21, 2024 1

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.

reneme avatar reneme commented on June 21, 2024 1

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.

Chaosvex avatar Chaosvex commented on June 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.