ffi-libsodium 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/crypto/box.rb +19 -1
- data/lib/crypto/one_time_auth.rb +9 -9
- 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: 6b1a503f0fa3b5aa81160f0901562ad7b3eec093
|
4
|
+
data.tar.gz: a1ed939f6e4109ab1c1ce234cee10a24b9afa44f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30a79852c979c2e52ca8bd9ea0948e20f767e1b5c09e1fab6df64af08ba4dd3a1c7628d14e96f47855fb116ee7282402b48f0349bf34bc552f123b87b955cc8d
|
7
|
+
data.tar.gz: ecbc879ff635b206277f1ac857db6aa47471cd6d6a562e6669504641ca2c42dd059c44efee10c1bee7bae5026142afa9692c603dbed2fe8330c1b8ce7d2eaa23
|
data/lib/crypto/box.rb
CHANGED
@@ -17,6 +17,7 @@ module Crypto
|
|
17
17
|
attach_function :secretkeybytes, :crypto_box_secretkeybytes, [], :size_t
|
18
18
|
attach_function :noncebytes, :crypto_box_noncebytes, [], :size_t
|
19
19
|
attach_function :macbytes, :crypto_box_macbytes, [], :size_t
|
20
|
+
attach_function :beforenmbytes, :crypto_box_beforenmbytes, [], :size_t
|
20
21
|
|
21
22
|
PRIMITIVE = primitive.freeze
|
22
23
|
SEEDBYTES = seedbytes.freeze
|
@@ -24,6 +25,7 @@ module Crypto
|
|
24
25
|
SECRETKEYBYTES = secretkeybytes.freeze
|
25
26
|
NONCEBYTES = noncebytes.freeze
|
26
27
|
MACBYTES = macbytes.freeze
|
28
|
+
BEFORENMBYTES = beforenmbytes.freeze
|
27
29
|
|
28
30
|
attach_function :crypto_box_keypair, [:buffer_out, :buffer_out], :int
|
29
31
|
attach_function :crypto_box_seed_keypair, [:buffer_out, :buffer_out, :buffer_in], :int
|
@@ -34,6 +36,8 @@ module Crypto
|
|
34
36
|
attach_function :crypto_box_detached, [:buffer_out, :buffer_out, :buffer_in, :ulong_long, :buffer_in, :buffer_in, :buffer_in], :int
|
35
37
|
attach_function :crypto_box_open_detached, [:buffer_out, :buffer_in, :buffer_in, :ulong_long, :buffer_in, :buffer_in, :buffer_in], :int
|
36
38
|
|
39
|
+
attach_function :crypto_box_beforenm, [:buffer_out, :buffer_in, :buffer_in], :int
|
40
|
+
|
37
41
|
module_function
|
38
42
|
|
39
43
|
def nonce
|
@@ -84,6 +88,20 @@ module Crypto
|
|
84
88
|
seed.noaccess if seed.is_a?(Sodium::SecretBuffer)
|
85
89
|
end
|
86
90
|
|
91
|
+
def beforenm(public_key, secret_key)
|
92
|
+
check_length(public_key, PUBLICKEYBYTES, :PublicKey)
|
93
|
+
check_length(secret_key, SECRETKEYBYTES, :SecretKey)
|
94
|
+
|
95
|
+
shared_secret = Sodium::SecretBuffer.new(BEFORENMBYTES)
|
96
|
+
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
97
|
+
crypto_box_beforenm(shared_secret, public_key, secret_key)
|
98
|
+
shared_secret.noaccess
|
99
|
+
|
100
|
+
shared_secret
|
101
|
+
ensure
|
102
|
+
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
103
|
+
end
|
104
|
+
|
87
105
|
def box(message, nonce, public_key, secret_key)
|
88
106
|
message_len = get_size(message)
|
89
107
|
check_length(nonce, NONCEBYTES, :Nonce)
|
@@ -151,8 +169,8 @@ module Crypto
|
|
151
169
|
if crypto_box_open_easy(ciphertext, ciphertext, ciphertext_len, nonce, public_key, secret_key) == -1
|
152
170
|
raise Sodium::CryptoError, "Message forged", caller
|
153
171
|
end
|
154
|
-
|
155
172
|
ciphertext.slice!(message_len..-1)
|
173
|
+
|
156
174
|
if encoding
|
157
175
|
ciphertext.force_encoding(encoding)
|
158
176
|
end
|
data/lib/crypto/one_time_auth.rb
CHANGED
@@ -34,21 +34,21 @@ module Crypto
|
|
34
34
|
def onetimeauth(message, key)
|
35
35
|
check_length(key, KEYBYTES, :SecretKey)
|
36
36
|
|
37
|
-
|
37
|
+
mac = zeros(BYTES)
|
38
38
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
39
|
-
crypto_onetimeauth(
|
39
|
+
crypto_onetimeauth(mac, message, get_size(message), key)
|
40
40
|
|
41
|
-
|
41
|
+
mac
|
42
42
|
ensure
|
43
43
|
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
44
44
|
end
|
45
45
|
|
46
|
-
def verify(
|
47
|
-
check_length(
|
46
|
+
def verify(mac, message, key)
|
47
|
+
check_length(mac, BYTES, :Mac)
|
48
48
|
check_length(key, KEYBYTES, :SecretKey)
|
49
49
|
|
50
50
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
51
|
-
crypto_onetimeauth_verify(
|
51
|
+
crypto_onetimeauth_verify(mac, message, get_size(message), key) == 0
|
52
52
|
ensure
|
53
53
|
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
54
54
|
end
|
@@ -70,9 +70,9 @@ module Crypto
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def final(state)
|
73
|
-
|
74
|
-
crypto_onetimeauth_final(state,
|
75
|
-
|
73
|
+
mac = zeros(BYTES)
|
74
|
+
crypto_onetimeauth_final(state, mac)
|
75
|
+
mac
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
data/lib/sodium/version.rb
CHANGED