Skip to content

Commit

Permalink
remove hash_message hack, use deserialize_element
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Garg committed May 1, 2018
1 parent 6229ade commit 9210eaf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/hbbft.erl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ decrypt(Key, Bin) ->

-spec serialize(hbbft_data()) -> {hbbft_serialized_data(), tpke_privkey:privkey_serialized() | tpke_privkey:privkey()}.
serialize(Data) ->
%% serialize the SK if not explicitly told not to do so
%% serialize the SK unless explicitly told not to
serialize(Data, true).

-spec serialize(hbbft_data(), boolean()) -> {hbbft_serialized_data(), tpke_privkey:privkey_serialized() | tpke_privkey:privkey()}.
Expand Down Expand Up @@ -235,10 +235,9 @@ deserialize(#hbbft_serialized_data{batch_size=BatchSize,
thingtosign=ThingToSign}, SerializedSK) ->

SK = tpke_privkey:deserialize(SerializedSK),
Derp = tpke_pubkey:hash_message(tpke_privkey:public_key(SK), <<"derp">>),
NewThingToSign = case ThingToSign of
undefined -> undefined;
_ -> erlang_pbc:binary_to_element(Derp, ThingToSign)
_ -> tpke_pubkey:deserialize_element(tpke_privkey:public_key(SK), ThingToSign)
end,
#hbbft_data{secret_key=SK,
batch_size=BatchSize,
Expand Down
4 changes: 1 addition & 3 deletions src/hbbft_cc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ serialize(#cc_data{state=State, sid=SID, n=N, f=F, shares=Shares}) ->

-spec deserialize(cc_serialized_data(), tpke_privkey:privkey()) -> cc_data().
deserialize(#cc_serialized_data{state=State, sid=SID, n=N, f=F, shares=Shares}, SK) ->
%% XXX: same hack as in hbbft_utils
Yolo = tpke_pubkey:hash_message(tpke_privkey:public_key(SK), <<"yolo">>),
Element = erlang_pbc:binary_to_element(Yolo, SID),
Element = tpke_pubkey:deserialize_element(tpke_privkey:public_key(SK), SID),
#cc_data{state=State, sk=SK, sid=Element, n=N, f=F, shares=deserialize_shares(Shares, SK)}.

%% TODO: specs
Expand Down
4 changes: 1 addition & 3 deletions src/hbbft_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ share_to_binary({ShareIdx, ShareElement}) ->

-spec binary_to_share(binary(), tpke_privkey:privkey()) -> {non_neg_integer(), erlang_pbc:element()}.
binary_to_share(<<ShareIdx:8/integer-unsigned, ShareBinary/binary>>, SK) ->
%% XXX we don't have a great way to deserialize the elements yet, this is a hack
Ugh = tpke_pubkey:hash_message(tpke_privkey:public_key(SK), <<"ugh">>),
ShareElement = erlang_pbc:binary_to_element(Ugh, ShareBinary),
ShareElement = tpke_pubkey:deserialize_element(tpke_privkey:public_key(SK), ShareBinary),
{ShareIdx, ShareElement}.

%% wrap a subprotocol's outbound messages with a protocol identifier
Expand Down

0 comments on commit 9210eaf

Please sign in to comment.