summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2014-05-12 14:55:47 +0200
committerLinus Nordberg <linus@nordberg.se>2014-05-12 14:55:47 +0200
commitdb0894020b459775e7051441ee343ecd1c270883 (patch)
tree766023e90897106966e7fd60adce209c6b7d396e /src
parent942cba0d18b9fc7d692ebc49f4955ae95f65a2be (diff)
Encode signatures properly.
Diffstat (limited to 'src')
-rw-r--r--src/plop.erl49
1 files changed, 43 insertions, 6 deletions
diff --git a/src/plop.erl b/src/plop.erl
index 4b9d321..e1c1382 100644
--- a/src/plop.erl
+++ b/src/plop.erl
@@ -185,7 +185,11 @@ spt(LogID, PrivKey, #timestamped_entry{
timestamp = Timestamp,
entry_type = EntryType,
signed_entry = EntryData})),
- Signature = signhash(BinToSign, PrivKey),
+ Signature = #signature{
+ algorithm = #sig_and_hash_alg{
+ hash_alg = sha256,
+ signature_alg = ecdsa},
+ signature = signhash(BinToSign, PrivKey)},
#spt{
version = ?PLOPVERSION,
logid = LogID,
@@ -193,6 +197,7 @@ spt(LogID, PrivKey, #timestamped_entry{
signature = Signature}.
%% @doc Signed Tree Head as specified in RFC6962 section 3.2.
+-spec sth(#'ECPrivateKey'{}, ht:head(), sth_signed() | list()) -> sth().
sth(PrivKey, Tree, []) ->
sth(PrivKey, Tree, #sth_signed{timestamp = now});
sth(PrivKey, Tree, #sth_signed{version = Version, timestamp = Timestamp_in}) ->
@@ -206,7 +211,11 @@ sth(PrivKey, Tree, #sth_signed{version = Version, timestamp = Timestamp_in}) ->
timestamp = Timestamp,
tree_size = Treesize,
root_hash = Roothash})),
- Signature = signhash(BinToSign, PrivKey),
+ Signature = #signature{
+ algorithm = #sig_and_hash_alg{
+ hash_alg = sha256,
+ signature_alg = ecdsa},
+ signature = signhash(BinToSign, PrivKey)},
STH = #sth{
treesize = Treesize,
timestamp = Timestamp,
@@ -295,6 +304,21 @@ entry_type(test) -> 2.
leaf_type(timestamped_entry) -> 0;
leaf_type(test) -> 1.
+-spec hash_alg_type(hash_alg_type()) -> integer().
+hash_alg_type(none) -> 0;
+hash_alg_type(md5) -> 1;
+hash_alg_type(sha1) -> 2;
+hash_alg_type(sha224) -> 3;
+hash_alg_type(sha256) -> 4;
+hash_alg_type(sha384) -> 5;
+hash_alg_type(sha512) -> 6.
+
+-spec signature_alg_type(signature_alg_type()) -> integer().
+signature_alg_type(anonymous) -> 0;
+signature_alg_type(rsa) -> 1;
+signature_alg_type(dsa) -> 2;
+signature_alg_type(ecdsa) -> 3.
+
-spec timestamp(now | integer()) -> integer().
timestamp(Timestamp) ->
case Timestamp of
@@ -307,7 +331,8 @@ timestamp(Timestamp) ->
end.
-spec serialise(plop_entry() | timestamped_entry() | mtl() |
- spt() | spt_signed() | sth() | sth_signed()) -> iolist().
+ spt() | spt_signed() | sth() | sth_signed() |
+ sig_and_hash_alg() | signature()) -> iolist().
serialise(#plop_entry{
type = TypeAtom,
data = Data
@@ -329,8 +354,8 @@ serialise(#spt{
}) ->
[<<Version:8,
LogID/binary,
- Timestamp:64,
- Signature/binary>>];
+ Timestamp:64>>,
+ serialise(Signature)];
serialise(#spt_signed{
version = Version,
signature_type = SigtypeAtom,
@@ -366,7 +391,19 @@ serialise(#sth_signed{ % Signed Tree Head.
Sigtype:8,
Timestamp:64,
Treesize:64,
- Roothash/binary>>].
+ Roothash/binary>>];
+serialise(#sig_and_hash_alg{
+ hash_alg = HashAlgType,
+ signature_alg = SignatureAlgType
+ }) ->
+ HashAlg = hash_alg_type(HashAlgType),
+ SignatureAlg = signature_alg_type(SignatureAlgType),
+ [<<HashAlg:8, SignatureAlg:8>>];
+serialise(#signature{
+ algorithm = Algorithm,
+ signature = Signature
+ }) ->
+ [serialise(Algorithm), <<Signature/binary>>].
%%%%%%%%%%%%%%%%%%%%
%% Tests.