Skip to content

Commit

Permalink
secp384r1 logs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Oct 23, 2024
1 parent 7e59ec8 commit c7969ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions lib/curves/ecdsa.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ecdsa.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c7969ed

Please sign in to comment.