cf-ruby-libecp 0.1.3 → 0.1.4

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/libecp.rb +24 -22
  3. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4f27c3a6c06808402180260ca2403df1b936fef
4
- data.tar.gz: 213418a4289f4a74d24070d629de76599f329bba
3
+ metadata.gz: 5dcfb0c06bc9cc0ad5dadf35f7b2571a5edc24c4
4
+ data.tar.gz: 74386da86512de41b0e8495645f752e7a0911c8a
5
5
  SHA512:
6
- metadata.gz: e8cf6270d559c4d8c555905c92a8cb91d95c61ab96612049298a89fc2884b7700ddbe7aee6c448edea925fef1c41c6aca5c3759185058591d8f0d932e4539f1d
7
- data.tar.gz: 51e11d81fdaa98ca73541b8b663fe185c26f14e48c2eace7cc5db9d969a33979323470f72cc5adbaf7fb1738e4128fab7851f0baff02197c7e3244e5d39437b0
6
+ metadata.gz: 5d669aa4b09bcb31e1842e04e1c1bf41784a1b08a86e92c53ff75e8238548d1c9b2300cbba91e5bbe53bd31f7117536c2fd19d14edeb084c0b78360d0942ae69
7
+ data.tar.gz: 49bfb6006923c877b2cffb459ca692ed9b1acdc05f61af11bdbc7ce36e94c14dc637c04cebb7082b1986c46eeedd3ae214e5c8620f074664bee9d4f6b02e1211
data/lib/libecp.rb CHANGED
@@ -6,29 +6,30 @@ require "securerandom"
6
6
 
7
7
  module LibEcp
8
8
  extend FFI::Library
9
- # load the C++ shared library libecp.so
9
+
10
+ # Load the C++ shared library libecp.so
10
11
  ffi_lib Gem.find_files("libecp.so")[0]
11
12
 
12
- # attached methods from the libecp C++ library
13
+ # Attached methods from the libecp C++ library
13
14
  attach_function :ecp_pubkey_u8, [:pointer, :buffer_in, :buffer_in, :buffer_in, :buffer_in, :size_t], :void
14
15
  attach_function :ecp_sign_u8, [:pointer, :pointer, :buffer_in, :buffer_in, :buffer_in, :buffer_in, :buffer_in, :buffer_in, :size_t], :void
15
16
  attach_function :ecp_verify_u8, [:buffer_in, :buffer_in, :buffer_in, :buffer_in, :buffer_in, :buffer_in, :buffer_in, :buffer_in, :size_t], :bool
16
17
 
17
- # get the byte string of a, G, p and n
18
- p="\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE\xFF\xFF\xE5m".force_encoding("ASCII-8BIT")
19
- a="\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".force_encoding("ASCII-8BIT")
20
- g="\x00\xA1E[3M\xF0\x99\xDF0\xFC(\xA1i\xA4g\xE9\xE4pu\xA9\x0F~e\x0E\xB6\xB7\xA4\\\x00~\b\x9F\xED\x7F\xBA4B\x82\xCA\xFB\xD6\xF7\xE3\x19\xF7\xC0\xB0\xBDY\xE2\xCAK\xDBUma\xA5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01".force_encoding("ASCII-8BIT")
21
- n="\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xDC\xE8\xD2\xECa\x84\xCA\xF0\xA9qv\x9F\xB1\xF7".force_encoding("ASCII-8BIT")
18
+ # Get the byte string of a, g, p and n
19
+ p = "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE\xFF\xFF\xE5m".force_encoding("ASCII-8BIT")
20
+ a = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".force_encoding("ASCII-8BIT")
21
+ g = "\x00\xA1E[3M\xF0\x99\xDF0\xFC(\xA1i\xA4g\xE9\xE4pu\xA9\x0F~e\x0E\xB6\xB7\xA4\\\x00~\b\x9F\xED\x7F\xBA4B\x82\xCA\xFB\xD6\xF7\xE3\x19\xF7\xC0\xB0\xBDY\xE2\xCAK\xDBUma\xA5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01".force_encoding("ASCII-8BIT")
22
+ n = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xDC\xE8\xD2\xECa\x84\xCA\xF0\xA9qv\x9F\xB1\xF7".force_encoding("ASCII-8BIT")
22
23
 
