noise-ruby 0.9.4 → 0.10.0
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 +4 -4
- data/Gemfile +4 -1
- data/README.md +56 -17
- data/lib/noise/functions/hash.rb +3 -0
- data/lib/noise/functions/hash/blake3.rb +35 -0
- data/lib/noise/protocol.rb +2 -1
- data/lib/noise/version.rb +1 -1
- data/noise.gemspec +2 -1
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5b0a36466f2dfcc8a03a1e3d70d3010d150e76dcca4c2669d70ab1d849d3cb5
|
4
|
+
data.tar.gz: 4e3cea23eb34312dbc98b0b4562d045e272047d29a842027242eb28c47b0a615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebcd5a9d334e4b7697fec40d1936d2918d71bc143aca44e5711584ce1c3b2c19fa6b64048d57c8d1b4780eced81e5f982279aeb562ba82bd4809fa6b2f38b238
|
7
|
+
data.tar.gz: 69fcabcd507ad92edab302bc5576e128df0777ce890095c7765f2dc461ef512084cdcb595b4ac451f77baf2a115575787e41d39692a51f8fb8dcad7555eb9b63
|
data/Gemfile
CHANGED
@@ -7,5 +7,8 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
7
7
|
# Specify your gem's dependencies in noise.gemspec
|
8
8
|
gemspec
|
9
9
|
|
10
|
-
# Use secp256k1 as
|
10
|
+
# Use secp256k1 as ecdh function
|
11
11
|
# gem 'secp256k1-ruby'
|
12
|
+
|
13
|
+
# Use blake3 as hash function
|
14
|
+
# gem 'blake3'
|
data/README.md
CHANGED
@@ -2,17 +2,36 @@
|
|
2
2
|
|
3
3
|
A Ruby implementation of the Noise Protocol framework(http://noiseprotocol.org/).
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
Supported Features:
|
6
|
+
|
7
|
+
* DH Functions
|
8
|
+
* ED25519
|
9
|
+
* ED448
|
10
|
+
* Secp256k1
|
11
|
+
* Secp256k1 is required for Lightning Network, layer-2 protocol for bitcoin. see [BOLT #8: Encrypted and Authenticated Transport](https://github.com/lightningnetwork/lightning-rfc/blob/master/08-transport.md)
|
12
|
+
* Cipher Algorithm
|
13
|
+
* ChaCha20-Poly1305
|
14
|
+
* AES-GCM
|
15
|
+
* Hash Functions
|
16
|
+
* SHA256
|
17
|
+
* SHA512
|
18
|
+
* BLAKE2s
|
19
|
+
* BLAKE2b
|
20
|
+
* BLAKE3
|
21
|
+
* Pattens
|
22
|
+
* One-way Patterns(3)
|
23
|
+
* N, K, X
|
24
|
+
* Fundamental Interactive Patterns(12)
|
25
|
+
* NN, KN, NK, KK, NX, KX, XN, IN, XK, IK, XX, IX
|
26
|
+
* Defferred Interactive Patterns(23)
|
27
|
+
* NK1, NX1, X1N, X1K, XK1, X1K1, X1X, XX1, X1X1, K1N, K1K, KK1, K1K1,K1X, KX1, K1X1, I1N, I1K, IK1, I1K1, I1X, IX1, I1X1
|
28
|
+
* Fallback
|
29
|
+
* PSK
|
11
30
|
|
12
31
|
## Installation
|
13
32
|
|
14
|
-
This gem needs libsodium
|
15
|
-
To install
|
33
|
+
This gem needs libsodium library.
|
34
|
+
To install libsodium, see https://github.com/jedisct1/libsodium
|
16
35
|
|
17
36
|
Add this line to your application's Gemfile:
|
18
37
|
|
@@ -28,6 +47,18 @@ Or install it yourself as:
|
|
28
47
|
|
29
48
|
$ gem install noise-ruby
|
30
49
|
|
50
|
+
If you use Ed448 as DH function, you must install [libgoldilocks](https://github.com/otrv4/libgoldilocks).
|
51
|
+
|
52
|
+
After installing, define an environment variable as follows:
|
53
|
+
|
54
|
+
* on macOS
|
55
|
+
|
56
|
+
$ export LIBGOLDILOCKS=/usr/local/lib/libgoldilocks.dylib
|
57
|
+
|
58
|
+
* on Linux(Ubuntu)
|
59
|
+
|
60
|
+
$ export LIBGOLDILOCKS=/usr/local/lib/libgoldilocks.so
|
61
|
+
|
31
62
|
If you use Secp256k1, you must install [libsecp256k1](https://github.com/bitcoin-core/secp256k1).
|
32
63
|
|
33
64
|
$ git clone https://github.com/bitcoin-core/secp256k1
|
@@ -43,6 +74,13 @@ and, add this line to your Gemfile:
|
|
43
74
|
gem 'secp256k1-ruby'
|
44
75
|
```
|
45
76
|
|
77
|
+
If you use BLAKE3, you must install [Rust and Cargo](https://www.rust-lang.org/tools/install).
|
78
|
+
And add this line to your Gemfile:
|
79
|
+
|
80
|
+
```
|
81
|
+
gem 'blake3'
|
82
|
+
```
|
83
|
+
|
46
84
|
## Usage
|
47
85
|
|
48
86
|
Followings shows handshake protocol with "Noise_NN_25519_ChaChaPoly_BLAKE2b"
|
@@ -58,12 +96,12 @@ initiator.start_handshake # => true
|
|
58
96
|
cipher = initiator.write_message("") # => "\xB6\xF7gmxi\xAB\xBCY|t\xF0\x9D\x01A\ad\x92\xBBvp\x80ZNU\f=\x83\x81^\xFD\x15"
|
59
97
|
```
|
60
98
|
|
61
|
-
then initiator sends `cipher` to responder.
|
99
|
+
then initiator sends `cipher` to the responder.
|
62
100
|
|
63
101
|
#### responder
|
64
102
|
|
65
|
-
|
66
|
-
|
103
|
+
The responder receives `cipher` from the initiator.
|
104
|
+
The responder responds messages to the initiator.
|
67
105
|
|
68
106
|
```
|
69
107
|
responder = Noise::Connection::Responder.new("Noise_NN_25519_ChaChaPoly_BLAKE2b")
|
@@ -74,25 +112,26 @@ cipher = responder.write_message("") # => "\v\xD9\x97'\xC0\xB1\xC9\xFFD\x8C\x7F\
|
|
74
112
|
```
|
75
113
|
|
76
114
|
|
77
|
-
|
115
|
+
#### initiator
|
78
116
|
|
79
117
|
```
|
80
118
|
plain = initiator.read_message(cipher) # => ""
|
81
119
|
```
|
82
120
|
|
83
|
-
###
|
121
|
+
### Transport (after handshake finished)
|
122
|
+
|
123
|
+
#### Send transport message
|
84
124
|
|
85
125
|
```
|
86
126
|
cipher = initiator.encrypt("Hello, World!") # => "\xDA\xC7\xD7as\v\xFA\xCC,\xB3\xC7\xD0/xL\xE8I,\xD9\n\xEExh\x8F\xFA\xD6\x01\x99W"
|
87
127
|
```
|
88
128
|
|
89
|
-
|
129
|
+
#### Receive transport message
|
90
130
|
|
91
131
|
```
|
92
132
|
plain = responder.decrypt(cipher) # => "Hello, World!"
|
93
133
|
```
|
94
134
|
|
95
|
-
|
96
135
|
## Development
|
97
136
|
|
98
137
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -101,8 +140,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
101
140
|
|
102
141
|
## Contributing
|
103
142
|
|
104
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
143
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Yamaguchi/noise. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
105
144
|
|
106
145
|
## Code of Conduct
|
107
146
|
|
108
|
-
Everyone interacting in the Noise project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
147
|
+
Everyone interacting in the Noise project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Yamaguchi/noise/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/noise/functions/hash.rb
CHANGED
@@ -7,6 +7,7 @@ module Noise
|
|
7
7
|
autoload :Blake2s, 'noise/functions/hash/blake2s'
|
8
8
|
autoload :Sha256, 'noise/functions/hash/sha256'
|
9
9
|
autoload :Sha512, 'noise/functions/hash/sha512'
|
10
|
+
autoload :Blake3, 'noise/functions/hash/blake3'
|
10
11
|
|
11
12
|
def self.hmac_hash(key, data, digest)
|
12
13
|
if digest.include?('SHA')
|
@@ -15,6 +16,8 @@ module Noise
|
|
15
16
|
Noise::Functions::Hash::Blake2bHMAC.new(key).update(data).digest
|
16
17
|
elsif digest.include?('BLAKE2s')
|
17
18
|
Noise::Functions::Hash::Blake2sHMAC.new(key).update(data).digest
|
19
|
+
elsif digest.include?('BLAKE3')
|
20
|
+
Noise::Functions::Hash::Blake3HMAC.new(key).update(data).digest
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'blake3'
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
|
+
|
8
|
+
module Noise
|
9
|
+
module Functions
|
10
|
+
module Hash
|
11
|
+
class Blake3
|
12
|
+
HASHLEN = 64
|
13
|
+
BLOCKLEN = 128
|
14
|
+
def hash(data)
|
15
|
+
::Blake3.digest(data)
|
16
|
+
end
|
17
|
+
|
18
|
+
def hashlen
|
19
|
+
HASHLEN
|
20
|
+
end
|
21
|
+
|
22
|
+
def blocklen
|
23
|
+
BLOCKLEN
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Blake3HMAC < HMAC::Base
|
28
|
+
def initialize(key = nil)
|
29
|
+
super(::Blake3::Hasher, Blake3::BLOCKLEN, Blake3::HASHLEN, key)
|
30
|
+
end
|
31
|
+
public_class_method :new, :digest, :hexdigest
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/noise/protocol.rb
CHANGED
@@ -21,7 +21,8 @@ module Noise
|
|
21
21
|
'BLAKE2b': Noise::Functions::Hash::Blake2b,
|
22
22
|
'BLAKE2s': Noise::Functions::Hash::Blake2s,
|
23
23
|
'SHA256': Noise::Functions::Hash::Sha256,
|
24
|
-
'SHA512': Noise::Functions::Hash::Sha512
|
24
|
+
'SHA512': Noise::Functions::Hash::Sha512,
|
25
|
+
'BLAKE3': Noise::Functions::Hash::Blake3,
|
25
26
|
}.stringify_keys.freeze
|
26
27
|
|
27
28
|
def self.create(name)
|
data/lib/noise/version.rb
CHANGED
data/noise.gemspec
CHANGED
@@ -21,13 +21,14 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
+
spec.add_development_dependency 'blake3'
|
24
25
|
spec.add_development_dependency 'bundler', '~> 1.15'
|
25
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
28
|
spec.add_development_dependency 'secp256k1-ruby'
|
28
29
|
|
29
30
|
spec.add_runtime_dependency 'ecdsa'
|
31
|
+
spec.add_runtime_dependency 'ed448'
|
30
32
|
spec.add_runtime_dependency 'rbnacl'
|
31
33
|
spec.add_runtime_dependency 'ruby-hmac'
|
32
|
-
spec.add_runtime_dependency 'ed448'
|
33
34
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noise-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hajime Yamaguchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: blake3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +95,7 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: ed448
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ">="
|
@@ -95,7 +109,7 @@ dependencies:
|
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: rbnacl
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - ">="
|
@@ -109,7 +123,7 @@ dependencies:
|
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
126
|
+
name: ruby-hmac
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - ">="
|
@@ -167,6 +181,7 @@ files:
|
|
167
181
|
- lib/noise/functions/hash.rb
|
168
182
|
- lib/noise/functions/hash/blake2b.rb
|
169
183
|
- lib/noise/functions/hash/blake2s.rb
|
184
|
+
- lib/noise/functions/hash/blake3.rb
|
170
185
|
- lib/noise/functions/hash/sha256.rb
|
171
186
|
- lib/noise/functions/hash/sha512.rb
|
172
187
|
- lib/noise/key.rb
|