ecdsa_ext 0.1.1 → 0.2.1

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: b7deba9160e31d20d837d2fce03b555c8f9dee1cc40c1bbdb04958c0a489e1ad
4
- data.tar.gz: ec8fea9687a956a1390311257ae71b4d22bd9aea47867c8ae69310198da42deb
3
+ metadata.gz: d034afcff3fe0f7bcdd0a201387242296617c4115c8a5e5c17be9c55727aa7b5
4
+ data.tar.gz: 94ca9bd31bd199527df5e77d82bfad340d81a869675ecaec0dec2f41c63a4ae7
5
5
  SHA512:
6
- metadata.gz: 4938e0327a13cfc62fe1c009d840ebe7c8a36aac30393cd72c0729b0c985ee14d92b05aaccfd0d5d9997d3e43869529de1e7f55762c527be00908f48c63419bd
7
- data.tar.gz: 63d3a4e725d737a4ba5a625ba811b448e707a5c0cb121e7546d3b9ec51caebe3f6efa8981d4f3186918ab5c56540db33fc68500b952696394dba8a744caa7674
6
+ metadata.gz: 57ce381df7da79e9e4853c1e0f9e7a67157a49c7e6701db9076eec31f41b6e87e6e03350280c833d9b5d91c125ca3619364c96b9e621688b5f5b0ea09456f7d5
7
+ data.tar.gz: 75ecb95e6e18a751dea27a435555b6ae4dc583c93c5dda206a7a9bfd24fbda045d6a09a715f4d962060165aad0c961366977d4092743f3755e0cc04080731e20
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # EcdsaExt
1
+ # Extension of the ecdsa gem
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ecdsa_ext`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This library is an extension of the [ecdsa gem](https://github.com/DavidEGrayson/ruby_ecdsa/),
4
+ which mainly speeds up the computation of points on elliptic curves by using projective rather than affine coordinates.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ This gem was not written by a cryptography expert and has not been carefully checked as with the original gem.
7
+ It is provided "as is" and it is the user's responsibility to make sure it will be suitable for the desired purpose.
6
8
 
7
9
  ## Installation
8
10
 
@@ -22,22 +24,55 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ ### Convert coordinate from affine to projective
26
28
 
27
- ## Development
29
+ ```ruby
30
+ require 'ecdsa_ext'
31
+ require 'securerandom'
28
32
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+ group = ECDSA::Group::Secp256k1
34
+ private_key = 1 + SecureRandom.random_number(group.order - 1)
35
+ affine_point = group.generator * private_key
36
+ #<ECDSA::Point: secp256k1, 0x22a7d03cd6fec52e13d2713da6921cf8f374631ecea7d575d31c3f338a410ad, 0x530b82285b951582bc330fc0b1d26df56bf93277d1229676ab9c2d4749098a7c>
30
37
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+ # convert to projective point
39
+ projective_point = affine_point.to_projective
40
+ #<ECDSA::Ext::ProjectivePoint:0x00007f45baa7f5b0 @group=#<ECDSA::Group:secp256k1>, @x=979696094695476041658010915065787178569931130816884020506645009594358960301, @y=37562300065191370074864991137132392549749230653372621152572375247509483260540, @z=1>
41
+ ```
32
42
 
33
- ## Contributing
43
+ ### Create directory
34
44
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ecdsa_ext. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ecdsa_ext/blob/master/CODE_OF_CONDUCT.md).
45
+ ```ruby
46
+ require 'ecdsa_ext'
47
+ require 'securerandom'
36
48
 
37
- ## License
49
+ group = ECDSA::Group::Secp256k1
50
+ private_key = 1 + SecureRandom.random_number(group.order - 1)
51
+ projective_point = group.generator.to_projective * private_key
52
+ #<ECDSA::Ext::ProjectivePoint:0x00007f45baa7f5b0 @group=#<ECDSA::Group:secp256k1>, @x=979696094695476041658010915065787178569931130816884020506645009594358960301, @y=37562300065191370074864991137132392549749230653372621152572375247509483260540, @z=1>
53
+ ```
38
54
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
55
+ ### Operation
56
+
57
+ `ECDSA::Ext::ProjectivePoint` instance supports point addition, scalar multiplication and negation.
58
+
59
+ ```ruby
60
+ require 'ecdsa_ext'
40
61
 
41
- ## Code of Conduct
62
+ # addition
63
+ projective_point3 = projective_point1 + projective_point2
64
+
65
+ # multiplication
66
+ projective_point4 = projective_point3 * 123
67
+
68
+ # negation
69
+ projective_point4_neg = projective_point4.negate
70
+ ```
71
+
72
+ ### Convert coordinate from projective to affine
73
+
74
+ ```ruby
75
+ require 'ecdsa_ext'
42
76
 
43
- Everyone interacting in the EcdsaExt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ecdsa_ext/blob/master/CODE_OF_CONDUCT.md).
77
+ affine_point = projective_point4.to_affine
78
+ ```
@@ -103,11 +103,8 @@ module ECDSA
103
103
  if infinity?
104
104
  group.infinity
105
105
  else
106
- ECDSA::Point.new(
107
- group,
108
- field.mod(x * field.inverse(z)),
109
- field.mod(y * field.inverse(z))
110
- )
106
+ z_inv = field.inverse(z)
107
+ ECDSA::Point.new(group, field.mod(x * z_inv), field.mod(y * z_inv))
111
108
  end
112
109
  end
113
110
 
@@ -145,7 +142,14 @@ module ECDSA
145
142
 
146
143
  def ==(other)
147
144
  return false unless other.is_a?(ProjectivePoint)
148
- group == other.group && x == other.x && y == other.y && z == other.z
145
+ return true if infinity? && other.infinity?
146
+
147
+ lhs_x = field.mod(x * other.z)
148
+ rhs_x = field.mod(other.x * z)
149
+ lhs_y = field.mod(y * other.z)
150
+ rhs_y = field.mod(other.y * z)
151
+
152
+ lhs_x == rhs_x && lhs_y == rhs_y
149
153
  end
150
154
  end
151
155
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ECDSA
4
4
  module Ext
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecdsa_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-25 00:00:00.000000000 Z
11
+ date: 2023-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ecdsa