Skip to content

Commit 2239f14

Browse files
committed
Digest computation matches
1 parent 409f5a6 commit 2239f14

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

lib/zkp/srp_chor.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ defmodule Zkp.SrpChor do
4747

4848
with SrpServer.(secret) <-
4949
SrpServer.compute_secret(n, big_a, big_b, b_secret, tok) do
50-
if SrpServer.valid_m1?(big_a, big_b, k, m1) do
50+
if SrpServer.valid_m1?(big_a, big_b, secret, m1) do
5151
SrpServer[L] ~> SrpClient
5252
SrpServer.compute_m2(big_a, m1, secret) ~> SrpClient.(m2)
5353

@@ -82,7 +82,7 @@ defmodule Zkp.SrpChor do
8282

8383
def hash_things([a]), do: String.length("(#{a})") |> IO.inspect(label: "hash(#{a})")
8484
def hash_things([a, b]), do: String.length("(#{a} #{b})") |> IO.inspect(label: "hash(#{a}, #{b})")
85-
def hash_things([a, b, c]), do: String.length("(#{a} #{b} #{c})")
85+
def hash_things([a, b, c]), do: String.length("(#{a} #{b} #{c})") |> IO.inspect(label: "hash(#{a}, #{b}, #{c})")
8686

8787
def hash_things(args) do
8888
args

lib/zkp/srp_client_impl.ex

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,25 @@ defmodule Zkp.SrpClientImpl do
88
IO.gets("[Login] username: ") |> String.trim()
99
end
1010

11-
def hash_passwd(id, salt, passwd) do
12-
hash_things([id, salt, passwd])
13-
end
14-
1511
@impl true
1612
def compute_secret(g, n, s, big_b, k, id) do
1713
passwd = IO.gets("[Login] password: ") |> String.trim()
1814

1915
# a = Enum.random(2..n)
2016
a = 7
21-
big_a = :crypto.mod_pow(g, a, n) |> as_int()
17+
big_a = :crypto.mod_pow(g, a, n)
18+
big_a = as_int(big_a)
2219
big_b = as_int(big_b)
23-
x = hash_passwd(id, s, passwd)
24-
# IO.inspect(as_int(x), label: "[client] x")
25-
mpow(g, x, n) |> as_int() |> IO.inspect(label: "[client] should match verif code")
20+
x = hash_things([id, s, passwd])
2621

27-
u = as_int(hash_things([big_a, big_b]))
28-
# u's match; x looks good
22+
u = hash_things([big_a, big_b])
2923

3024
k = as_int(k)
31-
big_b = as_int(big_b)
32-
# IO.inspect({as_int(big_b), k, g, as_int(x), a, u, n}, label: "[client] {big_b, k, g, x, a, u, n}")
33-
secret_k = mpow(as_int(big_b) - (k * as_int(mpow(g, x, n))), (a + u * as_int(x)), n) |> as_int()
34-
# IO.inspect(as_int(secret_k), label: "[client] secret_k")
25+
secret_k = mpow(as_int(big_b) - (k * as_int(mpow(g, x, n))), (a + u * as_int(x)), n)
3526

36-
IO.puts("[client] a: #{a}, A: #{big_a}, x: #{x}, u: #{u}, k: #{k}, B: #{big_b}, secret: #{secret_k}")
27+
IO.puts("[client] a: #{a}, A: #{big_a}, x: #{x}, u: #{u}, k: #{k}, B: #{big_b}, secret: #{as_int(secret_k)}")
3728

38-
m1 = hash_things([big_a, big_b, secret_k])
29+
m1 = hash_things([big_a, big_b, as_int(secret_k)]) |> IO.inspect(label: "[client] m1")
3930
{big_a, m1, secret_k}
4031
end
4132

lib/zkp/srp_server_impl.ex

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,19 @@ defmodule Zkp.SrpServerImpl do
4141
big_a = as_int(big_a)
4242
big_b = as_int(big_b)
4343
u = hash_things([big_a, big_b])
44-
# IO.inspect(as_int(u), label: "[server] u")
4544

46-
# IO.inspect({as_int(big_a), as_int(v), as_int(u), b, n}, label: "[server] {big_a, v, u, b n}")
45+
secret_k = mpow((big_a * as_int(mpow(v, u, n))), b, n)
4746

48-
secret_k = mpow((as_int(big_a) * as_int(mpow(v, u, n))), b, n) |> as_int()
47+
IO.puts("[server] A: #{big_a}, b: #{b}, B: #{big_b}, u: #{as_int(u)}, v: #{as_int(v)}, secret: #{as_int(secret_k)}")
4948

50-
# IO.inspect(as_int(secret_k), label: "[server] secret_k")
51-
big_a = as_int(big_a)
52-
big_b = as_int(big_b)
53-
u = as_int(u)
54-
v = as_int(v)
55-
56-
IO.puts("[server] A: #{big_a}, b: #{b}, B: #{big_b}, u: #{u}, v: #{v}, secret: #{secret_k}")
5749
secret_k
5850
end
5951

6052
@impl true
6153
def valid_m1?(a, b, k, m1) do
54+
b = as_int(b)
55+
k = as_int(k)
56+
IO.inspect({a, b, k, m1, hash_things([a, b, k])}, label: "[server] a b k m1 m1_verif")
6257
hash_things([a, b, k]) == m1
6358
end
6459

0 commit comments

Comments
 (0)