aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/keys.ex
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-10-10 16:48:38 +0200
committerAlex Auvolat <alex@adnab.me>2018-10-10 16:48:38 +0200
commit7bdd60c7f99df417b2589f0e99ff16abc8e925c5 (patch)
tree8508404c74bf91c453f4679363dc25680de02b56 /shard/lib/keys.ex
parent1ee9c3fa6d4259d63685aea95d23b515f59a74cf (diff)
downloadshard-7bdd60c7f99df417b2589f0e99ff16abc8e925c5.tar.gz
shard-7bdd60c7f99df417b2589f0e99ff16abc8e925c5.zip
Connecting works, but the rest probably doesnt
Diffstat (limited to 'shard/lib/keys.ex')
-rw-r--r--shard/lib/keys.ex20
1 files changed, 13 insertions, 7 deletions
diff --git a/shard/lib/keys.ex b/shard/lib/keys.ex
index fe63148..d021242 100644
--- a/shard/lib/keys.ex
+++ b/shard/lib/keys.ex
@@ -4,7 +4,6 @@ defmodule Shard.Keys do
"""
use Agent
- require Salty.Sign.Ed25519, as: Sign
require Logger
@key_db [Application.get_env(:shard, :data_path), "key_db"] |> Path.join |> String.to_atom
@@ -20,7 +19,7 @@ defmodule Shard.Keys do
end
defp gen_keypair(suffix, n \\ 0) do
- {:ok, pk, sk} = Sign.keypair
+ %{public: pk, secret: sk} = :enacl.sign_keypair
if rem(n, 10000) == 0 do
Logger.info "#{n}... expected #{:math.pow(256, byte_size(suffix))}"
end
@@ -51,7 +50,7 @@ defmodule Shard.Keys do
{pk, sk} = gen_keypair(Application.get_env(:shard, :identity_suffix))
Logger.info "New identity: #{pk|>Base.encode16}"
:dets.insert @key_db, {pk, sk}
- Shard.Manager.Manifest.start %SApp.Identity.Manifest{pk: pk}
+ Shard.Manifest.start %SApp.Identity.Manifest{pk: pk}
pk
end
@@ -72,7 +71,7 @@ defmodule Shard.Keys do
def sign(pk, bin) do
case :dets.lookup @key_db, pk do
[{^pk, sk}] ->
- Sign.sign(bin, sk)
+ :enacl.sign(bin, sk)
_ -> {:error, :not_found}
end
end
@@ -84,7 +83,7 @@ defmodule Shard.Keys do
"""
def open(pk, signed) do
if valid_identity_pk? pk do
- Sign.open(signed, pk)
+ :enacl.sign_open(signed, pk)
else
{:error, :invalid_pk_suffix}
end
@@ -97,6 +96,13 @@ defmodule Shard.Keys do
end
end
+ def get_sk(pk) do
+ case :dets.lookup @key_db, pk do
+ [{^pk, sk}] -> sk
+ _ -> nil
+ end
+ end
+
@doc"""
Lookup the secret key for a pk and generate a detached signature for a message.
@@ -108,7 +114,7 @@ defmodule Shard.Keys do
def sign_detached(pk, bin) do
case :dets.lookup @key_db, pk do
[{^pk, sk}] ->
- Sign.sign_detached(bin, sk)
+ :enacl.sign_detached(bin, sk)
_ -> {:error, :not_found}
end
end
@@ -120,7 +126,7 @@ defmodule Shard.Keys do
"""
def verify(pk, bin, sign) do
if valid_identity_pk? pk do
- Sign.verify_detached(sign, bin, pk)
+ :enacl.sign_verify_detached(sign, bin, pk)
else
{:error, :invalid_pk_suffix}
end