noise-ruby 0.7.3 → 0.7.4
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecfac7577c0e2c49956249076aa5351f4c002fc135341f4bb21b9279cf54ba56
|
4
|
+
data.tar.gz: d65b64e5ce9df56c2ad0599a75fabb4070b9739ff7313961ec0e6b3ab11b68cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be99c89230f89d0f286a4dc1da6aadb10ce06ba64206325381cca8032ae71abec0406d1a957fafe0946791f72f346ef23cce019c74868605280e5fa357287e18
|
7
|
+
data.tar.gz: b11a5a496096daf4f4abe9dbfb6f2bba693ec4b5be2c680be6b42b450d7be89a7f119535f20e46bba7429c1f5024ebd62896922c7a944c24a76d951e2df8df4c
|
@@ -3,9 +3,10 @@
|
|
3
3
|
module Noise
|
4
4
|
module Connection
|
5
5
|
class Base
|
6
|
-
attr_reader :protocol, :handshake_started, :handshake_finished, :handshake_hash
|
6
|
+
attr_reader :protocol, :handshake_started, :handshake_finished, :handshake_hash, :handshake_state
|
7
7
|
attr_reader :cipher_state_encrypt, :cipher_state_decrypt, :cipher_state_handshake
|
8
8
|
attr_accessor :psks, :prologue
|
9
|
+
attr_reader :s, :rs
|
9
10
|
|
10
11
|
def initialize(name, keypairs: { s: nil, e: nil, rs: nil, re: nil })
|
11
12
|
@protocol = Protocol.create(name)
|
@@ -103,6 +104,8 @@ module Noise
|
|
103
104
|
|
104
105
|
def handshake_done(_c1, _c2)
|
105
106
|
@handshake_hash = @symmetric_state.handshake_hash
|
107
|
+
@s = @handshake_state.s
|
108
|
+
@rs = @handshake_state.rs
|
106
109
|
@handshake_state = nil
|
107
110
|
@symmetric_state = nil
|
108
111
|
@cipher_state_handshake = nil
|
@@ -4,6 +4,8 @@ module Noise
|
|
4
4
|
module Functions
|
5
5
|
module Cipher
|
6
6
|
class AesGcm
|
7
|
+
MAX_NONCE = 2**64 - 1
|
8
|
+
|
7
9
|
def encrypt(k, n, ad, plaintext)
|
8
10
|
cipher = OpenSSL::Cipher::AES.new(256, :GCM).encrypt
|
9
11
|
cipher.key = k
|
@@ -24,6 +26,16 @@ module Noise
|
|
24
26
|
def nonce_to_bytes(n)
|
25
27
|
"\x00" * 4 + format('%16x', n).htb
|
26
28
|
end
|
29
|
+
|
30
|
+
# Returns a new 32-byte cipher key as a pseudorandom function of k.
|
31
|
+
# If this function is not specifically defined for some set of cipher
|
32
|
+
# functions, then it defaults to returning the first 32 bytes from
|
33
|
+
# ENCRYPT(k,maxnonce, zerolen, zeros), where maxnonce equals 264-1,
|
34
|
+
# zerolen is a zero-length byte sequence, and zeros is a sequence of
|
35
|
+
# 32 bytes filled with zeros.
|
36
|
+
def rekey(k)
|
37
|
+
encrypt(k, MAX_NONCE, '', "\x00" * 32)[0...32]
|
38
|
+
end
|
27
39
|
end
|
28
40
|
end
|
29
41
|
end
|
@@ -4,16 +4,18 @@ module Noise
|
|
4
4
|
module Functions
|
5
5
|
module Cipher
|
6
6
|
class ChaChaPoly
|
7
|
+
MAX_NONCE = 2**64 - 1
|
8
|
+
|
7
9
|
def encrypt(k, n, ad, plaintext)
|
8
|
-
|
9
|
-
|
10
|
+
cipher = RbNaCl::AEAD::ChaCha20Poly1305IETF.new(String.new(k).force_encoding('ASCII-8BIT'))
|
11
|
+
cipher.encrypt(nonce_to_bytes(n), plaintext, ad)
|
10
12
|
rescue ::RbNaCl::CryptoError => e
|
11
13
|
raise Noise::Exceptions::EncryptError, e
|
12
14
|
end
|
13
15
|
|
14
16
|
def decrypt(k, n, ad, ciphertext)
|
15
|
-
|
16
|
-
|
17
|
+
cipher = RbNaCl::AEAD::ChaCha20Poly1305IETF.new(String.new(k).force_encoding('ASCII-8BIT'))
|
18
|
+
cipher.decrypt(nonce_to_bytes(n), ciphertext, ad)
|
17
19
|
rescue ::RbNaCl::CryptoError => e
|
18
20
|
raise Noise::Exceptions::DecryptError, e
|
19
21
|
end
|
@@ -21,6 +23,16 @@ module Noise
|
|
21
23
|
def nonce_to_bytes(n)
|
22
24
|
"\x00" * 4 + format('%16x', n).htb.reverse
|
23
25
|
end
|
26
|
+
|
27
|
+
# Returns a new 32-byte cipher key as a pseudorandom function of k.
|
28
|
+
# If this function is not specifically defined for some set of cipher
|
29
|
+
# functions, then it defaults to returning the first 32 bytes from
|
30
|
+
# ENCRYPT(k,maxnonce, zerolen, zeros), where maxnonce equals 2**64-1,
|
31
|
+
# zerolen is a zero-length byte sequence, and zeros is a sequence of
|
32
|
+
# 32 bytes filled with zeros.
|
33
|
+
def rekey(k)
|
34
|
+
encrypt(k, MAX_NONCE, '', "\x00" * 32)[0..32]
|
35
|
+
end
|
24
36
|
end
|
25
37
|
end
|
26
38
|
end
|
@@ -18,6 +18,7 @@ module Noise
|
|
18
18
|
# Each message pattern is a sequence of tokens from the set ("e", "s", "ee", "es", "se", "ss").
|
19
19
|
class HandshakeState
|
20
20
|
attr_reader :message_patterns, :symmetric_state
|
21
|
+
attr_reader :s, :rs
|
21
22
|
|
22
23
|
def initialize(connection, protocol, initiator, prologue, keypairs)
|
23
24
|
@connection = connection
|
data/lib/noise/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noise-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hajime Yamaguchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|