From 2a32417effc1108e8c73033e609d89abc852a619 Mon Sep 17 00:00:00 2001 From: 5HT Date: Fri, 25 Oct 2024 16:37:18 +0300 Subject: [PATCH] wip --- lib/{curves => agreement/EC}/curve.ex | 0 lib/{curves => agreement/EC}/integer.ex | 0 lib/{curves/math.ex => agreement/EC/jacobian.ex} | 0 lib/{curves => agreement/EC}/point.ex | 0 lib/agreement/GF/.gitignore | 0 lib/agreement/ML/.gitignore | 0 lib/agreement/RSA/.gitignore | 0 lib/{curves/knownCurves.ex => agreement/ecc.ex} | 0 lib/signing/ecdsa.ex | 11 ++++++++--- src/ca_enroll.erl | 7 +------ 10 files changed, 9 insertions(+), 9 deletions(-) rename lib/{curves => agreement/EC}/curve.ex (100%) rename lib/{curves => agreement/EC}/integer.ex (100%) rename lib/{curves/math.ex => agreement/EC/jacobian.ex} (100%) rename lib/{curves => agreement/EC}/point.ex (100%) create mode 100644 lib/agreement/GF/.gitignore create mode 100644 lib/agreement/ML/.gitignore create mode 100644 lib/agreement/RSA/.gitignore rename lib/{curves/knownCurves.ex => agreement/ecc.ex} (100%) diff --git a/lib/curves/curve.ex b/lib/agreement/EC/curve.ex similarity index 100% rename from lib/curves/curve.ex rename to lib/agreement/EC/curve.ex diff --git a/lib/curves/integer.ex b/lib/agreement/EC/integer.ex similarity index 100% rename from lib/curves/integer.ex rename to lib/agreement/EC/integer.ex diff --git a/lib/curves/math.ex b/lib/agreement/EC/jacobian.ex similarity index 100% rename from lib/curves/math.ex rename to lib/agreement/EC/jacobian.ex diff --git a/lib/curves/point.ex b/lib/agreement/EC/point.ex similarity index 100% rename from lib/curves/point.ex rename to lib/agreement/EC/point.ex diff --git a/lib/agreement/GF/.gitignore b/lib/agreement/GF/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/lib/agreement/ML/.gitignore b/lib/agreement/ML/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/lib/agreement/RSA/.gitignore b/lib/agreement/RSA/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/lib/curves/knownCurves.ex b/lib/agreement/ecc.ex similarity index 100% rename from lib/curves/knownCurves.ex rename to lib/agreement/ecc.ex diff --git a/lib/signing/ecdsa.ex b/lib/signing/ecdsa.ex index 4d91e7d..ca641c6 100644 --- a/lib/signing/ecdsa.ex +++ b/lib/signing/ecdsa.ex @@ -4,6 +4,12 @@ defmodule CA.ECDSA do require CA.Jacobian @moduledoc "CA/ECDSA ECC Signature (SYNRC)." + def decode_integer(bin) do + len = :erlang.size(bin) + <> = bin + int + end + def sign(message, privateKey, options) do %{hashfunc: hashfunc} = Enum.into(options, %{hashfunc: :sha256}) number = :crypto.hash(hashfunc, message) |> numberFromString() @@ -37,9 +43,8 @@ defmodule CA.ECDSA do 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) } + {:ok, {:"ECDSA-Sig-Value",r,s}} =:"PKIXAlgs-2009".decode(:"ECDSA-Sig-Value", sig) + {r, s} end def sign(file, key) do diff --git a/src/ca_enroll.erl b/src/ca_enroll.erl index bee4cb5..629ab0f 100644 --- a/src/ca_enroll.erl +++ b/src/ca_enroll.erl @@ -1,12 +1,7 @@ -module(ca_enroll). -copyright('Namdak Tonpa'). -include_lib("public_key/include/public_key.hrl"). --export([init/2, boot/0, boot/1, cwd/0, ca/1, enroll/3, service/3, maybe_service/3, echo/2, decode_integer/1]). - -decode_integer(Bin) -> - Len = byte_size(Bin), - <> = Bin, - Int. +-export([init/2, boot/0, boot/1, cwd/0, ca/1, enroll/3, service/3, maybe_service/3, echo/2]). init(Req,Opts) -> Method = cowboy_req:method(Req),