ffi-libsodium 0.1.1 → 0.1.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 +1 -1
- data/lib/crypto/box.rb +4 -4
- data/lib/crypto/generic_hash.rb +3 -3
- data/lib/crypto/pw_hash/scrypt_salsa208_sha256.rb +7 -7
- data/lib/crypto/secret_box.rb +1 -1
- data/lib/libsodium.rb +2 -1
- data/lib/sodium/errors.rb +5 -0
- data/lib/sodium/utils.rb +7 -6
- data/lib/sodium/version.rb +1 -1
- data/lib/sodium.rb +5 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a64973f4ee49434ae79e0981dedabdade25b65cc
|
4
|
+
data.tar.gz: 903493fc260cb41a5914b796e7e9c01ca593bc5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c84186666cb598453a1967930137a11d6bdc2ceb8b2b1cc49bdbad37625636aed4859edd860ab772b3d3e0b15cfe65e12f5988dddebf7d9efd8398364e42b92c
|
7
|
+
data.tar.gz: 2f771787c58557835b65687e7ab65d021a981a37058a04be965ce3d64341fb86fcdbb1099d9382164c8fce3cc403e1cce9d7fe96c15b4668f57d8e1108866b26
|
@@ -3,7 +3,7 @@ require_relative '../../sodium/utils'
|
|
3
3
|
require_relative '../../random_bytes'
|
4
4
|
require_relative '../../sodium/buffer'
|
5
5
|
require_relative '../../sodium/secret_buffer'
|
6
|
-
require_relative '../../sodium'
|
6
|
+
require_relative '../../sodium/errors'
|
7
7
|
|
8
8
|
module Crypto
|
9
9
|
module AEAD
|
data/lib/crypto/box.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative '../sodium/utils'
|
|
3
3
|
require_relative '../random_bytes'
|
4
4
|
require_relative '../sodium/buffer'
|
5
5
|
require_relative '../sodium/secret_buffer'
|
6
|
-
require_relative '../sodium'
|
6
|
+
require_relative '../sodium/errors'
|
7
7
|
|
8
8
|
module Crypto
|
9
9
|
module Box
|
@@ -29,8 +29,8 @@ module Crypto
|
|
29
29
|
attach_function :crypto_box_keypair, [:buffer_out, :buffer_out], :int, blocking: true
|
30
30
|
attach_function :crypto_box_seed_keypair, [:buffer_out, :buffer_out, :buffer_in], :int, blocking: true
|
31
31
|
|
32
|
-
attach_function :crypto_box_easy,
|
33
|
-
attach_function :crypto_box_open_easy,
|
32
|
+
attach_function :crypto_box_easy, [:buffer_out, :buffer_in, :ulong_long, :buffer_in, :buffer_in, :buffer_in], :int, blocking: true
|
33
|
+
attach_function :crypto_box_open_easy, [:buffer_out, :buffer_in, :ulong_long, :buffer_in, :buffer_in, :buffer_in], :int, blocking: true
|
34
34
|
|
35
35
|
attach_function :crypto_box_beforenm, [:buffer_out, :buffer_in, :buffer_in], :int, blocking: true
|
36
36
|
|
@@ -152,7 +152,7 @@ module Crypto
|
|
152
152
|
check_length(secret_key, SECRETKEYBYTES, :SecretKey)
|
153
153
|
|
154
154
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
155
|
-
unless crypto_box_open_easy(ciphertext, ciphertext, ciphertext
|
155
|
+
unless crypto_box_open_easy(ciphertext, ciphertext, get_size(ciphertext), nonce, public_key, secret_key).zero?
|
156
156
|
raise Sodium::CryptoError, "Message forged", caller
|
157
157
|
end
|
158
158
|
|
data/lib/crypto/generic_hash.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'ffi'
|
2
2
|
require_relative '../sodium/utils'
|
3
|
-
require_relative '../sodium'
|
3
|
+
require_relative '../sodium/errors'
|
4
4
|
require_relative '../sodium/buffer'
|
5
5
|
require_relative '../sodium/secret_buffer'
|
6
6
|
|
@@ -47,7 +47,7 @@ module Crypto
|
|
47
47
|
|
48
48
|
def generichash(message, hash_size = BYTES, key = nil)
|
49
49
|
if hash_size > BYTES_MAX ||hash_size < BYTES_MIN
|
50
|
-
fail Sodium::LengthError, "Hash size must be between #{BYTES_MIN} and #{BYTES_MAX} bytes, got size=#{hash_size
|
50
|
+
fail Sodium::LengthError, "Hash size must be between #{BYTES_MIN} and #{BYTES_MAX} bytes, got size=#{hash_size} bytes", caller
|
51
51
|
end
|
52
52
|
|
53
53
|
if key
|
@@ -84,7 +84,7 @@ module Crypto
|
|
84
84
|
end
|
85
85
|
|
86
86
|
if hash_size > BYTES_MAX ||hash_size < BYTES_MIN
|
87
|
-
fail Sodium::LengthError, "Hash size must be between #{BYTES_MIN} and #{BYTES_MAX} bytes, got size=#{hash_size
|
87
|
+
fail Sodium::LengthError, "Hash size must be between #{BYTES_MIN} and #{BYTES_MAX} bytes, got size=#{hash_size} bytes", caller
|
88
88
|
end
|
89
89
|
|
90
90
|
state = State.new
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'ffi'
|
2
2
|
require_relative '../../sodium/utils'
|
3
3
|
require_relative '../../random_bytes'
|
4
|
-
require_relative '../../sodium'
|
4
|
+
require_relative '../../sodium/errors'
|
5
5
|
require_relative '../../sodium/secret_buffer'
|
6
6
|
|
7
7
|
module Crypto
|
@@ -52,15 +52,15 @@ module Crypto
|
|
52
52
|
out = nil
|
53
53
|
check_length(salt, SALTBYTES, :Salt)
|
54
54
|
if opslimit < OPSLIMIT_INTERACTIVE
|
55
|
-
fail Sodium::LengthError, "Opslimit must be at least #{OPSLIMIT_INTERACTIVE}, got #{opslimit
|
55
|
+
fail Sodium::LengthError, "Opslimit must be at least #{OPSLIMIT_INTERACTIVE}, got #{opslimit}", caller
|
56
56
|
end
|
57
57
|
if memlimit < MEMLIMIT_INTERACTIVE
|
58
|
-
fail Sodium::LengthError, "Memlimit must be at least #{MEMLIMIT_INTERACTIVE}, got #{memlimit
|
58
|
+
fail Sodium::LengthError, "Memlimit must be at least #{MEMLIMIT_INTERACTIVE}, got #{memlimit}", caller
|
59
59
|
end
|
60
60
|
|
61
61
|
out = Sodium::SecretBuffer.new(outlen, PRIMITIVE)
|
62
62
|
unless crypto_pwhash_scryptsalsa208sha256(out, outlen, passwd, get_size(passwd), salt, opslimit, memlimit).zero?
|
63
|
-
raise NoMemoryError, "Failed to allocate memory max size=#{memlimit
|
63
|
+
raise NoMemoryError, "Failed to allocate memory max size=#{memlimit} bytes", caller
|
64
64
|
end
|
65
65
|
|
66
66
|
out
|
@@ -70,15 +70,15 @@ module Crypto
|
|
70
70
|
|
71
71
|
def str(passwd, opslimit = OPSLIMIT_INTERACTIVE, memlimit = MEMLIMIT_INTERACTIVE)
|
72
72
|
if opslimit < OPSLIMIT_INTERACTIVE
|
73
|
-
fail Sodium::LengthError, "Opslimit must be at least #{OPSLIMIT_INTERACTIVE}, got #{opslimit
|
73
|
+
fail Sodium::LengthError, "Opslimit must be at least #{OPSLIMIT_INTERACTIVE}, got #{opslimit}", caller
|
74
74
|
end
|
75
75
|
if memlimit < MEMLIMIT_INTERACTIVE
|
76
|
-
fail Sodium::LengthError, "Memlimit must be at least #{MEMLIMIT_INTERACTIVE}, got #{memlimit
|
76
|
+
fail Sodium::LengthError, "Memlimit must be at least #{MEMLIMIT_INTERACTIVE}, got #{memlimit}", caller
|
77
77
|
end
|
78
78
|
|
79
79
|
hashed_password = FFI::MemoryPointer.new(:char, STRBYTES)
|
80
80
|
unless crypto_pwhash_scryptsalsa208sha256_str(hashed_password, passwd, get_size(passwd), opslimit, memlimit).zero?
|
81
|
-
raise NoMemoryError, "Failed to allocate memory max size=#{memlimit
|
81
|
+
raise NoMemoryError, "Failed to allocate memory max size=#{memlimit} bytes", caller
|
82
82
|
end
|
83
83
|
|
84
84
|
hashed_password.get_string(0)
|
data/lib/crypto/secret_box.rb
CHANGED
@@ -87,7 +87,7 @@ module Crypto
|
|
87
87
|
check_length(key, KEYBYTES, :SecretKey)
|
88
88
|
|
89
89
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
90
|
-
unless crypto_secretbox_open_easy(ciphertext, ciphertext, ciphertext
|
90
|
+
unless crypto_secretbox_open_easy(ciphertext, ciphertext, get_size(ciphertext), nonce, key).zero?
|
91
91
|
raise Sodium::CryptoError, "Message forged", caller
|
92
92
|
end
|
93
93
|
|
data/lib/libsodium.rb
CHANGED
data/lib/sodium/utils.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '../sodium'
|
1
|
+
require_relative '../sodium/errors'
|
2
2
|
require 'ffi'
|
3
3
|
|
4
4
|
module Sodium
|
@@ -8,16 +8,17 @@ module Sodium
|
|
8
8
|
|
9
9
|
def check_length(data, length, description)
|
10
10
|
if data.is_a?(String) ||data.respond_to?(:bytesize)
|
11
|
-
unless data.bytesize == length
|
12
|
-
fail Sodium::LengthError, "Expected a length=#{length
|
11
|
+
unless data.bytesize == length
|
12
|
+
fail Sodium::LengthError, "Expected a length=#{length} bytes #{description}, got size=#{data.bytesize} bytes", caller
|
13
13
|
end
|
14
14
|
elsif data.is_a?(FFI::Pointer) ||data.respond_to?(:size)
|
15
|
-
unless data.size == length
|
16
|
-
fail Sodium::LengthError, "Expected a length=#{length
|
15
|
+
unless data.size == length
|
16
|
+
fail Sodium::LengthError, "Expected a length=#{length} bytes #{description}, got size=#{data.size} bytes", caller
|
17
17
|
end
|
18
18
|
else
|
19
|
-
fail ArgumentError, "#{description} must be of type String or FFI::Pointer and be length=#{length
|
19
|
+
fail ArgumentError, "#{description} must be of type String or FFI::Pointer and be length=#{length} bytes long", caller
|
20
20
|
end
|
21
|
+
|
21
22
|
true
|
22
23
|
end
|
23
24
|
|
data/lib/sodium/version.rb
CHANGED
data/lib/sodium.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
require 'ffi'
|
2
|
+
require_relative 'sodium/errors'
|
2
3
|
|
3
4
|
module Sodium
|
4
|
-
class CryptoError < StandardError; end
|
5
|
-
class LengthError < ArgumentError; end
|
6
|
-
class MemoryError < StandardError; end
|
7
|
-
|
8
5
|
extend FFI::Library
|
9
6
|
ffi_lib :libsodium
|
10
7
|
|
@@ -25,26 +22,26 @@ module Sodium
|
|
25
22
|
|
26
23
|
def mlock(addr, len)
|
27
24
|
unless sodium_mlock(addr, len).zero?
|
28
|
-
raise MemoryError, "Could not lock length=#{len
|
25
|
+
raise MemoryError, "Could not lock length=#{len} bytes memory at address=#{addr.address}", caller
|
29
26
|
end
|
30
27
|
end
|
31
28
|
|
32
29
|
def munlock(addr, len)
|
33
30
|
unless sodium_munlock(addr, len).zero?
|
34
|
-
raise MemoryError, "Could not unlock length=#{len
|
31
|
+
raise MemoryError, "Could not unlock length=#{len} bytes memory at address=#{addr.address}", caller
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
35
|
def malloc(size)
|
39
36
|
unless (mem = sodium_malloc(size))
|
40
|
-
raise NoMemoryError, "Failed to allocate memory size=#{size
|
37
|
+
raise NoMemoryError, "Failed to allocate memory size=#{size} bytes", caller
|
41
38
|
end
|
42
39
|
mem
|
43
40
|
end
|
44
41
|
|
45
42
|
def allocarray(count, size)
|
46
43
|
unless (mem = sodium_allocarray(count, size))
|
47
|
-
raise NoMemoryError, "Failed to allocate memory size=#{count
|
44
|
+
raise NoMemoryError, "Failed to allocate memory size=#{count * size} bytes", caller
|
48
45
|
end
|
49
46
|
mem
|
50
47
|
end
|
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.1.
|
4
|
+
version: 0.1.2
|
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-12-
|
11
|
+
date: 2014-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/random_bytes.rb
|
62
62
|
- lib/sodium.rb
|
63
63
|
- lib/sodium/buffer.rb
|
64
|
+
- lib/sodium/errors.rb
|
64
65
|
- lib/sodium/secret_buffer.rb
|
65
66
|
- lib/sodium/utils.rb
|
66
67
|
- lib/sodium/version.rb
|