ecdsa_ext 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 344f77af4186a6c073efd7ceb86c1023f9395921e360a6239e6443aeaf31c957
4
- data.tar.gz: e9a32a697a607c61dd7f7993975eea458bfb09ccd1445ebe9715809b6c3620d5
3
+ metadata.gz: 49c7d6aa8f97890fc13a7648051ca3c232cd2bdf35dd5e669c071e6fb8dd3e58
4
+ data.tar.gz: 576286bd095cde15807d3512cbe57e08c10c8936549b4280c854abf29ee1a12b
5
5
  SHA512:
6
- metadata.gz: b45f1ef8661a6b1a6a3b222f29b8ed5b95dbf90576040bc6cef13f295b496017508867d1ae0a6ef14c51310d349e6b01d881ba9e8f151b5fa01bc02bb6f04093
7
- data.tar.gz: e5717cb07126434a13051d760a9b2c797f6834d7e95a31a2ec433128480f55a40b2cf8e4d336913781319858e0fc7de30a00832bd3810a624a67498a9cab08ef
6
+ metadata.gz: 1209c40701adcb12a716d70914ce4c03ec4bb92cf6e1df4b628ff1d62944aa0cbf5f7172c7ad45679e04fa376baca65e87d1e7e97ce9202315e0312e5b165b90
7
+ data.tar.gz: 010464b3223ba96790714b0c705661bd8445acc780e95d28de73137c42b3dbf592e9a5d0a9c1fcdec91f0e4276d9cb862cc258280d0ac2d5d8139f8dbf3f98e4
data/.rubocop.yml CHANGED
@@ -17,5 +17,6 @@ Style/WhileUntilModifier:
17
17
  Enabled: false
18
18
  Naming/MethodParameterName:
19
19
  Enabled: false
20
- RSpec/FilePath:
21
- Enabled: false
20
+ RSpec/SpecFilePathFormat:
21
+ Exclude:
22
+ - 'spec/ecdsa/ext/point_spec.rb'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-3.3.0
1
+ ruby-4.0.0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.2] - 2026-08-07
4
+
5
+ - Fix a timing leak of the ephemeral key's bit length in `ECDSA.sign` by padding the scalar with the group order
6
+ - Check r and s against the range [1, n-1] (group order) instead of the curve's prime field in `ECDSA.check_signature!`
7
+ - Fix `NoMethodError` when comparing an infinity point with a non-infinity point via `==`
8
+
3
9
  ## [0.1.0] - 2023-02-23
4
10
 
5
11
  - Initial release
data/Gemfile CHANGED
@@ -14,4 +14,10 @@ gem 'prettier', '4.0.3'
14
14
  gem 'rubocop-rake'
15
15
  gem 'rubocop-rspec'
16
16
 
17
- gem 'benchmark-ips'
17
+ gem 'benchmark-ips'
18
+
19
+ # Bundled gems removed from default gems in Ruby 3.5/4.0.
20
+ gem 'base64'
21
+ gem 'benchmark'
22
+ gem 'ostruct'
23
+ gem 'racc'
@@ -71,6 +71,7 @@ module ECDSA
71
71
  def ==(other)
72
72
  return false unless other.is_a?(JacobianPoint)
73
73
  return true if infinity? && other.infinity?
74
+ return false if infinity? || other.infinity?
74
75
 
75
76
  zz = field.square(z)
76
77
  other_zz = field.square(other.z)
@@ -68,6 +68,7 @@ module ECDSA
68
68
  def ==(other)
69
69
  return false unless other.is_a?(ProjectivePoint)
70
70
  return true if infinity? && other.infinity?
71
+ return false if infinity? || other.infinity?
71
72
 
72
73
  lhs_x = field.mod(x * other.z)
73
74
  rhs_x = field.mod(other.x * z)
@@ -5,7 +5,12 @@ module ECDSA
5
5
  def self.sign(group, private_key, digest, temporary_key)
6
6
  # Second part of step 1: Select ephemeral elliptic curve key pair
7
7
  # temporary_key was already selected for us by the caller
8
- r_point = (group.generator.to_jacobian * temporary_key).to_affine
8
+ # Pad the scalar with the group order so that its bit length is fixed,
9
+ # mitigating a timing leak of the bit length of temporary_key.
10
+ # Since (k + i * n)G = kG, this does not change the result.
11
+ k = temporary_key + group.order
12
+ k += group.order if k.bit_length == group.order.bit_length
13
+ r_point = (group.generator.to_jacobian * k).to_affine
9
14
 
10
15
  # Steps 2 and 3
11
16
  point_field = PrimeField.new(group.order)
@@ -29,13 +34,13 @@ module ECDSA
29
34
 
30
35
  def self.check_signature!(public_key, digest, signature)
31
36
  group = public_key.group
32
- field = group.field
37
+ point_field = PrimeField.new(group.order)
33
38
 
34
- # Step 1: r and s must be in the field and non-zero
35
- unless field.include?(signature.r)
39
+ # Step 1: r and s must be in the range [1, n-1].
40
+ unless point_field.include?(signature.r)
36
41
  raise InvalidSignatureError, "Invalid signature: r is not in the field."
37
42
  end
38
- unless field.include?(signature.s)
43
+ unless point_field.include?(signature.s)
39
44
  raise InvalidSignatureError, "Invalid signature: s is not in the field."
40
45
  end
41
46
  if signature.r.zero?
@@ -51,7 +56,6 @@ module ECDSA
51
56
  e = normalize_digest(digest, group.bit_length)
52
57
 
53
58
  # Step 4
54
- point_field = PrimeField.new(group.order)
55
59
  s_inverted = point_field.inverse(signature.s)
56
60
  u1 = point_field.mod(e * s_inverted)
57
61
  u2 = point_field.mod(signature.r * s_inverted)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ECDSA
4
4
  module Ext
5
- VERSION = "0.5.1"
5
+ VERSION = "0.5.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecdsa_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-02-08 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: ecdsa
@@ -61,7 +60,6 @@ metadata:
61
60
  homepage_uri: https://github.com/azuchi/ruby_ecdsa_ext
62
61
  source_code_uri: https://github.com/azuchi/ruby_ecdsa_ext
63
62
  changelog_uri: https://github.com/azuchi/ruby_ecdsa_ext
64
- post_install_message:
65
63
  rdoc_options: []
66
64
  require_paths:
67
65
  - lib
@@ -76,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
74
  - !ruby/object:Gem::Version
77
75
  version: '0'
78
76
  requirements: []
79
- rubygems_version: 3.4.1
80
- signing_key:
77
+ rubygems_version: 4.0.3
81
78
  specification_version: 4
82
79
  summary: Extension of the ecdsa gem.
83
80
  test_files: []