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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fdf2755e2f03cc6623c7647268b39129c98bfa2
4
- data.tar.gz: 108fddf54a5bec531c59edf61c1f8e36561cfea8
3
+ metadata.gz: db57f3625d3dd2ed4d017d7a5ac8bcfe469cc6a7
4
+ data.tar.gz: a9b590fb8e516aef2531171d95024a6f394e904e
5
5
  SHA512:
6
- metadata.gz: a1e2dca08a4adb58a31c16ed61083a24bfc176e71a2fb5e87aedbb04e8a455f3469ca5497db971108416c968994f49bd80b5b1655a475d7777fe916fec6b5994
7
- data.tar.gz: 31a9813ca2b05350f4a1e25583add234b2da74ee0862c714f9a8a6f589420e1b99fa4d89035056af44f2d2cd9bbb796bb1ec46c3caff39521d1c42c17e7bbaaa
6
+ metadata.gz: 88ed2e75f60cbdf1689dd1681c59a84eb107981493ad257a086dfad655668d553ce59fc037c7785b9ea06be34269a288df994c32cab440b46381195cfe892405
7
+ data.tar.gz: 28cb354ed7193a57a0f65d26e1f8590319cafe4bacd109520dc655764b4d0f945bf787c908ab45c97e0a15b9f0fe74972ce3d2d5f4f8bd0c42d6e0caa0246228
@@ -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
- if p2.is_infinity?
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
@@ -1,3 +1,3 @@
1
1
  module EllipticCurve
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
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.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-08 00:00:00.000000000 Z
11
+ date: 2015-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler