ffi-libsodium 0.4.4 → 0.4.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f69721c907579641680a434287394a6bf4167701
4
- data.tar.gz: aa8032ace5a3f2cd8ac8a7e664c78da9b87605ab
3
+ metadata.gz: 6b1a503f0fa3b5aa81160f0901562ad7b3eec093
4
+ data.tar.gz: a1ed939f6e4109ab1c1ce234cee10a24b9afa44f
5
5
  SHA512:
6
- metadata.gz: 258b1c21db7bf8e33097284cce68b7ee769336ce68c6522af170dd3026540ccddc3ea9bf62c0d8fab34d34932c76d92cee5454955b77db63c8d69a61667a8bc0
7
- data.tar.gz: 3b4c31224024845e5aa13c6e80b4844834b7760015ee328c231d586170f5d2edb9d22756da7bb8f5dfcd5b95cdf764af7794a2d56d4145532b45c9d340bd9026
6
+ metadata.gz: 30a79852c979c2e52ca8bd9ea0948e20f767e1b5c09e1fab6df64af08ba4dd3a1c7628d14e96f47855fb116ee7282402b48f0349bf34bc552f123b87b955cc8d
7
+ data.tar.gz: ecbc879ff635b206277f1ac857db6aa47471cd6d6a562e6669504641ca2c42dd059c44efee10c1bee7bae5026142afa9692c603dbed2fe8330c1b8ce7d2eaa23
@@ -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
@@ -34,21 +34,21 @@ module Crypto
34
34
  def onetimeauth(message, key)
35
35
  check_length(key, KEYBYTES, :SecretKey)
36
36
 
37
- out = zeros(BYTES)
37
+ mac = zeros(BYTES)
38
38
  key.readonly if key.is_a?(Sodium::SecretBuffer)
39
- crypto_onetimeauth(out, message, get_size(message), key)
39
+ crypto_onetimeauth(mac, message, get_size(message), key)
40
40
 
41
- out
41
+ mac
42
42
  ensure
43
43
  key.noaccess if key.is_a?(Sodium::SecretBuffer)
44
44
  end
45
45
 
46
- def verify(out, message, key)
47
- check_length(out, BYTES, :Authenticator)
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(out, message, get_size(message), key) == 0
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
- out = zeros(BYTES)
74
- crypto_onetimeauth_final(state, out)
75
- out
73
+ mac = zeros(BYTES)
74
+ crypto_onetimeauth_final(state, mac)
75
+ mac
76
76
  end
77
77
  end
78
78
 
@@ -1,3 +1,3 @@
1
1
  module Sodium
2
- VERSION = Gem::Version.new('0.4.4')
2
+ VERSION = Gem::Version.new('0.4.5')
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-libsodium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hendrik Beskow