ffi-libsodium 0.0.8 → 0.0.9
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/lib/crypto/aead/chacha20_poly1305.rb +5 -4
- data/lib/crypto/auth.rb +4 -4
- data/lib/crypto/box.rb +14 -10
- data/lib/crypto/generic_hash.rb +7 -6
- data/lib/crypto/one_time_auth.rb +7 -4
- data/lib/crypto/scalar_mult.rb +4 -2
- data/lib/crypto/secret_box.rb +11 -8
- data/lib/crypto/short_hash.rb +2 -1
- data/lib/crypto/sign.rb +6 -3
- data/lib/sodium/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68412992b272b75f8a23bb0fb06d4e0d77fd757e
|
4
|
+
data.tar.gz: 7c377501671e1f002c9a095f71526cfacc444272
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54c59d11d1b0ae79363ae106576d23d25b52e488d1777308418f9e3d885d30dd0c02c1c9a1183f39f02b7ebec3fa6ee969f6c27553c17063237845d91f541a91
|
7
|
+
data.tar.gz: a7d268d7d9e7b88766794b749abf453dee3a673cf5c08df96813bf9314c8fe9f89d53df83838bca792ed72dcf2940015454f55466d50e3ced0323893746a1c8a
|
@@ -49,9 +49,10 @@ module Crypto
|
|
49
49
|
ciphertext = Sodium::Buffer.new(:uchar, message_len + ABYTES)
|
50
50
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
51
51
|
crypto_aead_chacha20poly1305_encrypt(ciphertext, nil, message, message_len, additional_data, additional_data_len, nil, nonce, key)
|
52
|
-
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
53
52
|
|
54
53
|
ciphertext
|
54
|
+
ensure
|
55
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
55
56
|
end
|
56
57
|
|
57
58
|
def decrypt(ciphertext, additional_data, nonce, key)
|
@@ -64,13 +65,13 @@ module Crypto
|
|
64
65
|
|
65
66
|
decrypted = Sodium::Buffer.new(:uchar, ciphertext_len - ABYTES)
|
66
67
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
67
|
-
|
68
|
-
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
69
|
-
if rc == -1
|
68
|
+
if crypto_aead_chacha20poly1305_decrypt(decrypted, nil, nil, ciphertext, ciphertext_len, additional_data, additional_data_len, nonce, key) == -1
|
70
69
|
raise Sodium::CryptoError, "Message forged", caller
|
71
70
|
end
|
72
71
|
|
73
72
|
decrypted
|
73
|
+
ensure
|
74
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
74
75
|
end
|
75
76
|
end
|
76
77
|
end
|
data/lib/crypto/auth.rb
CHANGED
@@ -30,9 +30,10 @@ module Crypto
|
|
30
30
|
mac = Sodium::Buffer.new(:uchar, BYTES)
|
31
31
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
32
32
|
crypto_auth(mac, message, message_len, key)
|
33
|
-
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
34
33
|
|
35
34
|
mac
|
35
|
+
ensure
|
36
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
36
37
|
end
|
37
38
|
|
38
39
|
def verify(mac, message, key)
|
@@ -41,10 +42,9 @@ module Crypto
|
|
41
42
|
check_length(key, KEYBYTES, :SecretKey)
|
42
43
|
|
43
44
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
44
|
-
|
45
|
+
crypto_auth_verify(mac, message, message_len, key) == 0
|
46
|
+
ensure
|
45
47
|
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
46
|
-
|
47
|
-
rc == 0
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
data/lib/crypto/box.rb
CHANGED
@@ -58,9 +58,10 @@ module Crypto
|
|
58
58
|
secret_key = Sodium::Buffer.new(:uchar, SECRETKEYBYTES)
|
59
59
|
seed.readonly if seed.is_a?(Sodium::SecretBuffer)
|
60
60
|
crypto_box_seed_keypair(public_key, secret_key, seed)
|
61
|
-
seed.noaccess if seed.is_a?(Sodium::SecretBuffer)
|
62
61
|
|
63
62
|
[public_key, secret_key]
|
63
|
+
ensure
|
64
|
+
seed.noaccess if seed.is_a?(Sodium::SecretBuffer)
|
64
65
|
end
|
65
66
|
|
66
67
|
def memory_locked_keypair
|
@@ -79,10 +80,11 @@ module Crypto
|
|
79
80
|
secret_key = Sodium::SecretBuffer.new(SECRETKEYBYTES)
|
80
81
|
seed.readonly if seed.is_a?(Sodium::SecretBuffer)
|
81
82
|
crypto_box_seed_keypair(public_key, secret_key, seed)
|
82
|
-
seed.noaccess if seed.is_a?(Sodium::SecretBuffer)
|
83
83
|
secret_key.noaccess
|
84
84
|
|
85
85
|
[public_key, secret_key]
|
86
|
+
ensure
|
87
|
+
seed.noaccess if seed.is_a?(Sodium::SecretBuffer)
|
86
88
|
end
|
87
89
|
|
88
90
|
def box(message, nonce, public_key, secret_key)
|
@@ -94,9 +96,10 @@ module Crypto
|
|
94
96
|
ciphertext = Sodium::Buffer.new(:uchar, message_len + MACBYTES)
|
95
97
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
96
98
|
crypto_box_easy(ciphertext, message, message_len, nonce, public_key, secret_key)
|
97
|
-
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
98
99
|
|
99
100
|
ciphertext
|
101
|
+
ensure
|
102
|
+
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
100
103
|
end
|
101
104
|
|
102
105
|
def open(ciphertext, nonce, public_key, secret_key)
|
@@ -107,13 +110,13 @@ module Crypto
|
|
107
110
|
|
108
111
|
decrypted = Sodium::Buffer.new(:uchar, ciphertext_len - MACBYTES)
|
109
112
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
110
|
-
|
111
|
-
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
112
|
-
if rc == -1
|
113
|
+
if crypto_box_open_easy(decrypted, ciphertext, ciphertext_len, nonce, public_key, secret_key) == -1
|
113
114
|
raise Sodium::CryptoError, "Message forged", caller
|
114
115
|
end
|
115
116
|
|
116
117
|
decrypted
|
118
|
+
ensure
|
119
|
+
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
117
120
|
end
|
118
121
|
|
119
122
|
def easy_in_place(data, nonce, public_key, secret_key)
|
@@ -126,9 +129,10 @@ module Crypto
|
|
126
129
|
message << zeros(MACBYTES)
|
127
130
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
128
131
|
crypto_box_easy(message, message, message_len, nonce, public_key, secret_key)
|
129
|
-
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
130
132
|
|
131
133
|
message
|
134
|
+
ensure
|
135
|
+
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
132
136
|
end
|
133
137
|
|
134
138
|
def open_easy_in_place(data, nonce, public_key, secret_key, utf8 = false)
|
@@ -142,9 +146,7 @@ module Crypto
|
|
142
146
|
check_length(secret_key, SECRETKEYBYTES, :SecretKey)
|
143
147
|
|
144
148
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
145
|
-
|
146
|
-
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
147
|
-
if rc == -1
|
149
|
+
if crypto_box_open_easy(ciphertext, ciphertext, ciphertext.bytesize, nonce, public_key, secret_key) == -1
|
148
150
|
raise Sodium::CryptoError, "Message forged", caller
|
149
151
|
end
|
150
152
|
|
@@ -155,6 +157,8 @@ module Crypto
|
|
155
157
|
end
|
156
158
|
|
157
159
|
ciphertext
|
160
|
+
ensure
|
161
|
+
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
158
162
|
end
|
159
163
|
end
|
160
164
|
|
data/lib/crypto/generic_hash.rb
CHANGED
@@ -63,13 +63,13 @@ module Crypto
|
|
63
63
|
|
64
64
|
blake2b = Sodium::Buffer.new(:uchar, hash_size)
|
65
65
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
66
|
-
|
67
|
-
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
68
|
-
if rc == -1
|
66
|
+
if crypto_generichash(blake2b, hash_size, message, message_len, key, key_len) == -1
|
69
67
|
raise Sodium::CryptoError
|
70
68
|
end
|
71
69
|
|
72
70
|
blake2b
|
71
|
+
ensure
|
72
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
73
73
|
end
|
74
74
|
|
75
75
|
def init(key = nil, hash_size = BYTES)
|
@@ -90,13 +90,14 @@ module Crypto
|
|
90
90
|
state = State.new
|
91
91
|
blake2b = Sodium::Buffer.new(:uchar, hash_size)
|
92
92
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
93
|
-
|
94
|
-
key
|
95
|
-
if rc == -1
|
93
|
+
|
94
|
+
if crypto_generichash_init(state, key, key_len, hash_size) == -1
|
96
95
|
raise Sodium::CryptoError
|
97
96
|
end
|
98
97
|
|
99
98
|
[state, blake2b]
|
99
|
+
ensure
|
100
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
100
101
|
end
|
101
102
|
|
102
103
|
def update(state, message)
|
data/lib/crypto/one_time_auth.rb
CHANGED
@@ -39,9 +39,10 @@ module Crypto
|
|
39
39
|
out = Sodium::Buffer.new(:uchar, BYTES)
|
40
40
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
41
41
|
crypto_onetimeauth(out, message, message_len, key)
|
42
|
-
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
43
42
|
|
44
43
|
out
|
44
|
+
ensure
|
45
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
45
46
|
end
|
46
47
|
|
47
48
|
def verify(out, message, key)
|
@@ -50,10 +51,11 @@ module Crypto
|
|
50
51
|
check_length(key, KEYBYTES, :SecretKey)
|
51
52
|
|
52
53
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
53
|
-
|
54
|
-
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
54
|
+
crypto_onetimeauth_verify(out, message, message_len, key) == 0
|
55
55
|
|
56
56
|
rc == 0
|
57
|
+
ensure
|
58
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
57
59
|
end
|
58
60
|
|
59
61
|
def init(key)
|
@@ -62,9 +64,10 @@ module Crypto
|
|
62
64
|
state = State.new
|
63
65
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
64
66
|
crypto_onetimeauth_init(state, key)
|
65
|
-
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
66
67
|
|
67
68
|
state
|
69
|
+
ensure
|
70
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
68
71
|
end
|
69
72
|
|
70
73
|
def update(state, message)
|
data/lib/crypto/scalar_mult.rb
CHANGED
@@ -29,9 +29,10 @@ module Crypto
|
|
29
29
|
public_key = Sodium::Buffer.new(:uchar, BYTES)
|
30
30
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
31
31
|
crypto_scalarmult_base(public_key, secret_key)
|
32
|
-
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
33
32
|
|
34
33
|
public_key
|
34
|
+
ensure
|
35
|
+
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
35
36
|
end
|
36
37
|
|
37
38
|
def scalarmut(secret_key, public_key)
|
@@ -41,10 +42,11 @@ module Crypto
|
|
41
42
|
shared_secret = Sodium::SecretBuffer.new(BYTES)
|
42
43
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
43
44
|
crypto_scalarmult(shared_secret, secret_key, public_key)
|
44
|
-
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
45
45
|
shared_secret.noaccess
|
46
46
|
|
47
47
|
shared_secret
|
48
|
+
ensure
|
49
|
+
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
data/lib/crypto/secret_box.rb
CHANGED
@@ -39,9 +39,10 @@ module Crypto
|
|
39
39
|
ciphertext = Sodium::Buffer.new(:uchar, message_len + MACBYTES)
|
40
40
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
41
41
|
crypto_secretbox_easy(ciphertext, message, message_len, nonce, key)
|
42
|
-
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
43
42
|
|
44
43
|
ciphertext
|
44
|
+
ensure
|
45
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
45
46
|
end
|
46
47
|
|
47
48
|
def open(ciphertext, nonce, key)
|
@@ -51,13 +52,14 @@ module Crypto
|
|
51
52
|
|
52
53
|
decrypted = Sodium::Buffer.new(:uchar, ciphertext_len - MACBYTES)
|
53
54
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
54
|
-
|
55
|
-
|
56
|
-
if rc == -1
|
55
|
+
|
56
|
+
if crypto_secretbox_open_easy(decrypted, ciphertext, ciphertext_len, nonce, key) == -1
|
57
57
|
raise Sodium::CryptoError, "Message forged", caller
|
58
58
|
end
|
59
59
|
|
60
60
|
decrypted
|
61
|
+
ensure
|
62
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
61
63
|
end
|
62
64
|
|
63
65
|
def easy_in_place(data, nonce, key)
|
@@ -69,9 +71,10 @@ module Crypto
|
|
69
71
|
message << zeros(MACBYTES)
|
70
72
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
71
73
|
crypto_secretbox_easy(message, message, message_len, nonce, key)
|
72
|
-
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
73
74
|
|
74
75
|
message
|
76
|
+
ensure
|
77
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
75
78
|
end
|
76
79
|
|
77
80
|
def open_easy_in_place(data, nonce, key, utf8 = false)
|
@@ -84,9 +87,7 @@ module Crypto
|
|
84
87
|
check_length(key, KEYBYTES, :SecretKey)
|
85
88
|
|
86
89
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
87
|
-
|
88
|
-
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
89
|
-
if rc == -1
|
90
|
+
if crypto_secretbox_open_easy(ciphertext, ciphertext, ciphertext.bytesize, nonce, key) == -1
|
90
91
|
raise Sodium::CryptoError, "Message forged", caller
|
91
92
|
end
|
92
93
|
|
@@ -97,6 +98,8 @@ module Crypto
|
|
97
98
|
end
|
98
99
|
|
99
100
|
ciphertext
|
101
|
+
ensure
|
102
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
100
103
|
end
|
101
104
|
end
|
102
105
|
|
data/lib/crypto/short_hash.rb
CHANGED
@@ -29,9 +29,10 @@ module Crypto
|
|
29
29
|
siphash = Sodium::Buffer.new(:uchar, BYTES)
|
30
30
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
31
31
|
crypto_shorthash(siphash, short_data, short_data_len, key)
|
32
|
-
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
33
32
|
|
34
33
|
siphash
|
34
|
+
ensure
|
35
|
+
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
data/lib/crypto/sign.rb
CHANGED
@@ -46,9 +46,10 @@ module Crypto
|
|
46
46
|
secret_key = Sodium::Buffer.new(:uchar, SECRETKEYBYTES)
|
47
47
|
seed.readonly if seed.is_a?(Sodium::SecretBuffer)
|
48
48
|
crypto_sign_seed_keypair(public_key, secret_key, seed)
|
49
|
-
seed.noaccess if seed.is_a?(Sodium::SecretBuffer)
|
50
49
|
|
51
50
|
[public_key, secret_key]
|
51
|
+
ensure
|
52
|
+
seed.noaccess if seed.is_a?(Sodium::SecretBuffer)
|
52
53
|
end
|
53
54
|
|
54
55
|
def memory_locked_keypair
|
@@ -67,10 +68,11 @@ module Crypto
|
|
67
68
|
secret_key = Sodium::SecretBuffer.new(:uchar, SECRETKEYBYTES)
|
68
69
|
seed.readonly if seed.is_a?(Sodium::SecretBuffer)
|
69
70
|
crypto_sign_seed_keypair(public_key, secret_key, seed)
|
70
|
-
seed.noaccess if seed.is_a?(Sodium::SecretBuffer)
|
71
71
|
secret_key.noaccess
|
72
72
|
|
73
73
|
[public_key, secret_key]
|
74
|
+
ensure
|
75
|
+
seed.noaccess if seed.is_a?(Sodium::SecretBuffer)
|
74
76
|
end
|
75
77
|
|
76
78
|
def sign(message, secret_key)
|
@@ -80,9 +82,10 @@ module Crypto
|
|
80
82
|
sealed_message = Sodium::Buffer.new(:uchar, message_len + BYTES)
|
81
83
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
82
84
|
crypto_sign(sealed_message, nil, message, message_len, secret_key)
|
83
|
-
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
84
85
|
|
85
86
|
sealed_message
|
87
|
+
ensure
|
88
|
+
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
86
89
|
end
|
87
90
|
|
88
91
|
def open(sealed_message, public_key)
|
data/lib/sodium/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-libsodium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hendrik Beskow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.4.
|
87
|
+
rubygems_version: 2.4.2
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: libsodium ffi wrapper
|