Skip to content

Commit

Permalink
Update TranscriptHash to take bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
bifurcation committed Aug 30, 2024
1 parent 91e5508 commit 23fb1c8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 39 deletions.
3 changes: 1 addition & 2 deletions include/mls/key_schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,9 @@ struct TranscriptHash
const bytes& confirmation_tag);

// Updating hashes
bytes new_confirmed(const AuthenticatedContent& content_auth) const;
bytes new_confirmed(const bytes& transcript_hash_input) const;
void set_confirmed(bytes confirmed_transcript_hash);
void update_interim(const bytes& confirmation_tag);
void update_interim(const AuthenticatedContent& content_auth);
};

bool
Expand Down
10 changes: 5 additions & 5 deletions include/mls/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,12 @@ class State
const bytes& leaf_secret,
const std::optional<CommitOpts>& opts,
const MessageOpts& msg_opts,
CommitParams params);
const CommitParams& params);

struct CommitMaterials;
CommitMaterials prepare_commit(const bytes& leaf_secret,
const std::optional<CommitOpts>& opts,
CommitParams params) const;
const CommitParams& params) const;
Welcome welcome(bool inline_tree,
const std::vector<PSKWithSecret>& psks,
const std::vector<KeyPackage>& joiners,
Expand All @@ -346,7 +346,7 @@ class State
LeafIndex committer,
const std::optional<NodeIndex>& path_secret_decrypt_node,
const std::optional<HPKECiphertext>& encrypted_path_secret,
const ExtensionList& extensions,
ExtensionList extensions,
const std::vector<PSKWithSecret>& psks,
const std::optional<bytes>& force_init_secret,
const bytes& confirmed_transcript_hash,
Expand Down Expand Up @@ -448,8 +448,8 @@ class State
ExtensionList extensions,
const bytes& confirmed_transcript_hash,
bool has_path,
const std::vector<PSKWithSecret> psks,
const std::optional<bytes> force_init_secret) const;
const std::vector<PSKWithSecret>& psks,
const std::optional<bytes>& force_init_secret) const;
};

} // namespace MLS_NAMESPACE
12 changes: 6 additions & 6 deletions lib/mls_vectors/src/mls_vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ TranscriptTestVector::TranscriptTestVector(CipherSuite suite)
sig_priv,
group_context);

const auto new_confirmed = transcript.new_confirmed(authenticated_content);
const auto new_confirmed = transcript.new_confirmed(authenticated_content.confirmed_transcript_hash_input());
transcript.set_confirmed(new_confirmed);

group_context.confirmed_transcript_hash = transcript.confirmed;
Expand All @@ -999,10 +999,8 @@ TranscriptTestVector::TranscriptTestVector(CipherSuite suite)
std::nullopt,
transcript.confirmed,
tls::marshal(group_context));
authenticated_content.set_confirmation_tag(
key_schedule_after.confirmation_tag);

transcript.update_interim(authenticated_content);
transcript.update_interim(key_schedule_after.confirmation_tag);

// Store the required data
confirmation_key = key_schedule_after.confirmation_key;
Expand All @@ -1016,9 +1014,11 @@ TranscriptTestVector::verify() const
auto transcript = TranscriptHash(cipher_suite);
transcript.interim = interim_transcript_hash_before;

const auto new_confirmed = transcript.new_confirmed(authenticated_content);
const auto new_confirmed = transcript.new_confirmed(authenticated_content.confirmed_transcript_hash_input());
transcript.set_confirmed(new_confirmed);
transcript.update_interim(authenticated_content);

const auto input_confirmation_tag = opt::get(authenticated_content.auth.confirmation_tag);
transcript.update_interim(input_confirmation_tag);

VERIFY_EQUAL(
"confirmed", transcript.confirmed, confirmed_transcript_hash_after);
Expand Down
17 changes: 3 additions & 14 deletions src/key_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,9 @@ TranscriptHash::TranscriptHash(CipherSuite suite_in,
}

bytes
TranscriptHash::new_confirmed(const AuthenticatedContent& content_auth) const
TranscriptHash::new_confirmed(const bytes& transcript_hash_input) const
{
const auto transcript =
interim + content_auth.confirmed_transcript_hash_input();
return suite.digest().hash(transcript);
return suite.digest().hash(interim + transcript_hash_input);
}

