ecc 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -35
- data/lib/ecc.rb +2 -4
- data/lib/ecc/curve.rb +37 -0
- data/lib/ecc/point.rb +72 -0
- data/lib/ecc/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d98d09dff9b8e79d2f2bf3e8586670af8b88d28
|
4
|
+
data.tar.gz: cd0ccb2dc012c5c2a0bf4537c6c0bc3bd189984d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c5e15c949de7f31ad37440fcaae68172d1b6ef7f9de0755b5a13bbe6c9075176cf80652bb9c7628a5e369cbe6274b6f1c785d5ca1942e2fd68495b514d02b06
|
7
|
+
data.tar.gz: 3dc436af37685bae1dab518d97ad08ca5587914bc16448e2b682dc233bc8e0974eedc87e60d3714ac5260d6a25c98b027eff6689e21a9e0f63409b28448f5eaa
|
data/README.md
CHANGED
@@ -1,43 +1,17 @@
|
|
1
1
|
# Ecc
|
2
2
|
|
3
|
-
|
3
|
+
## Install
|
4
4
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'ecc'
|
13
5
|
```
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install ecc
|
6
|
+
gem install ecc
|
7
|
+
```
|
22
8
|
|
23
9
|
## Usage
|
24
10
|
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
11
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ecc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
-
|
37
|
-
## License
|
38
|
-
|
39
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
40
|
-
|
41
|
-
## Code of Conduct
|
42
|
-
|
43
|
-
Everyone interacting in the Ecc project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ecc/blob/master/CODE_OF_CONDUCT.md).
|
12
|
+
```
|
13
|
+
ecc = Ecc::Curve.new(a = 3, b = 4, fp = 7)
|
14
|
+
a = Ecc::Point.new(ecc, 0, 2)
|
15
|
+
b = Ecc::Point.new(ecc, 0, 2)
|
16
|
+
puts a + b
|
17
|
+
```
|
data/lib/ecc.rb
CHANGED
data/lib/ecc/curve.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Ecc
|
2
|
+
|
3
|
+
class Curve
|
4
|
+
|
5
|
+
attr_accessor :a, :b, :fp
|
6
|
+
|
7
|
+
def initialize(a, b, fp)
|
8
|
+
|
9
|
+
@a = a
|
10
|
+
@b = b
|
11
|
+
@fp = fp
|
12
|
+
|
13
|
+
raise "not elliptic curve" if 4 * (@a ** 3) + 27 * (@b ** 2) == 0
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def belong?(x,y)
|
18
|
+
|
19
|
+
return (y ** 2) % @fp == (x ** 3 + @a * x + @b) % @fp
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def point_order(x, y)
|
24
|
+
|
25
|
+
p2 = Point.new(self, x, y)
|
26
|
+
|
27
|
+
i = 2
|
28
|
+
loop do
|
29
|
+
break if p * i == p2
|
30
|
+
i += 1
|
31
|
+
end
|
32
|
+
i
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/ecc/point.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Ecc
|
2
|
+
class Point
|
3
|
+
|
4
|
+
attr_accessor :x, :y
|
5
|
+
|
6
|
+
def initialize(curve, x, y)
|
7
|
+
|
8
|
+
if curve.class != Curve
|
9
|
+
raise "1st argument type error"
|
10
|
+
end
|
11
|
+
|
12
|
+
@curve = curve
|
13
|
+
@x = x
|
14
|
+
@y = y
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
|
20
|
+
"(#{@x}, #{@y})"
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def zero?
|
25
|
+
|
26
|
+
@x == 0 and @y == 0
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def ==(other)
|
31
|
+
|
32
|
+
@x == other.x and @y == other.y
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def +(other)
|
37
|
+
|
38
|
+
u = Point.new(@ecc, self) if u.class != Point
|
39
|
+
v = Point.new(@ecc, other) if v.class != Point
|
40
|
+
|
41
|
+
return u if v.zero?
|
42
|
+
return v if u.zero?
|
43
|
+
|
44
|
+
lambda = nil
|
45
|
+
|
46
|
+
if u != v
|
47
|
+
lambda = ((v.y - u.y) * (((v.x - u.x) ** (@fp - 2)) % @fp)) % @fp
|
48
|
+
else
|
49
|
+
lambda = ((3 * u.x ** 2 + @a) * (((2 * u.y) ** (@fp - 2)) % @fp)) % @fp
|
50
|
+
end
|
51
|
+
|
52
|
+
x3 = lambda ** 2 - u.x - v.x
|
53
|
+
y3 = lambda * (u.x - x3) - u.y
|
54
|
+
Point.new(@ecc, [x3 % @fp, y3 % @fp])
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def *(d)
|
59
|
+
|
60
|
+
sum = Point.new(@ecc, self)
|
61
|
+
|
62
|
+
(d - 1).times do
|
63
|
+
sum = sum + self
|
64
|
+
end
|
65
|
+
|
66
|
+
sum
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/lib/ecc/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chihiro Hasegawa
|
@@ -71,6 +71,8 @@ files:
|
|
71
71
|
- bin/setup
|
72
72
|
- ecc.gemspec
|
73
73
|
- lib/ecc.rb
|
74
|
+
- lib/ecc/curve.rb
|
75
|
+
- lib/ecc/point.rb
|
74
76
|
- lib/ecc/version.rb
|
75
77
|
homepage: https://alicemacs.com
|
76
78
|
licenses:
|
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
94
|
version: '0'
|
93
95
|
requirements: []
|
94
96
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.6.
|
97
|
+
rubygems_version: 2.6.8
|
96
98
|
signing_key:
|
97
99
|
specification_version: 4
|
98
100
|
summary: Elliptic Curve Cryptography for CTFer
|