Current section

23 Versions

Jump to

Compare versions

4 files changed
+14 additions
-10 deletions
  @@ -1,6 +1,6 @@
1 1 The MIT License (MIT)
2 2
3 - Copyright (c) 2016 Matt Miller
3 + Copyright (c) 2016-2017 Matt Miller, Bram Verburg
4 4
5 5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 6 of this software and associated documentation files (the "Software"), to deal
  @@ -11,4 +11,4 @@
11 11 {<<"maintainers">>,[<<"Matt Miller">>]}.
12 12 {<<"name">>,<<"ed25519">>}.
13 13 {<<"requirements">>,[]}.
14 - {<<"version">>,<<"1.0.0">>}.
14 + {<<"version">>,<<"1.0.1">>}.
  @@ -42,15 +42,19 @@ defmodule Ed25519 do
42 42 defp hash(m), do: :crypto.hash(:sha512,m)
43 43 defp hashint(m), do: m |> hash |> decodeint
44 44
45 - defp square(x), do: x * x
46 -
45 + # :crypto.mod_pow chokes on negative inputs, so we feed it positive values
46 + # only and patch up the result if necessary
47 47 defp expmod(_b,0,_m), do: 1
48 + defp expmod(b,e,m) when b > 0 do
49 + b |> :crypto.mod_pow(e,m) |> :binary.decode_unsigned
50 + end
48 51 defp expmod(b,e,m) do
49 - t = b |> expmod(div(e,2), m) |> square |> mod(m)
50 - case (e &&& 1) do
51 - 1 -> (t * b) |> mod(m)
52 - _ -> t
53 - end
52 + i = b |> abs() |> :crypto.mod_pow(e,m) |> :binary.decode_unsigned
53 + cond do
54 + mod(e, 2) == 0 -> i
55 + i == 0 -> i
56 + true -> m - i
57 + end
54 58 end
55 59
56 60 defp inv(x), do: x |> expmod(@p - 2, @p)
  @@ -3,7 +3,7 @@ defmodule Ed25519.Mixfile do
3 3
4 4 def project do
5 5 [app: :ed25519,
6 - version: "1.0.0",
6 + version: "1.0.1",
7 7 elixir: "~> 1.4",
8 8 name: "Ed25519",
9 9 source_url: "https://github.com/mwmiller/ed25519_ex",