Merge issue-41-hmac-pbkdf2: HMAC-SHA1 and PBKDF2-HMAC-SHA256 (closes #41)
This commit is contained in:
commit
9b773a4553
6 files changed
+826
-46
No files matched your search
@@ -5,6 +5,7 @@
|
||||
#include <Void/Functional/Result.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
@@ -195,6 +196,19 @@ namespace Void::Crypto
|
||||
std::span<const std::byte> signature,
|
||||
const ProviderOptions& provider = {});
|
||||
|
||||
/// Compute HMAC-SHA-1 (RFC 2104) into a caller-owned 20-byte buffer.
|
||||
/// Wipes output on backend failure and rejects overlapping buffers.
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
hmac_sha1_into(std::span<const std::byte> secret_key,
|
||||
std::span<const std::byte> message,
|
||||
std::span<std::byte> output,
|
||||
const ProviderOptions& provider = {});
|
||||
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
hmac_sha1(std::span<const std::byte> secret_key,
|
||||
std::span<const std::byte> message,
|
||||
const ProviderOptions& provider = {});
|
||||
|
||||
/// Compute HMAC-SHA-256 into a caller-owned 32-byte buffer.
|
||||
/// Wipes output on backend failure and rejects overlapping buffers.
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
@@ -208,6 +222,25 @@ namespace Void::Crypto
|
||||
std::span<const std::byte> message,
|
||||
const ProviderOptions& provider = {});
|
||||
|
||||
/// Derive key material with RFC 8018 PBKDF2-HMAC-SHA-256 into a
|
||||
/// caller-owned buffer. iterations must be 1..kMaxPbkdf2Iterations, salt
|
||||
/// at most kMaxPbkdf2SaltBytes and output 1..kMaxPbkdf2OutputBytes.
|
||||
/// Rejects overlapping buffers and wipes output on any failure after
|
||||
/// validation.
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
pbkdf2_hmac_sha256_into(std::span<const std::byte> password,
|
||||
std::span<const std::byte> salt,
|
||||
std::uint32_t iterations,
|
||||
std::span<std::byte> output,
|
||||
const ProviderOptions& provider = {});
|
||||
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
pbkdf2_hmac_sha256(std::span<const std::byte> password,
|
||||
std::span<const std::byte> salt,
|
||||
std::uint32_t iterations,
|
||||
std::size_t output_length,
|
||||
const ProviderOptions& provider = {});
|
||||
|
||||
/// Derive key material with RFC 5869 HKDF-SHA-256 into a caller-owned
|
||||
/// buffer (1..CryptoLimits::kMaxHkdfOutputBytes). Rejects overlapping
|
||||
/// buffers and wipes secret_output on any failure after validation.
|
||||
|
||||
@@ -16,12 +16,16 @@ namespace Void::Crypto
|
||||
inline constexpr std::size_t Ed25519PublicKeySize = 32;
|
||||
inline constexpr std::size_t Ed25519SignatureSize = 64;
|
||||
inline constexpr std::size_t Ed25519SeedSize = 32;
|
||||
inline constexpr std::size_t HmacSha1Size = 20;
|
||||
inline constexpr std::size_t HmacSha256Size = 32;
|
||||
|
||||
struct CryptoLimits {
|
||||
static constexpr std::size_t kMaxOneShotMessageBytes =
|
||||
16ULL * 1024ULL * 1024ULL;
|
||||
static constexpr std::size_t kMaxHkdfOutputBytes = 4ULL * 1024ULL;
|
||||
static constexpr std::uint32_t kMaxPbkdf2Iterations = 10'000'000U;
|
||||
static constexpr std::size_t kMaxPbkdf2SaltBytes = 64ULL * 1024ULL;
|
||||
static constexpr std::size_t kMaxPbkdf2OutputBytes = 1024ULL;
|
||||
static constexpr std::size_t kStreamChunkBytes = 64ULL * 1024ULL;
|
||||
static constexpr std::size_t kDefaultMaxConcurrentFileHashes = 8;
|
||||
static constexpr std::size_t kDefaultMaxWaitingFileHashes = 32;
|
||||
@@ -256,7 +260,8 @@ namespace Void::Crypto
|
||||
ed25519_sign,
|
||||
ed25519_verify,
|
||||
hmac,
|
||||
hkdf
|
||||
hkdf,
|
||||
pbkdf2
|
||||
};
|
||||
|
||||
struct FaultConfig {
|
||||
|
||||
Reference in new issue
Block a user