Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Oct 25, 2024
1 parent 7000913 commit 2a32417
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 9 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added lib/agreement/GF/.gitignore
Empty file.
Empty file added lib/agreement/ML/.gitignore
Empty file.
Empty file added lib/agreement/RSA/.gitignore
Empty file.
File renamed without changes.
11 changes: 8 additions & 3 deletions lib/signing/ecdsa.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<<int::size(len)-big-integer-signed-unit(8)>> = bin
int
end

def sign(message, privateKey, options) do
%{hashfunc: hashfunc} = Enum.into(options, %{hashfunc: :sha256})
number = :crypto.hash(hashfunc, message) |> numberFromString()
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions src/ca_enroll.erl
Original file line number Diff line number Diff line change
@@ -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),
<<Int:Len/signed-unit:8>> = 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),
Expand Down

0 comments on commit 2a32417

Please sign in to comment.