Skip to content

Commit bc11db7

Browse files
committed
feat: support ECDSA with secp256k1 curve and SHA256
1 parent 0774ef8 commit bc11db7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/openssl/signature_algorithm/ecdsa.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def verify(*args)
4545
ACCEPTED_PARAMETERS = [
4646
{ curve: "prime256v1", hash_function: "SHA256" },
4747
{ curve: "secp384r1", hash_function: "SHA384" },
48-
{ curve: "secp521r1", hash_function: "SHA512" }
48+
{ curve: "secp521r1", hash_function: "SHA512" },
49+
{ curve: "secp256k1", hash_function: "SHA256" }
4950
].freeze
5051

5152
attr_reader :curve, :hash_function

spec/openssl/signature_algorithm/ecdsa_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,23 @@
133133
end
134134
end
135135

136+
context "secp256k1 curve" do
137+
let(:algorithm_parameters) { { curve: "secp256k1" } }
138+
139+
it "picks SHA256" do
140+
expect(signer_algorithm.hash_function).to eq("SHA256")
141+
end
142+
143+
it "works" do
144+
# Signer sends verify key to Verifier
145+
verify_key_string = signing_key.verify_key.serialize
146+
147+
# Verifier
148+
verifier_algorithm.verify_key = OpenSSL::SignatureAlgorithm::ECDSA::VerifyKey.deserialize(verify_key_string)
149+
expect(verifier_algorithm.verify(signature, to_be_signed)).to be_truthy
150+
end
151+
end
152+
136153
context "when signer and verifier algorithms are different" do
137154
let(:signer_algorithm) { OpenSSL::SignatureAlgorithm::ECDSA.new(curve: "secp384r1") }
138155
let(:verifier_algorithm) { OpenSSL::SignatureAlgorithm::ECDSA.new(curve: "secp521r1") }

0 commit comments

Comments
 (0)