Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ option(TESTING "Build tests" OFF)
option(CLANG_TIDY "Perform linting with clang-tidy" OFF)
option(SANITIZERS "Enable sanitizers" OFF)
option(NO_ALLOC "Build without needing an allocator" OFF)
option(MLS_CONTEXT "Build with MLSContext support" ON)
option(NAMESPACE_SUFFIX "Namespace Suffix for CXX and CMake Export")

if(NAMESPACE_SUFFIX)
Expand Down Expand Up @@ -72,6 +73,11 @@ if(NO_ALLOC)
add_definitions(-DNO_ALLOC)
endif()

if(NOT MLS_CONTEXT)
message(STATUS "Disabling MLSContext")
add_definitions(-DSFRAME_ENABLE_MLS_CONTEXT=0)
endif()

###
### Dependencies
###
Expand Down
8 changes: 8 additions & 0 deletions include/sframe/sframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#define SFRAME_EPOCH_BITS 4
#endif

#ifndef SFRAME_ENABLE_MLS_CONTEXT
#define SFRAME_ENABLE_MLS_CONTEXT 1
#endif

namespace SFRAME_NAMESPACE {

#ifdef __cpp_exceptions
Expand Down Expand Up @@ -147,6 +151,8 @@ class Context
input_bytes metadata);
};

#if SFRAME_ENABLE_MLS_CONTEXT

// MLSContext augments Context with logic for deriving keys from MLS. Instead
// of adding individual keys, salts, and key IDs, the caller adds a secret for
// an epoch, and keys / salts / key IDs are derived as needed.
Expand Down Expand Up @@ -219,4 +225,6 @@ class MLSContext : protected Context
vector<std::optional<EpochKeys>, max_epochs> epoch_cache;
};

#endif // SFRAME_ENABLE_MLS_CONTEXT

} // namespace SFRAME_NAMESPACE
4 changes: 4 additions & 0 deletions src/sframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ Context::unprotect_inner(const Header& header,
return open(suite, key_and_salt.key, nonce, plaintext, aad, ciphertext);
}

#if SFRAME_ENABLE_MLS_CONTEXT

///
/// MLSContext
///
Expand Down Expand Up @@ -417,4 +419,6 @@ MLSContext::ensure_key(KeyID key_id, KeyUsage usage)
return Context::add_key(key_id, usage, base);
}

#endif // SFRAME_ENABLE_MLS_CONTEXT

} // namespace SFRAME_NAMESPACE
4 changes: 4 additions & 0 deletions test/sframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ TEST_CASE("SFrame Round-Trip")

// The MLS-based key derivation isn't covered by the RFC test vectors. So we
// only have round-trip tests, not known-answer tests.
#if SFRAME_ENABLE_MLS_CONTEXT
TEST_CASE("MLS Round-Trip")
{
const auto epoch_bits = 2;
Expand Down Expand Up @@ -231,6 +232,7 @@ TEST_CASE("MLS Failure after Purge")
const auto dec_ab_2 = member_b.unprotect(pt_out, enc_ab_2, metadata).unwrap();
CHECK(plaintext == to_bytes(dec_ab_2));
}
#endif // SFRAME_ENABLE_MLS_CONTEXT

TEST_CASE("SFrame Context Remove Key")
{
Expand Down Expand Up @@ -286,6 +288,7 @@ TEST_CASE("SFrame Context Remove Key - Nonexistent Key")
CHECK_NOTHROW(ctx.remove_key(KeyID(0x99)));
}

#if SFRAME_ENABLE_MLS_CONTEXT
TEST_CASE("MLS Remove Epoch")
{
const auto suite = CipherSuite::AES_GCM_128_SHA256;
Expand Down Expand Up @@ -344,3 +347,4 @@ TEST_CASE("MLS Remove Epoch")
dec = to_bytes(member_b.unprotect(pt_out, enc, metadata).unwrap());
CHECK(plaintext == dec);
}
#endif // SFRAME_ENABLE_MLS_CONTEXT
Loading