Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/main_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Run clang-format style check for C/C++ programs
uses: jidicula/clang-format-action@v4.11.0
with:
clang-format-version: 16
clang-format-version: 19
include-regex: '^\./(src|include|test|cmd|lib)/.*\.(cpp|h)$'
fallback-style: 'Mozilla'

Expand Down
32 changes: 31 additions & 1 deletion include/mls/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,37 @@ struct SignaturePrivateKey
void set_public_key(CipherSuite suite);
std::string to_jwk(CipherSuite suite) const;

TLS_SERIALIZABLE(data)
/// Returns true if this key can be serialized/exported
bool exportable() const { return !_sign_func; }

/// TLS serialization - throws if key is not exportable
friend tls::ostream& operator<<(tls::ostream& str,
const SignaturePrivateKey& obj)
{
if (!obj.exportable()) {
throw std::runtime_error(
"Cannot serialize non-exportable SignaturePrivateKey");
}
return str << obj.data;
}

friend tls::istream& operator>>(tls::istream& str, SignaturePrivateKey& obj)
{
obj._sign_func = nullptr;
return str >> obj.data;
}

friend bool operator==(const SignaturePrivateKey& lhs,
const SignaturePrivateKey& rhs)
{
return lhs.data == rhs.data;
}

friend bool operator!=(const SignaturePrivateKey& lhs,
const SignaturePrivateKey& rhs)
{
return !(lhs == rhs);
}

