ffi-libsodium 0.0.1 → 0.0.2
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 +2 -2
- data/lib/crypto/box.rb +49 -0
- data/lib/crypto/one_time_auth.rb +5 -5
- data/lib/crypto/scalar_mult.rb +2 -2
- data/lib/crypto/short_hash.rb +1 -1
- data/lib/crypto/sign.rb +4 -4
- 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: ada72fa7e9887b70143e4e2bba21d0b2165d72a9
|
4
|
+
data.tar.gz: 5bfac66a243ac4861d782e5c8ba7fcb412f6264f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bd7feeb776a528d318bea1ffca5108ee3ea5751acfb3d98e96d0c152c516bc1e601e3c20421ad5d1bc73276fdb616e62102f6fd552d57c881af7ef2f7269c4a
|
7
|
+
data.tar.gz: 1e3381716d27b253ba9623b48310bfc5954b23e59904b5e93a27d423764c6f6c73bd3616d10801322eff4db8e9e698528e7ef3c5ccb43d237f5a4b9fa589e39e
|
@@ -29,8 +29,8 @@ module Crypto
|
|
29
29
|
NPUBBYTES = npubbytes.freeze
|
30
30
|
ABYTES = abytes.freeze
|
31
31
|
|
32
|
-
attach_function :crypto_aead_chacha20poly1305_encrypt, [:buffer_out, :buffer_out, :buffer_in, :ulong_long, :buffer_in, :ulong_long, :pointer, :buffer_in, :buffer_in], :int
|
33
|
-
attach_function :crypto_aead_chacha20poly1305_decrypt, [:buffer_out, :buffer_out, :pointer, :buffer_in, :ulong_long, :buffer_in, :ulong_long, :buffer_in, :buffer_in], :int
|
32
|
+
attach_function :crypto_aead_chacha20poly1305_encrypt, [:buffer_out, :buffer_out, :buffer_in, :ulong_long, :buffer_in, :ulong_long, :pointer, :buffer_in, :buffer_in], :int, blocking: true
|
33
|
+
attach_function :crypto_aead_chacha20poly1305_decrypt, [:buffer_out, :buffer_out, :pointer, :buffer_in, :ulong_long, :buffer_in, :ulong_long, :buffer_in, :buffer_in], :int, blocking: true
|
34
34
|
|
35
35
|
module_function
|
36
36
|
|
data/lib/crypto/box.rb
CHANGED
@@ -15,6 +15,7 @@ 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
|
18
19
|
attach_function :noncebytes, :crypto_box_noncebytes, [], :size_t
|
19
20
|
attach_function :macbytes, :crypto_box_macbytes, [], :size_t
|
20
21
|
|
@@ -22,6 +23,7 @@ module Crypto
|
|
22
23
|
SEEDBYTES = seedbytes.freeze
|
23
24
|
PUBLICKEYBYTES = publickeybytes.freeze
|
24
25
|
SECRETKEYBYTES = secretkeybytes.freeze
|
26
|
+
BEFORENMBYTES = beforenmbytes.freeze
|
25
27
|
NONCEBYTES = noncebytes.freeze
|
26
28
|
MACBYTES = macbytes.freeze
|
27
29
|
|
@@ -31,6 +33,11 @@ module Crypto
|
|
31
33
|
attach_function :crypto_box_easy, [:buffer_out, :buffer_in, :ulong_long, :buffer_in, :buffer_in, :buffer_in], :int, blocking: true
|
32
34
|
attach_function :crypto_box_open_easy, [:buffer_out, :buffer_in, :ulong_long, :buffer_in, :buffer_in, :buffer_in], :int, blocking: true
|
33
35
|
|
36
|
+
attach_function :crypto_box_beforenm, [:buffer_out, :buffer_in, :buffer_in], :int, blocking: true
|
37
|
+
|
38
|
+
attach_function :crypto_box_afternm, [:buffer_out, :buffer_in, :ulong_long, :buffer_in, :buffer_in], :int, blocking: true
|
39
|
+
attach_function :crypto_box_open_afternm, [:buffer_out, :buffer_in, :ulong_long, :buffer_in, :buffer_in], :int, blocking: true
|
40
|
+
|
34
41
|
module_function
|
35
42
|
|
36
43
|
def nonce
|
@@ -89,6 +96,8 @@ module Crypto
|
|
89
96
|
ciphertext
|
90
97
|
end
|
91
98
|
|
99
|
+
alias_method :box, :easy
|
100
|
+
|
92
101
|
def open_easy(ciphertext, nonce, public_key, secret_key)
|
93
102
|
ciphertext_len = get_size(ciphertext)
|
94
103
|
check_length(nonce, NONCEBYTES, :Nonce)
|
@@ -106,6 +115,8 @@ module Crypto
|
|
106
115
|
decrypted
|
107
116
|
end
|
108
117
|
|
118
|
+
alias_method :open, :open_easy
|
119
|
+
|
109
120
|
def easy_in_place(data, nonce, public_key, secret_key)
|
110
121
|
message = get_string(data)
|
111
122
|
check_length(nonce, NONCEBYTES, :Nonce)
|
@@ -146,5 +157,43 @@ module Crypto
|
|
146
157
|
|
147
158
|
ciphertext
|
148
159
|
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
|
+
end
|
195
|
+
|
196
|
+
def box(*args)
|
197
|
+
Box.box(*args)
|
149
198
|
end
|
150
199
|
end
|
data/lib/crypto/one_time_auth.rb
CHANGED
@@ -18,17 +18,17 @@ module Crypto
|
|
18
18
|
BYTES = bytes.freeze
|
19
19
|
KEYBYTES = keybytes.freeze
|
20
20
|
|
21
|
-
attach_function :crypto_onetimeauth, [:buffer_out, :buffer_in, :ulong_long, :buffer_in], :int
|
22
|
-
attach_function :crypto_onetimeauth_verify, [:buffer_in, :buffer_in, :ulong_long, :buffer_in], :int
|
21
|
+
attach_function :crypto_onetimeauth, [:buffer_out, :buffer_in, :ulong_long, :buffer_in], :int, blocking: true
|
22
|
+
attach_function :crypto_onetimeauth_verify, [:buffer_in, :buffer_in, :ulong_long, :buffer_in], :int, blocking: true
|
23
23
|
|
24
24
|
class State < FFI::Struct
|
25
25
|
layout :aligner, :ulong_long,
|
26
26
|
:opaque, [:uchar, 136]
|
27
27
|
end
|
28
28
|
|
29
|
-
attach_function :crypto_onetimeauth_init, [State.ptr, :buffer_in], :int
|
30
|
-
attach_function :crypto_onetimeauth_update, [State.ptr, :buffer_in, :ulong_long], :int
|
31
|
-
attach_function :crypto_onetimeauth_final, [State.ptr, :buffer_out], :int
|
29
|
+
attach_function :crypto_onetimeauth_init, [State.ptr, :buffer_in], :int, blocking: true
|
30
|
+
attach_function :crypto_onetimeauth_update, [State.ptr, :buffer_in, :ulong_long], :int, blocking: true
|
31
|
+
attach_function :crypto_onetimeauth_final, [State.ptr, :buffer_out], :int, blocking: true
|
32
32
|
|
33
33
|
module_function
|
34
34
|
|
data/lib/crypto/scalar_mult.rb
CHANGED
@@ -19,8 +19,8 @@ module Crypto
|
|
19
19
|
BYTES = bytes.freeze
|
20
20
|
SCALARBYTES = scalarbytes.freeze
|
21
21
|
|
22
|
-
attach_function :crypto_scalarmult_base, [:buffer_out, :buffer_in], :int
|
23
|
-
attach_function :crypto_scalarmult, [:buffer_out, :buffer_in, :buffer_in], :int
|
22
|
+
attach_function :crypto_scalarmult_base, [:buffer_out, :buffer_in], :int, blocking: true
|
23
|
+
attach_function :crypto_scalarmult, [:buffer_out, :buffer_in, :buffer_in], :int, blocking: true
|
24
24
|
|
25
25
|
module_function
|
26
26
|
|
data/lib/crypto/short_hash.rb
CHANGED
@@ -18,7 +18,7 @@ module Crypto
|
|
18
18
|
BYTES = bytes.freeze
|
19
19
|
KEYBYTES = keybytes.freeze
|
20
20
|
|
21
|
-
attach_function :crypto_shorthash, [:buffer_out, :buffer_in, :ulong_long, :buffer_in], :int
|
21
|
+
attach_function :crypto_shorthash, [:buffer_out, :buffer_in, :ulong_long, :buffer_in], :int, blocking: true
|
22
22
|
|
23
23
|
module_function
|
24
24
|
|
data/lib/crypto/sign.rb
CHANGED
@@ -23,11 +23,11 @@ module Crypto
|
|
23
23
|
PUBLICKEYBYTES = publickeybytes.freeze
|
24
24
|
SECRETKEYBYTES = secretkeybytes.freeze
|
25
25
|
|
26
|
-
attach_function :crypto_sign_keypair, [:buffer_out, :buffer_out], :int
|
27
|
-
attach_function :crypto_sign_seed_keypair, [:buffer_out, :buffer_out, :buffer_in], :int
|
26
|
+
attach_function :crypto_sign_keypair, [:buffer_out, :buffer_out], :int, blocking: true
|
27
|
+
attach_function :crypto_sign_seed_keypair, [:buffer_out, :buffer_out, :buffer_in], :int, blocking: true
|
28
28
|
|
29
|
-
attach_function :crypto_sign, [:buffer_out, :buffer_out, :buffer_in, :ulong_long, :buffer_in], :int
|
30
|
-
attach_function :crypto_sign_open, [:buffer_out, :buffer_out, :buffer_in, :ulong_long, :buffer_in], :int
|
29
|
+
attach_function :crypto_sign, [:buffer_out, :buffer_out, :buffer_in, :ulong_long, :buffer_in], :int, blocking: true
|
30
|
+
attach_function :crypto_sign_open, [:buffer_out, :buffer_out, :buffer_in, :ulong_long, :buffer_in], :int, blocking: true
|
31
31
|
|
32
32
|
module_function
|
33
33
|
|
data/lib/sodium/version.rb
CHANGED