ffi-libsodium 0.0.3 → 0.0.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.
- checksums.yaml +4 -4
- data/lib/crypto/box.rb +7 -39
- data/lib/sodium/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01cf5df0b9bcbcc100cc7acedb2a11b7f5a91b2c
|
4
|
+
data.tar.gz: 7fda27dfaaed7e2f538e82d234ddfc254c5b25d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2fe21f487536468f00fde101b3a595c7f671a3f9a2854890db9eb046e40dca5f5bea4db7f7beaecfcdaad8299e31a021c151442dbca0ec86d4d0f32230db15c
|
7
|
+
data.tar.gz: 0ba70b4e2983a644878bc186d16c0084c5195a40887de0efe1a66956f4a9b6471d0e336e5536d87e1731fea619e724a13cd71e1de035aec61c488af5f1bdee66
|
data/lib/crypto/box.rb
CHANGED
@@ -15,7 +15,6 @@ module Crypto
|
|
15
15
|
attach_function :seedbytes, :crypto_box_seedbytes, [], :size_t
|
16
16
|
attach_function :publickeybytes, :crypto_box_publickeybytes, [], :size_t
|
17
17
|
attach_function :secretkeybytes, :crypto_box_secretkeybytes, [], :size_t
|
18
|
-
attach_function :beforenmbytes, :crypto_box_beforenmbytes, [], :size_t
|
19
18
|
attach_function :noncebytes, :crypto_box_noncebytes, [], :size_t
|
20
19
|
attach_function :macbytes, :crypto_box_macbytes, [], :size_t
|
21
20
|
|
@@ -23,7 +22,6 @@ module Crypto
|
|
23
22
|
SEEDBYTES = seedbytes.freeze
|
24
23
|
PUBLICKEYBYTES = publickeybytes.freeze
|
25
24
|
SECRETKEYBYTES = secretkeybytes.freeze
|
26
|
-
BEFORENMBYTES = beforenmbytes.freeze
|
27
25
|
NONCEBYTES = noncebytes.freeze
|
28
26
|
MACBYTES = macbytes.freeze
|
29
27
|
|
@@ -96,7 +94,9 @@ module Crypto
|
|
96
94
|
ciphertext
|
97
95
|
end
|
98
96
|
|
99
|
-
|
97
|
+
def box(*args)
|
98
|
+
easy(*args)
|
99
|
+
end
|
100
100
|
|
101
101
|
def open_easy(ciphertext, nonce, public_key, secret_key)
|
102
102
|
ciphertext_len = get_size(ciphertext)
|
@@ -115,7 +115,9 @@ module Crypto
|
|
115
115
|
decrypted
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
def open(*args)
|
119
|
+
open_easy(*args)
|
120
|
+
end
|
119
121
|
|
120
122
|
def easy_in_place(data, nonce, public_key, secret_key)
|
121
123
|
message = get_string(data)
|
@@ -157,43 +159,9 @@ module Crypto
|
|
157
159
|
|
158
160
|
ciphertext
|
159
161
|
end
|
160
|
-
|
161
|
-
def beforenm(public_key, secret_key)
|
162
|
-
check_length(public_key, PUBLICKEYBYTES, :PublicKey)
|
163
|
-
check_length(secret_key, SECRETKEYBYTES, :SecretKey)
|
164
|
-
|
165
|
-
shared_secret = Sodium::SecretBuffer.new(BEFORENMBYTES)
|
166
|
-
crypto_box_beforenm(shared_secret, public_key, secret_key)
|
167
|
-
|
168
|
-
shared_secret
|
169
|
-
end
|
170
|
-
|
171
|
-
def afternm(message, nonce, shared_secret)
|
172
|
-
message_len = get_size(message)
|
173
|
-
check_length(nonce, NONCEBYTES, :Nonce)
|
174
|
-
check_length(shared_secret, BEFORENMBYTES, :SharedSecret)
|
175
|
-
|
176
|
-
ciphertext = Sodium::Buffer.new(:uchar, MACBYTES + message_len)
|
177
|
-
crypto_box_afternm(ciphertext, message, message_len, nonce, shared_secret)
|
178
|
-
|
179
|
-
ciphertext
|
180
|
-
end
|
181
|
-
|
182
|
-
def open_afternm(ciphertext, nonce, shared_secret)
|
183
|
-
ciphertext_len = get_size(ciphertext)
|
184
|
-
check_length(nonce, NONCEBYTES, :Nonce)
|
185
|
-
check_length(shared_secret, BEFORENMBYTES, :SharedSecret)
|
186
|
-
|
187
|
-
decrypted = Sodium::Buffer.new(:uchar, ciphertext_len - MACBYTES)
|
188
|
-
if crypto_box_open_afternm(decrypted, ciphertext, ciphertext_len, nonce, shared_secret) == -1
|
189
|
-
raise Sodium::CryptoError, "Message forged", caller
|
190
|
-
end
|
191
|
-
|
192
|
-
decrypted
|
193
|
-
end
|
194
162
|
end
|
195
163
|
|
196
164
|
def self.box(*args)
|
197
|
-
Box.
|
165
|
+
Box.easy(*args)
|
198
166
|
end
|
199
167
|
end
|
data/lib/sodium/version.rb
CHANGED