randombit / botan

Cryptography Toolkit
https://botan.randombit.net
BSD 2-Clause "Simplified" License
2.59k stars 567 forks source link

Extend/Update (public) APIs with `std::span` overloads #3318

Open reneme opened 1 year ago

reneme commented 1 year ago

Alongside existing std::vector<T, Alloc> and C-style ptr-length APIs we're gradually introducing overloads taking a std::span from C++20. This ticket is an attempt to create/maintain a list of interfaces that should get such overloads.

Public APIs and Interfaces

Internal APIs and Interfaces

randombit commented 1 year ago

Another one, from #3411

      Kyber_PublicKey(const AlgorithmIdentifier& alg_id,
-                      const std::vector<uint8_t>& key_bits);
+                      std::span<const uint8_t> key_bits);

Would be nice to do this for all of the key types.

(This might require some work on BER_Decoder though ...)

crazydef commented 1 year ago

It would be nice if Botan detected the C++ version in the headers and didn't expose unsupported/new features to C++ compilers that didn't support them.

I am currently trying to integrate Botan into a codebase that can't be built with C++20 (because other libraries we're using don't support it yet) and having to wrap everything is becoming a royal pain in the ass.

randombit commented 1 year ago

@crazydef Don't do that. Use Botan2, which is still supported and probably will be for years, and is C++11.

Or (for some functionality) you can use the C89 API in ffi.h

lieser commented 1 year ago

because other libraries we're using don't support it yet

Do this libraries really break if compiled with C++20? I would expect most older code to work without a problem if compiled with a newer C++ standard.

crazydef commented 1 year ago

@lieser C++17 deprecated a lot of stuff and removed even more. One particular library I have to deal with still only supports C++14 because of the mess that is C++17.

CharlesJQuarra commented 10 months ago

I'm just trying to build from tag 3.2.0, and I'm seeing the #include <span> breaking compilation for C++17. make is building with the following options:

g++ -fPIC -fvisibility=hidden -fstack-protector -m64 -pthread -std=c++17 -D_REENTRANT -O3 -DBOTAN_IS_BEING_BUILT -Wall -Wextra -Wpedantic -Wstrict-aliasing -Wcast-align -Wmissing-declarations -Wpointer-arith -Wcast-qual -Wzero-as-null-pointer-constant -Wnon-virtual-dtor -Wold-style-cast -Wsuggest-override -Wshadow -Wextra-semi -I build/include -isystem build/include/external

As I'm sure you are aware, #include <span> is only supported for C++20. Not sure if this is somehow supported as an extension by other compilers but on g++ 8.4.0 it is certainly not.

randombit commented 10 months ago

@CharlesJQuarra Botan 3.0 and higher requires C++20 and minimum GCC at least 11.2

That you're seeing precisely this error is surprising in that configure.py should have detected that the version of GCC is too old, and immediately errored out.

CharlesJQuarra commented 10 months ago

@randombit my bad, I ran make directly, as it worked on previous pulls, once I ran configure.py I saw the updated warnings that C++17 is no longer supported for v3