Module: LibEcp
- Extended by:
- FFI::Library
- Defined in:
- lib/libecp.rb
Constant Summary collapse
- @@pb =
Create the buffers
FFI::MemoryPointer.new(:char, 29)
- @@ab =
FFI::MemoryPointer.new(:char, 29)
- @@gb =
FFI::MemoryPointer.new(:char, 29*3)
- @@nb =
FFI::MemoryPointer.new(:char, 29)
Class Method Summary collapse
- .gen_nonce ⇒ Object
-
.gen_pub(priv_key) ⇒ Object
Generates public key from private key.
-
.gen_uid(user_id) ⇒ Object
Generates user id as a bytestring.
-
.private_key(uid, pass) ⇒ Object
Generates users private key, Arguments: user id bytestring (from gen_uid), password String.
-
.sign(user_id, snonce, cnonce, priv_key) ⇒ Object
Arguments: user id, server nonce, client nonce, users private key.
Class Method Details
.gen_nonce ⇒ Object
34 35 36 |
# File 'lib/libecp.rb', line 34 def self.gen_nonce SecureRandom.random_bytes(16) end |
.gen_pub(priv_key) ⇒ Object
Generates public key from private key
58 59 60 61 62 63 64 65 |
# File 'lib/libecp.rb', line 58 def self.gen_pub(priv_key) qbuf = FFI::MemoryPointer.new(:char, 29*3) zbuf = FFI::MemoryPointer.new(:char, 29) zbuf.put_bytes(1, priv_key) LibEcp::ecp_pubkey_u8 qbuf, @@pb, @@ab, @@gb, zbuf, 29 [Base64.encode64(qbuf.get_bytes(1, 28)).rstrip, Base64.encode64(qbuf.get_bytes(30, 28)).rstrip] end |
.gen_uid(user_id) ⇒ Object
Generates user id as a bytestring
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/libecp.rb', line 39 def self.gen_uid(user_id) ( (user_id >> 56 & 0xFF).chr + (user_id >> 48 & 0xFF).chr + (user_id >> 40 & 0xFF).chr + (user_id >> 32 & 0xFF).chr + (user_id >> 24 & 0xFF).chr + (user_id >> 16 & 0xFF).chr + (user_id >> 8 & 0xFF).chr + (user_id & 0xFF).chr ).encode("ASCII-8BIT") end |
.private_key(uid, pass) ⇒ Object
Generates users private key, Arguments: user id bytestring (from gen_uid), password String
53 54 55 |
# File 'lib/libecp.rb', line 53 def self.private_key(uid, pass) OpenSSL::Digest.digest("SHA224", uid + pass.encode("UTF-8").force_encoding("ASCII-8BIT")) end |
.sign(user_id, snonce, cnonce, priv_key) ⇒ Object
Arguments: user id, server nonce, client nonce, users private key. Returns an array with the two coordinates that is the signature.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/libecp.rb', line 69 def self.sign(user_id, snonce, cnonce, priv_key) rbuf = FFI::MemoryPointer.new(:char, 29) sbuf = FFI::MemoryPointer.new(:char, 29) dbuf = FFI::MemoryPointer.new(:char, 29) dbuf.put_bytes(1, priv_key) zbuf = FFI::MemoryPointer.new(:char, 29) zbuf.put_bytes(1, OpenSSL::Digest.digest("SHA224", user_id + snonce + cnonce)) LibEcp::ecp_sign_u8 rbuf, sbuf, @@pb, @@ab, @@gb, @@nb, dbuf, zbuf, 29 [rbuf.get_bytes(1, 28), sbuf.get_bytes(1, 28)] end |