void
Expand All @@ -567,16 +565,7 @@ TranscriptHash::set_confirmed(bytes confirmed_transcript_hash)
void
TranscriptHash::update_interim(const bytes& confirmation_tag)
{
const auto transcript = confirmed + tls::marshal(confirmation_tag);
interim = suite.digest().hash(transcript);
}

void
TranscriptHash::update_interim(const AuthenticatedContent& content_auth)
{
const auto transcript =
confirmed + content_auth.interim_transcript_hash_input();
interim = suite.digest().hash(transcript);
interim = suite.digest().hash(confirmed + tls::marshal(confirmation_tag));
}

bool
Expand Down
23 changes: 11 additions & 12 deletions src/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ struct State::CommitMaterials
State::CommitMaterials
State::prepare_commit(const bytes& leaf_secret,
const std::optional<CommitOpts>& opts,
CommitParams params) const
const CommitParams& params) const
{
// Construct a proposal list from cached proposals
auto proposals = std::vector<ProposalOrRef>{};
Expand Down Expand Up @@ -769,7 +769,7 @@ std::tuple<MLSMessage, Welcome, State>
State::commit(const bytes& leaf_secret,
const std::optional<CommitOpts>& opts,
const MessageOpts& msg_opts,
CommitParams params)
const CommitParams& params)
{
// Compute the new group state
auto commit_materials = prepare_commit(leaf_secret, opts, params);
Expand All @@ -789,8 +789,8 @@ State::commit(const bytes& leaf_secret,
sign(sender, commit, msg_opts.authenticated_data, msg_opts.encrypt);

// Update confirmed transcript hash and ratchet the key schedule forward
const auto confirmed_transcript_hash =
_transcript_hash.new_confirmed(preliminary_commit);
const auto confirmed_transcript_hash = _transcript_hash.new_confirmed(
preliminary_commit.confirmed_transcript_hash_input());

const auto next = successor(commit_materials.index,
std::move(commit_materials.new_tree),
Expand Down Expand Up @@ -874,7 +874,7 @@ State::handle(const ValidatedContent& val_content,

// Commits are handled in the remainder of this method
case ContentType::commit:
return handle_commit(content_auth, cached_state, expected_params);
return handle_commit(content_auth, std::move(cached_state), expected_params);

// Any other content type in this method is an error
default:
Expand Down Expand Up @@ -1013,8 +1013,8 @@ State::handle_commit(const AuthenticatedContent& content_auth,
}

// Update the transcript hash
const auto new_confirmed_transcript_hash =
_transcript_hash.new_confirmed(content_auth);
const auto new_confirmed_transcript_hash = _transcript_hash.new_confirmed(
content_auth.confirmed_transcript_hash_input());
const auto new_confirmation_tag =
opt::get(content_auth.auth.confirmation_tag);

Expand All @@ -1034,7 +1034,7 @@ State::ratchet(TreeKEMPublicKey new_tree,
LeafIndex committer,
const std::optional<NodeIndex>& path_secret_decrypt_node,
const std::optional<HPKECiphertext>& encrypted_path_secret,
const ExtensionList& extensions,
ExtensionList extensions,
const std::vector<PSKWithSecret>& psks,
const std::optional<bytes>& force_init_secret,
const bytes& confirmed_transcript_hash,
Expand Down Expand Up @@ -1421,7 +1421,6 @@ State::apply(const std::vector<CachedProposal>& proposals) const
auto psks = resolve(psk_ids);

tree.truncate();
// TODO _tree_priv.truncate(_tree.size);
tree.set_hash_all();
return { tree, joiner_locations, psks, extensions };
}
Expand Down Expand Up @@ -2263,16 +2262,16 @@ State::successor(LeafIndex index,
ExtensionList extensions,
const bytes& confirmed_transcript_hash,
bool has_path,
const std::vector<PSKWithSecret> psks,
const std::optional<bytes> force_init_secret) const
const std::vector<PSKWithSecret>& psks,
const std::optional<bytes>& force_init_secret) const
{
// Initialize a clone with updates, clear things that shouldn't be copied
auto next = *this;
next._epoch += 1;
next._index = index;
next._tree = std::move(tree);
next._tree_priv = std::move(tree_priv);
next._extensions = extensions;
next._extensions = std::move(extensions);
next._pending_proposals.clear();

// Copy forward a resumption PSK
Expand Down

0 comments on commit 23fb1c8

Please sign in to comment.