Skip to content

Commit

Permalink
move signature parsing out of OTP
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Oct 23, 2024
1 parent 8234062 commit db47c1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 8 additions & 1 deletion lib/curves/ecdsa.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ defmodule CA.ECDSA do
%CA.Point{ x: numberFromString(xs), y: numberFromString(ys)}
end

def signature(name) do
{:ok, sig} = :file.read_file name
{{_,[{_,r},{_,s}]},""} = :asn1rt_nif.decode_ber_tlv sig
{ :ca_enroll.decode_integer(r),
:ca_enroll.decode_integer(s) }
end

def sign(file, key) do
{:ok, msg} = :file.read_file file
{:ok, pem} = :file.read_file key
Expand All @@ -44,7 +51,7 @@ defmodule CA.ECDSA do
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), decodePointFromECPoint(public(pem)), [])
verify(msg, signature(signature_file), decodePointFromECPoint(public(pem)), [])
end

def verify(message, {r,s}, publicKey, options) do
Expand Down
7 changes: 0 additions & 7 deletions lib/ecdsa.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ defmodule CA.ECDSA.OTP do
[point, :crypto.ec_curve(:pubkey_cert_records.namedCurves(oid))])
end

def signature(name) do
{:ok, sig} = :file.read_file name
{{_,[{_,r},{_,s}]},""} = :asn1rt_nif.decode_ber_tlv sig
{ :ca_enroll.decode_integer(r),
:ca_enroll.decode_integer(s) }
end

def sign(file, priv) do
{:ok, msg} = :file.read_file file
{:ok, key} = :file.read_file priv
Expand Down

0 comments on commit db47c1d

Please sign in to comment.