Skip to content

crypto/hmac.hpp

Namespaces

Name
rlpx
rlpx::crypto

Classes

Name
class rlpx::crypto::Hmac

Source code

// Copyright 2025 GeniusVentures
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "../rlpx_types.hpp"
#include "../rlpx_error.hpp"

namespace rlpx::crypto {

// HMAC-SHA256 operations
class Hmac {
public:
    Hmac() = delete;

    // Compute HMAC-SHA256 digest
    [[nodiscard]] static CryptoResult<ByteBuffer>
    compute(ByteView key, ByteView data) noexcept;

    // Compute HMAC-SHA256 and return fixed-size MAC (truncated to kMacSize)
    [[nodiscard]] static CryptoResult<MacDigest>
    compute_mac(ByteView key, ByteView data) noexcept;

    // Verify HMAC (constant-time comparison)
    [[nodiscard]] static bool
    verify(ByteView key, ByteView data, ByteView expected_mac) noexcept;
};

} // namespace rlpx::crypto

Updated on 2026-04-13 at 23:22:46 -0700