https://github.com/azuchi/ruby_ecdsa_ext
Extension of the ecdsa gem.
https://github.com/azuchi/ruby_ecdsa_ext
ecdsa elliptic-curve
Last synced: 8 months ago
JSON representation
Extension of the ecdsa gem.
- Host: GitHub
- URL: https://github.com/azuchi/ruby_ecdsa_ext
- Owner: azuchi
- License: mit
- Created: 2023-02-24T08:33:28.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-12-27T07:24:16.000Z (over 1 year ago)
- Last Synced: 2024-12-27T07:30:23.563Z (over 1 year ago)
- Topics: ecdsa, elliptic-curve
- Language: Ruby
- Homepage:
- Size: 81.1 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Extension of the ecdsa gem
This library is an extension of the [ecdsa gem](https://github.com/DavidEGrayson/ruby_ecdsa/),
which mainly speeds up the computation of points on elliptic curves by using projective rather than affine coordinates.
This gem was not written by a cryptography expert and has not been carefully checked as with the original gem.
It is provided "as is" and it is the user's responsibility to make sure it will be suitable for the desired purpose.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'ecdsa_ext'
```
And then execute:
$ bundle install
Or install it yourself as:
$ gem install ecdsa_ext
## Usage
### Convert coordinate from affine to projective
```ruby
require 'ecdsa_ext'
require 'securerandom'
group = ECDSA::Group::Secp256k1
private_key = 1 + SecureRandom.random_number(group.order - 1)
affine_point = group.generator * private_key
#
# convert to projective point
projective_point = affine_point.to_projective
#, @x=979696094695476041658010915065787178569931130816884020506645009594358960301, @y=37562300065191370074864991137132392549749230653372621152572375247509483260540, @z=1>
```
### Create directory
```ruby
require 'ecdsa_ext'
require 'securerandom'
group = ECDSA::Group::Secp256k1
private_key = 1 + SecureRandom.random_number(group.order - 1)
projective_point = group.generator.to_projective * private_key
#, @x=979696094695476041658010915065787178569931130816884020506645009594358960301, @y=37562300065191370074864991137132392549749230653372621152572375247509483260540, @z=1>
```
### Operation
`ECDSA::Ext::ProjectivePoint` instance supports point addition, scalar multiplication and negation.
```ruby
require 'ecdsa_ext'
# addition
projective_point3 = projective_point1 + projective_point2
# multiplication
projective_point4 = projective_point3 * 123
# negation
projective_point4_neg = projective_point4.negate
```
### Convert coordinate from projective to affine
```ruby
require 'ecdsa_ext'
affine_point = projective_point4.to_affine
```
### Use jacobian coordinates
Jacobian coordinates have been supported since 0.3.0.
When using Jacobian coordinates, use `ECDSA::Ext::JacobianPoint` instead of `ECDSA::Ext::ProjectivePoint`.
In addition, `ECDSA::Point` now has a `to_jacobian` method that convert affine coordinates to jacobian coordinates.
### Apply jacobian coordinates to existing ECDSA sign/verify
If you want the existing ECDSA gem to generate and verify signatures in Jacobian coordinates,
add the following code. This code is a monkey patch to do the existing process in Jacobian coordinates.
```ruby
require 'ecdsa/ext/sign_verify'
```