private:
SignerFunc _sign_func;
Expand Down
11 changes: 5 additions & 6 deletions lib/hpke/src/signature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,13 @@ static const Signature&
sig_from_jwk(const std::string& jwk_json)
{
using KeyTypeAndCurve = std::tuple<std::string, std::string>;
static const auto alg_sig_map = std::map<KeyTypeAndCurve, const Signature&>
{
static const auto alg_sig_map = std::map<KeyTypeAndCurve, const Signature&>{
{ { "EC", "P-256" }, Signature::get<Signature::ID::P256_SHA256>() },
{ { "EC", "P-384" }, Signature::get<Signature::ID::P384_SHA384>() },
{ { "EC", "P-512" }, Signature::get<Signature::ID::P521_SHA512>() },
{ { "OKP", "Ed25519" }, Signature::get<Signature::ID::Ed25519>() },
{ { "EC", "P-384" }, Signature::get<Signature::ID::P384_SHA384>() },
{ { "EC", "P-512" }, Signature::get<Signature::ID::P521_SHA512>() },
{ { "OKP", "Ed25519" }, Signature::get<Signature::ID::Ed25519>() },
#if !defined(WITH_BORINGSSL)
{ { "OKP", "Ed448" }, Signature::get<Signature::ID::Ed448>() },
{ { "OKP", "Ed448" }, Signature::get<Signature::ID::Ed448>() },
#endif
// TODO(RLB): RSA
};
Expand Down
17 changes: 8 additions & 9 deletions lib/hpke/src/userinfo_vc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,17 @@ get_optional(const json& json_object, const std::string& field_name)
static const Signature&
signature_from_alg(const std::string& alg)
{
static const auto alg_sig_map = std::map<std::string, const Signature&>
{
static const auto alg_sig_map = std::map<std::string, const Signature&>{
{ "ES256", Signature::get<Signature::ID::P256_SHA256>() },
{ "ES384", Signature::get<Signature::ID::P384_SHA384>() },
{ "ES512", Signature::get<Signature::ID::P521_SHA512>() },
{ "Ed25519", Signature::get<Signature::ID::Ed25519>() },
{ "ES384", Signature::get<Signature::ID::P384_SHA384>() },
{ "ES512", Signature::get<Signature::ID::P521_SHA512>() },
{ "Ed25519", Signature::get<Signature::ID::Ed25519>() },
#if !defined(WITH_BORINGSSL)
{ "Ed448", Signature::get<Signature::ID::Ed448>() },
{ "Ed448", Signature::get<Signature::ID::Ed448>() },
#endif
{ "RS256", Signature::get<Signature::ID::RSA_SHA256>() },
{ "RS384", Signature::get<Signature::ID::RSA_SHA384>() },
{ "RS512", Signature::get<Signature::ID::RSA_SHA512>() },
{ "RS256", Signature::get<Signature::ID::RSA_SHA256>() },
{ "RS384", Signature::get<Signature::ID::RSA_SHA384>() },
{ "RS512", Signature::get<Signature::ID::RSA_SHA512>() },
};

return alg_sig_map.at(alg);
Expand Down
3 changes: 1 addition & 2 deletions lib/hpke/test/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ fips_disable(AEAD::ID id)
bool
fips_disable(Signature::ID id)
{
static const auto disabled = std::set<Signature::ID>
{
static const auto disabled = std::set<Signature::ID>{
#if !defined(WITH_BORINGSSL)
Signature::ID::Ed448,
#endif
Expand Down
12 changes: 6 additions & 6 deletions lib/hpke/test/hpke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ TEST_CASE("HPKE Round-Trip")
{
ensure_fips_if_required();

const std::vector<KEM::ID> kems
{
const std::vector<KEM::ID> kems{
KEM::ID::DHKEM_P256_SHA256, KEM::ID::DHKEM_P384_SHA384,
KEM::ID::DHKEM_P384_SHA384, KEM::ID::DHKEM_P521_SHA512,
KEM::ID::DHKEM_P384_SHA384, KEM::ID::DHKEM_P521_SHA512,
#if !defined(WITH_BORINGSSL)
KEM::ID::DHKEM_X448_SHA512,
KEM::ID::DHKEM_X448_SHA512,
#endif
#if defined(WITH_PQ)
KEM::ID::MLKEM512, KEM::ID::MLKEM768, KEM::ID::MLKEM1024,
KEM::ID::MLKEM768_P256, KEM::ID::MLKEM768_X25519, KEM::ID::MLKEM1024_P384,
KEM::ID::MLKEM512, KEM::ID::MLKEM768,
KEM::ID::MLKEM1024, KEM::ID::MLKEM768_P256,
KEM::ID::MLKEM768_X25519, KEM::ID::MLKEM1024_P384,
#endif
};
const std::vector<KDF::ID> kdfs{ KDF::ID::HKDF_SHA256,
Expand Down
19 changes: 9 additions & 10 deletions lib/hpke/test/kem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

#include "common.h"

static const auto ids = std::vector<KEM::ID>
{
static const auto ids = std::vector<KEM::ID>{
KEM::ID::DHKEM_P256_SHA256, KEM::ID::DHKEM_P384_SHA384,
KEM::ID::DHKEM_P384_SHA384, KEM::ID::DHKEM_P521_SHA512,
KEM::ID::DHKEM_P384_SHA384, KEM::ID::DHKEM_P521_SHA512,
#if !defined(WITH_BORINGSSL)
KEM::ID::DHKEM_X448_SHA512,
KEM::ID::DHKEM_X448_SHA512,
#endif
#if defined(WITH_PQ)
KEM::ID::MLKEM512, KEM::ID::MLKEM768, KEM::ID::MLKEM1024,
KEM::ID::MLKEM768_P256, KEM::ID::MLKEM1024_P384, KEM::ID::MLKEM768_X25519,
KEM::ID::MLKEM512, KEM::ID::MLKEM768,
KEM::ID::MLKEM1024, KEM::ID::MLKEM768_P256,
KEM::ID::MLKEM1024_P384, KEM::ID::MLKEM768_X25519,
#endif
};

Expand Down Expand Up @@ -52,11 +52,10 @@ TEST_CASE("AuthKEM round-trip")
{
ensure_fips_if_required();

static const auto no_auth = std::vector<KEM::ID>
{
static const auto no_auth = std::vector<KEM::ID>{
#if defined(WITH_PQ)
KEM::ID::MLKEM512, KEM::ID::MLKEM768, KEM::ID::MLKEM1024,
KEM::ID::MLKEM768_P256, KEM::ID::MLKEM1024_P384, KEM::ID::MLKEM768_X25519
KEM::ID::MLKEM512, KEM::ID::MLKEM768, KEM::ID::MLKEM1024,
KEM::ID::MLKEM768_P256, KEM::ID::MLKEM1024_P384, KEM::ID::MLKEM768_X25519
#endif
};

Expand Down
Loading
Loading