23
- #create the buffers
24
+ # Create the buffers
24
25
  @@pb = FFI::MemoryPointer.new(:char, 29)
25
- @@pb.put_bytes(0,p)
26
+ @@pb.put_bytes(0, p)
26
27
  @@ab = FFI::MemoryPointer.new(:char, 29)
27
- @@ab.put_bytes(0,a)
28
+ @@ab.put_bytes(0, a)
28
29
  @@gb = FFI::MemoryPointer.new(:char, 29*3)
29
- @@gb.put_bytes(0,g)
30
+ @@gb.put_bytes(0, g)
30
31
  @@nb = FFI::MemoryPointer.new(:char, 29)
31
- @@nb.put_bytes(0,n)
32
+ @@nb.put_bytes(0, n)
32
33
 
33
34
  def self.gen_nonce
34
35
  SecureRandom.random_bytes(16)
@@ -40,30 +41,31 @@ module LibEcp
40
41
  end
41
42
 
42
43
  # Generates users private key, Arguments: user id bytestring (from gen_uid), password String
43
- def self.private_key(uid,pass)
44
- return OpenSSL::Digest.digest("SHA224", uid + pass)
44
+ def self.private_key(uid, pass)
45
+ OpenSSL::Digest.digest("SHA224", uid + pass)
45
46
  end
46
47
 
47
48
  # Generates public key from private key
48
49
  def self.gen_pub(priv_key)
49
- #create pointer
50
50
  qbuf = FFI::MemoryPointer.new(:char, 29*3)
51
51
  zbuf = FFI::MemoryPointer.new(:char, 29)
52
- zbuf.put_bytes(1,priv_key)
52
+ zbuf.put_bytes(1, priv_key)
53
53
  LibEcp::ecp_pubkey_u8 qbuf, @@pb, @@ab, @@gb, zbuf, 29
54
- return [Base64.encode64(qbuf.get_bytes(1, 28)).rstrip,Base64.encode64(qbuf.get_bytes(30, 28)).rstrip]
54
+
55
+ [Base64.encode64(qbuf.get_bytes(1, 28)).rstrip, Base64.encode64(qbuf.get_bytes(30, 28)).rstrip]
55
56
  end
56
57
 
57
- # Arguments: user id, server nonce, client nonce, users private key ; returns an array with the two coordinates (i.e. the signature)
58
- def self.sign(user_id,snonce,cnonce,priv_key)
58
+ # Arguments: user id, server nonce, client nonce, users private key.
59
+ # Returns an array with the two coordinates that is the signature.
60
+ def self.sign(user_id, snonce, cnonce, priv_key)
59
61
  rbuf = FFI::MemoryPointer.new(:char, 29)
60
62
  sbuf = FFI::MemoryPointer.new(:char, 29)
61
63
  dbuf = FFI::MemoryPointer.new(:char, 29)
62
- dbuf.put_bytes(1,priv_key)
64
+ dbuf.put_bytes(1, priv_key)
63
65
  zbuf = FFI::MemoryPointer.new(:char, 29)
64
66
  zbuf.put_bytes(1, OpenSSL::Digest.digest("SHA224", user_id + snonce + cnonce))
65
67
  LibEcp::ecp_sign_u8 rbuf, sbuf, @@pb, @@ab, @@gb, @@nb, dbuf, zbuf, 29
66
- # these are the coordinates that is the signature:
67
- return [ rbuf.get_bytes(1, 28), sbuf.get_bytes(1, 28) ]
68
+
69
+ [rbuf.get_bytes(1, 28), sbuf.get_bytes(1, 28)]
68
70
  end
69
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cf-ruby-libecp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coinfloor LTD
@@ -15,6 +15,9 @@ dependencies:
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 1.9.3
20
23
  type: :runtime
@@ -22,9 +25,12 @@ dependencies:
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.9'
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 1.9.3
27
- description: Libecp is a C++ elliptic curve cryptography library for signing, verifying
33
+ description: LibECP is a C++ elliptic curve cryptography library for signing, verifying
28
34
  signatures and generating keys.
29
35
  email: development@coinfloor.co.uk
30
36
  executables: []