diff --git a/lib/curves/ecdsa.ex b/lib/curves/ecdsa.ex index 84f7e38..8da26ca 100644 --- a/lib/curves/ecdsa.ex +++ b/lib/curves/ecdsa.ex @@ -20,26 +20,25 @@ defmodule CA.ECDSA do def public(bin), do: :public_key.pem_entry_decode(hd(:public_key.pem_decode(bin))) def numberFromString(string) do - Base.encode16(string) - |> Integer.parse(16) - |> (fn {parsedInt, ""} -> parsedInt end).() + Base.encode16(string) + |> Integer.parse(16) + |> (fn {parsedInt, ""} -> parsedInt end).() end - def decodeIntegerFromECPoint(ec) do + def decodePointFromECPoint(ec) do {{:ECPoint, bin2}, {:namedCurve, oid}} = ec bin = :binary.part(bin2,1,:erlang.size(bin2)-1) curve = CA.KnownCurves.getCurveByOid(oid) baseLength = CA.Curve.getLength(curve) xs = :binary.part(bin, 0, baseLength) ys = :binary.part(bin, baseLength, :erlang.size(bin) - baseLength) - point = %CA.Point{ x: numberFromString(xs), y: numberFromString(ys)} - point + %CA.Point{ x: numberFromString(xs), y: numberFromString(ys)} end def verify(file, signature_file, pub) do {:ok, msg} = :file.read_file file {:ok, pem} = :file.read_file pub - verify(msg, CA.ECDSA.OTP.signature(signature_file), decodeIntegerFromECPoint(public(pem)), []) + verify(msg, CA.ECDSA.OTP.signature(signature_file), decodePointFromECPoint(public(pem)), []) end def verify(message, {r,s}, publicKey, options) do diff --git a/lib/ecdsa.ex b/lib/ecdsa.ex index da3e582..d36870d 100644 --- a/lib/ecdsa.ex +++ b/lib/ecdsa.ex @@ -7,6 +7,7 @@ defmodule CA.ECDSA.OTP do # openssl dgst -sha256 -sign $client.key mix.exs > mix.sig # openssl dgst -sha256 -verify $client.pub -signature mix.sig mix.exs # CA.ECDSA.verify "mix.exs", "mix.sig", "#{client}.pub" + # CA.ECDSA.OTP.verify "mix.exs", "mix.sig", "#{client}.pub" def signBin(msg, priv) do CA."ECPrivateKey"(privateKey: point, parameters: {:namedCurve, oid}) = priv @@ -16,7 +17,6 @@ defmodule CA.ECDSA.OTP do def verifyBin(msg, sig, pub) do {CA."ECPoint"(point: point), {:namedCurve, oid}} = pub - :io.format 'oid: ~p~n', [oid] :crypto.verify(:ecdsa, :sha256, msg, sig, [point, :crypto.ec_curve(:pubkey_cert_records.namedCurves(oid))]) end