elliptic_curve 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/lib/elliptic_curve.rb +23 -17
- data/lib/elliptic_curve/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db57f3625d3dd2ed4d017d7a5ac8bcfe469cc6a7
|
4
|
+
data.tar.gz: a9b590fb8e516aef2531171d95024a6f394e904e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88ed2e75f60cbdf1689dd1681c59a84eb107981493ad257a086dfad655668d553ce59fc037c7785b9ea06be34269a288df994c32cab440b46381195cfe892405
|
7
|
+
data.tar.gz: 28cb354ed7193a57a0f65d26e1f8590319cafe4bacd109520dc655764b4d0f945bf787c908ab45c97e0a15b9f0fe74972ce3d2d5f4f8bd0c42d6e0caa0246228
|
data/lib/elliptic_curve.rb
CHANGED
@@ -35,6 +35,28 @@ module EllipticCurve
|
|
35
35
|
return t
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
# Adds two points together - searches the third point on a line between the two
|
40
|
+
# points
|
41
|
+
def add(p1, p2)
|
42
|
+
if p2.is_infinity?
|
43
|
+
return p1
|
44
|
+
elsif p1.is_infinity?
|
45
|
+
return p2
|
46
|
+
elsif p1.x == p2.x
|
47
|
+
if p1.y == -p2.y
|
48
|
+
return P.new(ec, Float::INFINITY, Float::INFINITY)
|
49
|
+
else
|
50
|
+
k = (3 * p1.x**2+@a) * get_inv_p(2 * p1.y)
|
51
|
+
x = (k**2 - 2 * p1.x) % @p
|
52
|
+
return P.new(self, x, (k*(p1.x-x)-p1.y) % @p)
|
53
|
+
end
|
54
|
+
else
|
55
|
+
k = (p2.y-p1.y) * get_inv_p(p2.x-p1.x)
|
56
|
+
x = (k**2-p1.x-p2.x) % @p
|
57
|
+
return P.new(self, x, (k * (p1.x-x)-p1.y) % @p)
|
58
|
+
end
|
59
|
+
end
|
38
60
|
end
|
39
61
|
|
40
62
|
# A point on an elliptic curve
|
@@ -55,23 +77,7 @@ module EllipticCurve
|
|
55
77
|
|
56
78
|
# Adds p2 to self
|
57
79
|
def +(p2)
|
58
|
-
|
59
|
-
return self
|
60
|
-
elsif is_infinity?
|
61
|
-
return p2
|
62
|
-
elsif @x == p2.x
|
63
|
-
if @y == -p2.y
|
64
|
-
return P.new(ec, Float::INFINITY, Float::INFINITY)
|
65
|
-
else
|
66
|
-
k = (3 * @x**2+@ec.a) * @ec.get_inv_p(2 * @y)
|
67
|
-
x = (k**2 - 2 * @x) % @ec.p
|
68
|
-
return P.new(@ec, x, (k*(@x-x)-@y) % @ec.p)
|
69
|
-
end
|
70
|
-
else
|
71
|
-
k = (p2.y-@y) * @ec.get_inv_p(p2.x-@x)
|
72
|
-
x = (k**2-@x-p2.x) % @ec.p
|
73
|
-
return P.new(@ec, x, (k * (@x-x)-@y) % @ec.p)
|
74
|
-
end
|
80
|
+
@ec.add(self, p2)
|
75
81
|
end
|
76
82
|
|
77
83
|
# Multiplies itself by d
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elliptic_curve
|
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
|
- Linus Gasser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|