ffi-libsodium 0.0.5 → 0.0.6
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 +11 -11
- data/lib/crypto/auth.rb +3 -1
- data/lib/crypto/box.rb +7 -3
- data/lib/crypto/pw_hash/scrypt_salsa208_sha256.rb +1 -1
- data/lib/crypto/scalar_mult.rb +1 -1
- data/lib/crypto/secret_box.rb +1 -1
- data/lib/crypto/sign.rb +10 -9
- data/lib/sodium/utils.rb +2 -0
- data/lib/sodium/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 193aa2e92e5fc462d8d7f3c68a2ab71c9fb855a0
|
4
|
+
data.tar.gz: abc95a71587cea89a4d119ed6a1625b4337532cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19ab15b9ced7dbbc0da8b58bfbe2717c55dad11731ecd09c0c7c774a42a3b58260467ee6116fd17a65b01d8d020679fba5bb9a770d1c972007d2b20a20d2bbb7
|
7
|
+
data.tar.gz: e757e619ae02c46e91c336aebc1b632c0a652eec8e71453bf9efc3870e2be4448fd0fc22bef42e456889865fdb7c63a04242a99ad7cf138db6c278245491f5c0
|
@@ -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, :
|
33
|
-
attach_function :crypto_aead_chacha20poly1305_decrypt, [:buffer_out, :
|
32
|
+
attach_function :crypto_aead_chacha20poly1305_encrypt, [:buffer_out, :pointer, :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, :pointer, :pointer, :buffer_in, :ulong_long, :buffer_in, :ulong_long, :buffer_in, :buffer_in], :int, blocking: true
|
34
34
|
|
35
35
|
module_function
|
36
36
|
|
@@ -45,30 +45,30 @@ module Crypto
|
|
45
45
|
check_length(key, KEYBYTES, :SecretKey)
|
46
46
|
|
47
47
|
ciphertext = FFI::MemoryPointer.new(:uchar, message_len + ABYTES)
|
48
|
-
ciphertext_len = FFI::MemoryPointer.new(:ulong_long)
|
49
48
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
50
|
-
crypto_aead_chacha20poly1305_encrypt(ciphertext,
|
49
|
+
crypto_aead_chacha20poly1305_encrypt(ciphertext, nil, message, message_len, additional_data, additional_data_len, nil, nonce, key)
|
51
50
|
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
52
51
|
|
53
|
-
|
52
|
+
ciphertext
|
54
53
|
end
|
55
54
|
|
56
|
-
def decrypt(ciphertext,
|
57
|
-
ciphertext_len =
|
55
|
+
def decrypt(ciphertext, additional_data, nonce, key)
|
56
|
+
unless ((ciphertext_len = get_size(ciphertext)) - ABYTES) > 0
|
57
|
+
fail Sodium::LengthError, "Ciphertext is too short", caller
|
58
|
+
end
|
58
59
|
additional_data_len = get_size(additional_data)
|
59
60
|
check_length(nonce, NPUBBYTES, :Nonce)
|
60
61
|
check_length(key, KEYBYTES, :SecretKey)
|
61
62
|
|
62
|
-
decrypted = FFI::MemoryPointer.new(:uchar, ciphertext_len)
|
63
|
-
decrypted_len = FFI::MemoryPointer.new(:ulong_long)
|
63
|
+
decrypted = FFI::MemoryPointer.new(:uchar, ciphertext_len - ABYTES)
|
64
64
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
65
|
-
rc = crypto_aead_chacha20poly1305_decrypt(decrypted,
|
65
|
+
rc = crypto_aead_chacha20poly1305_decrypt(decrypted, nil, nil, ciphertext, ciphertext_len, additional_data, additional_data_len, nonce, key)
|
66
66
|
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
67
67
|
if rc == -1
|
68
68
|
raise Sodium::CryptoError, "Message forged", caller
|
69
69
|
end
|
70
70
|
|
71
|
-
|
71
|
+
decrypted
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
data/lib/crypto/auth.rb
CHANGED
data/lib/crypto/box.rb
CHANGED
@@ -55,8 +55,10 @@ module Crypto
|
|
55
55
|
|
56
56
|
public_key = Sodium::Buffer.new(:uchar, PUBLICKEYBYTES)
|
57
57
|
secret_key = Sodium::Buffer.new(:uchar, SECRETKEYBYTES)
|
58
|
+
seed.readonly if seed.is_a?(Sodium::SecretBuffer)
|
58
59
|
crypto_box_seed_keypair(public_key, secret_key, seed)
|
59
|
-
|
60
|
+
seed.noaccess if seed.is_a?(Sodium::SecretBuffer)
|
61
|
+
|
60
62
|
[public_key, secret_key]
|
61
63
|
end
|
62
64
|
|
@@ -73,8 +75,10 @@ module Crypto
|
|
73
75
|
check_length(seed, SEEDBYTES, :Seed)
|
74
76
|
|
75
77
|
public_key = Sodium::Buffer.new(:uchar, PUBLICKEYBYTES)
|
76
|
-
secret_key = Sodium::SecretBuffer.new(
|
78
|
+
secret_key = Sodium::SecretBuffer.new(SECRETKEYBYTES)
|
79
|
+
seed.readonly if seed.is_a?(Sodium::SecretBuffer)
|
77
80
|
crypto_box_seed_keypair(public_key, secret_key, seed)
|
81
|
+
seed.noaccess if seed.is_a?(Sodium::SecretBuffer)
|
78
82
|
secret_key.noaccess
|
79
83
|
|
80
84
|
[public_key, secret_key]
|
@@ -86,7 +90,7 @@ module Crypto
|
|
86
90
|
check_length(public_key, PUBLICKEYBYTES, :PublicKey)
|
87
91
|
check_length(secret_key, SECRETKEYBYTES, :SecretKey)
|
88
92
|
|
89
|
-
ciphertext = Sodium::Buffer.new(:uchar,
|
93
|
+
ciphertext = Sodium::Buffer.new(:uchar, message_len + MACBYTES)
|
90
94
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
91
95
|
crypto_box_easy(ciphertext, message, message_len, nonce, public_key, secret_key)
|
92
96
|
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
@@ -49,7 +49,7 @@ module Crypto
|
|
49
49
|
RandomBytes.buf(SALTBYTES)
|
50
50
|
end
|
51
51
|
|
52
|
-
def scryptsalsa208sha256(
|
52
|
+
def scryptsalsa208sha256(outlen, passwd, salt, opslimit = OPSLIMIT_INTERACTIVE, memlimit = MEMLIMIT_INTERACTIVE)
|
53
53
|
passwd_len = get_size(passwd)
|
54
54
|
check_length(salt, SALTBYTES, :Salt)
|
55
55
|
if opslimit < OPSLIMIT_INTERACTIVE
|
data/lib/crypto/scalar_mult.rb
CHANGED
@@ -37,7 +37,7 @@ module Crypto
|
|
37
37
|
|
38
38
|
def scalarmut(secret_key, public_key)
|
39
39
|
check_length(secret_key, SCALARBYTES, :SecretKey)
|
40
|
-
check_length(public_key,
|
40
|
+
check_length(public_key, BYTES, :PublicKey)
|
41
41
|
|
42
42
|
shared_secret = Sodium::SecretBuffer.new(BYTES)
|
43
43
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
data/lib/crypto/secret_box.rb
CHANGED
@@ -35,7 +35,7 @@ module Crypto
|
|
35
35
|
check_length(nonce, NONCEBYTES, :Nonce)
|
36
36
|
check_length(key, KEYBYTES, :SecretKey)
|
37
37
|
|
38
|
-
ciphertext = Sodium::Buffer.new(:uchar,
|
38
|
+
ciphertext = Sodium::Buffer.new(:uchar, message_len + MACBYTES)
|
39
39
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
40
40
|
crypto_secretbox_easy(ciphertext, message, message_len, nonce, key)
|
41
41
|
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
data/lib/crypto/sign.rb
CHANGED
@@ -75,24 +75,25 @@ module Crypto
|
|
75
75
|
message_len = get_size(message)
|
76
76
|
check_length(secret_key, SECRETKEYBYTES, :SecretKey)
|
77
77
|
|
78
|
-
sealed_message =
|
79
|
-
sealed_message_len = FFI::MemoryPointer.new(:ulong_long)
|
78
|
+
sealed_message = Sodium::Buffer.new(:uchar, message_len + BYTES)
|
80
79
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
81
|
-
crypto_sign(sealed_message,
|
80
|
+
crypto_sign(sealed_message, nil, message, message_len, secret_key)
|
82
81
|
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
83
82
|
|
84
|
-
|
83
|
+
sealed_message
|
85
84
|
end
|
86
85
|
|
87
|
-
def open(sealed_message,
|
88
|
-
sealed_message_len =
|
86
|
+
def open(sealed_message, public_key)
|
87
|
+
sealed_message_len = get_size(sealed_message)
|
89
88
|
check_length(public_key, PUBLICKEYBYTES, :PublicKey)
|
90
89
|
|
91
|
-
unsealed_message =
|
90
|
+
unsealed_message = Sodium::Buffer.new(:uchar, sealed_message_len - BYTES)
|
92
91
|
unsealed_message_len = FFI::MemoryPointer.new(:ulong_long)
|
93
|
-
crypto_sign_open(unsealed_message, unsealed_message_len, sealed_message, sealed_message_len, public_key)
|
92
|
+
if crypto_sign_open(unsealed_message, unsealed_message_len, sealed_message, sealed_message_len, public_key) == -1
|
93
|
+
raise Sodium::CryptoError, "Incorrect signature", caller
|
94
|
+
end
|
94
95
|
|
95
|
-
|
96
|
+
unsealed_message
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
data/lib/sodium/utils.rb
CHANGED
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.6
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|