ecc 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: 4d98d09dff9b8e79d2f2bf3e8586670af8b88d28
4
- data.tar.gz: cd0ccb2dc012c5c2a0bf4537c6c0bc3bd189984d
3
+ metadata.gz: 36b895b4f9fa437cfe648d0c07b647e743c66959
4
+ data.tar.gz: e850dc2713412f5c8c67616d377bce9a93b6674e
5
5
  SHA512:
6
- metadata.gz: 0c5e15c949de7f31ad37440fcaae68172d1b6ef7f9de0755b5a13bbe6c9075176cf80652bb9c7628a5e369cbe6274b6f1c785d5ca1942e2fd68495b514d02b06
7
- data.tar.gz: 3dc436af37685bae1dab518d97ad08ca5587914bc16448e2b682dc233bc8e0974eedc87e60d3714ac5260d6a25c98b027eff6689e21a9e0f63409b28448f5eaa
6
+ metadata.gz: a1d8229f6e2b4e8b8525f9e04b34087bb5625b59e34aca41a1a594f3bb73ad5cf0fbb3002e8093c30caaa43cbc95cbcc62c901e82b59d74213c809a128ac4d3e
7
+ data.tar.gz: 8d897df94b8762ff77da808e5f5ef1f3cb4dad85362c0550624fb3998464a2b3fc8f0262809ba31c6c9b14307e17b0dcd03765b0388fdb2634e5f64e8404e9b5
data/README.md CHANGED
@@ -14,4 +14,6 @@ ecc = Ecc::Curve.new(a = 3, b = 4, fp = 7)
14
14
  a = Ecc::Point.new(ecc, 0, 2)
15
15
  b = Ecc::Point.new(ecc, 0, 2)
16
16
  puts a + b
17
+ c = a * 2
18
+ puts c
17
19
  ```
@@ -1,4 +1,5 @@
1
1
  module Ecc
2
+
2
3
  class Point
3
4
 
4
5
  attr_accessor :x, :y
@@ -6,7 +7,7 @@ module Ecc
6
7
  def initialize(curve, x, y)
7
8
 
8
9
  if curve.class != Curve
9
- raise "1st argument type error"
10
+ raise "1st argument type error: "
10
11
  end
11
12
 
12
13
  @curve = curve
@@ -35,29 +36,30 @@ module Ecc
35
36
 
36
37
  def +(other)
37
38
 
38
- u = Point.new(@ecc, self) if u.class != Point
39
- v = Point.new(@ecc, other) if v.class != Point
40
-
39
+ u = self
40
+ v = other
41
+
41
42
  return u if v.zero?
42
43
  return v if u.zero?
43
44
 
44
- lambda = nil
45
-
45
+ t = 0
46
+
46
47
  if u != v
47
- lambda = ((v.y - u.y) * (((v.x - u.x) ** (@fp - 2)) % @fp)) % @fp
48
+ t = ((v.y - u.y) * (((v.x - u.x) ** (@curve.fp - 2)) % @curve.fp)) % @curve.fp
48
49
  else
49
- lambda = ((3 * u.x ** 2 + @a) * (((2 * u.y) ** (@fp - 2)) % @fp)) % @fp
50
+ t = ((3 * u.x ** 2 + @curve.a) * (((2 * u.y) ** (@curve.fp - 2)) % @curve.fp)) % @curve.fp
50
51
  end
51
52
 
52
- x3 = lambda ** 2 - u.x - v.x
53
- y3 = lambda * (u.x - x3) - u.y
54
- Point.new(@ecc, [x3 % @fp, y3 % @fp])
53
+ x3 = t ** 2 - u.x - v.x
54
+ y3 = t * (u.x - x3) - u.y
55
+
56
+ Point.new(@curve, x3 % @curve.fp, y3 % @curve.fp)
55
57
 
56
58
  end
57
59
 
58
60
  def *(d)
59
61
 
60
- sum = Point.new(@ecc, self)
62
+ sum = self
61
63
 
62
64
  (d - 1).times do
63
65
  sum = sum + self
@@ -1,3 +1,3 @@
1
1
  module Ecc
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chihiro Hasegawa