rbnacl 1.1.0 → 2.0.0.pre

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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -5
  3. data/CHANGES.md +15 -0
  4. data/Gemfile +4 -1
  5. data/Guardfile +8 -0
  6. data/README.md +52 -3
  7. data/lib/rbnacl.rb +65 -29
  8. data/lib/rbnacl/auth.rb +14 -18
  9. data/lib/rbnacl/boxes/curve25519xsalsa20poly1305.rb +185 -0
  10. data/lib/rbnacl/{keys → boxes/curve25519xsalsa20poly1305}/private_key.rb +26 -23
  11. data/lib/rbnacl/{keys → boxes/curve25519xsalsa20poly1305}/public_key.rb +13 -12
  12. data/lib/rbnacl/group_elements/curve25519.rb +81 -0
  13. data/lib/rbnacl/hash.rb +30 -14
  14. data/lib/rbnacl/hash/blake2b.rb +57 -0
  15. data/lib/rbnacl/hash/sha256.rb +15 -0
  16. data/lib/rbnacl/hash/sha512.rb +15 -0
  17. data/lib/rbnacl/hmac/sha256.rb +19 -17
  18. data/lib/rbnacl/hmac/sha512256.rb +18 -19
  19. data/lib/rbnacl/init.rb +10 -0
  20. data/lib/rbnacl/{keys/key_comparator.rb → key_comparator.rb} +1 -1
  21. data/lib/rbnacl/{auth/one_time.rb → one_time_auths/poly1305.rb} +21 -19
  22. data/lib/rbnacl/rake_tasks.rb +7 -6
  23. data/lib/rbnacl/random.rb +8 -3
  24. data/lib/rbnacl/random_nonce_box.rb +9 -14
  25. data/lib/rbnacl/secret_boxes/xsalsa20poly1305.rb +125 -0
  26. data/lib/rbnacl/self_test.rb +59 -40
  27. data/lib/rbnacl/serializable.rb +4 -12
  28. data/lib/rbnacl/signatures/ed25519.rb +15 -0
  29. data/lib/rbnacl/signatures/ed25519/signing_key.rb +104 -0
  30. data/lib/rbnacl/signatures/ed25519/verify_key.rb +91 -0
  31. data/lib/rbnacl/sodium.rb +43 -0
  32. data/lib/rbnacl/test_vectors.rb +34 -1
  33. data/lib/rbnacl/util.rb +52 -7
  34. data/lib/rbnacl/version.rb +2 -2
  35. data/rbnacl.gemspec +3 -6
  36. data/spec/rbnacl/{auth/one_time_spec.rb → authenticators/poly1305_spec.rb} +2 -2
  37. data/spec/rbnacl/boxes/curve25519xsalsa20poly1305/private_key_spec.rb +65 -0
  38. data/spec/rbnacl/{keys → boxes/curve25519xsalsa20poly1305}/public_key_spec.rb +10 -13
  39. data/spec/rbnacl/boxes/curve25519xsalsa20poly1305_spec.rb +39 -0
  40. data/spec/rbnacl/{point_spec.rb → group_element_spec.rb} +6 -8
  41. data/spec/rbnacl/hash/blake2b_spec.rb +26 -0
  42. data/spec/rbnacl/hash_spec.rb +13 -33
  43. data/spec/rbnacl/hmac/sha256_spec.rb +2 -2
  44. data/spec/rbnacl/hmac/sha512256_spec.rb +2 -2
  45. data/spec/rbnacl/random_nonce_box_spec.rb +21 -26
  46. data/spec/rbnacl/random_spec.rb +3 -3
  47. data/spec/rbnacl/secret_box_spec.rb +6 -6
  48. data/spec/rbnacl/signatures/ed25519/signing_key_spec.rb +30 -0
  49. data/spec/rbnacl/signatures/ed25519/verify_key_spec.rb +39 -0
  50. data/spec/rbnacl/util_spec.rb +67 -53
  51. data/spec/shared/authenticator.rb +36 -54
  52. data/spec/shared/box.rb +10 -10
  53. data/spec/shared/key_equality.rb +3 -3
  54. data/spec/shared/serializable.rb +17 -0
  55. data/spec/spec_helper.rb +14 -16
  56. data/tasks/rspec.rake +1 -0
  57. metadata +42 -67
  58. checksums.yaml.gz.sig +0 -0
  59. data.tar.gz.sig +0 -3
  60. data/lib/rbnacl/box.rb +0 -171
  61. data/lib/rbnacl/encoder.rb +0 -44
  62. data/lib/rbnacl/encoders/base32.rb +0 -33
  63. data/lib/rbnacl/encoders/base64.rb +0 -30
  64. data/lib/rbnacl/encoders/hex.rb +0 -30
  65. data/lib/rbnacl/encoders/raw.rb +0 -12
  66. data/lib/rbnacl/keys/signing_key.rb +0 -95
  67. data/lib/rbnacl/keys/verify_key.rb +0 -96
  68. data/lib/rbnacl/nacl.rb +0 -146
  69. data/lib/rbnacl/point.rb +0 -70
  70. data/lib/rbnacl/secret_box.rb +0 -119
  71. data/spec/rbnacl/box_spec.rb +0 -42
  72. data/spec/rbnacl/encoder_spec.rb +0 -14
  73. data/spec/rbnacl/encoders/base32_spec.rb +0 -16
  74. data/spec/rbnacl/encoders/base64_spec.rb +0 -15
  75. data/spec/rbnacl/encoders/hex_spec.rb +0 -15
  76. data/spec/rbnacl/keys/private_key_spec.rb +0 -68
  77. data/spec/rbnacl/keys/signing_key_spec.rb +0 -39
  78. data/spec/rbnacl/keys/verify_key_spec.rb +0 -51
  79. metadata.gz.sig +0 -2
@@ -1,6 +1,7 @@
1
1
  # encoding: binary
2
- module Crypto
3
- # Crypto::Box private key. Keep it safe
2
+
3
+ module RbNaCl
4
+ # RbNaCl::Box private key. Keep it safe
4
5
  #
5
6
  # This class generates and stores NaCL private keys, as well as providing a
6
7
  # reference to the public key associated with this private key, if that's
@@ -9,12 +10,22 @@ module Crypto
9
10
  # Note that the documentation for NaCl refers to this as a secret key, but in
10
11
  # this library its a private key, to avoid confusing the issue with the
11
12
  # SecretBox, which does symmetric encryption.
12
- class PrivateKey
13
+ class Boxes::Curve25519XSalsa20Poly1305::PrivateKey
14
+
13
15
  include KeyComparator
14
16
  include Serializable
17
+
18
+ extend Sodium
19
+
20
+ sodium_type :box
21
+ sodium_primitive :curve25519xsalsa20poly1305
22
+
23
+ sodium_function :box_curve25519xsalsa20poly1305_keypair,
24
+ :crypto_box_curve25519xsalsa20poly1305_keypair,
25
+ [:pointer, :pointer]
15
26
 
16
27
  # The size of the key, in bytes
17
- BYTES = NaCl::CURVE25519_XSALSA20_POLY1305_SECRETKEY_BYTES
28
+ BYTES = Boxes::Curve25519XSalsa20Poly1305::PRIVATEKEYBYTES
18
29
 
19
30
  # Initializes a new PrivateKey for key operations.
20
31
  #
@@ -25,23 +36,23 @@ module Crypto
25
36
  # @param private_key [String] The private key
26
37
  # @param key_encoding [Symbol] The encoding of the key
27
38
  #
28
- # @raise [Crypto::LengthError] If the key is not valid after decoding.
39
+ # @raise [TypeError] If the key is nil
40
+ # @raise [RbNaCl::LengthError] If the key is not valid after decoding.
29
41
  #
30
42
  # @return A new PrivateKey
31
- def initialize(private_key, key_encoding = :raw)
32
- @private_key = Crypto::Encoder[key_encoding].decode(private_key)
33
- Util.check_length(@private_key, BYTES, "Private key")
43
+ def initialize(private_key)
44
+ @private_key = Util.check_string(private_key, BYTES, "Private key")
34
45
  end
35
46
 
36
47
  # Generates a new keypair
37
48
  #
38
- # @raise [Crypto::CryptoError] if key generation fails, due to insufficient randomness.
49
+ # @raise [RbNaCl::CryptoError] if key generation fails, due to insufficient randomness.
39
50
  #
40
- # @return [Crypto::PrivateKey] A new private key, with the associated public key also set.
51
+ # @return [RbNaCl::PrivateKey] A new private key, with the associated public key also set.
41
52
  def self.generate
42
- pk = Util.zeros(NaCl::CURVE25519_XSALSA20_POLY1305_PUBLICKEY_BYTES)
43
- sk = Util.zeros(NaCl::CURVE25519_XSALSA20_POLY1305_SECRETKEY_BYTES)
44
- NaCl.crypto_box_curve25519xsalsa20poly1305_keypair(pk, sk) || raise(CryptoError, "Failed to generate a key pair")
53
+ pk = Util.zeros(Boxes::Curve25519XSalsa20Poly1305::PUBLICKEYBYTES)
54
+ sk = Util.zeros(Boxes::Curve25519XSalsa20Poly1305::PRIVATEKEYBYTES)
55
+ self.box_curve25519xsalsa20poly1305_keypair(pk, sk) || raise(CryptoError, "Failed to generate a key pair")
45
56
  new(sk)
46
57
  end
47
58
 
@@ -56,22 +67,14 @@ module Crypto
56
67
  #
57
68
  # @return [PublicKey] the key
58
69
  def public_key
59
- @public_key ||= PublicKey.new(Point.base.mult(to_bytes))
60
- end
61
-
62
- # The crypto primitive the PrivateKey class is to be used for
63
- #
64
- # @return [Symbol] The primitive
65
- def self.primitive
66
- :curve25519_xsalsa20_poly1305
70
+ @public_key ||= PublicKey.new GroupElements::Curve25519.base.mult(to_bytes)
67
71
  end
68
-
72
+
69
73
  # The crypto primitive this PrivateKey is to be used for.
70
74
  #
71
75
  # @return [Symbol] The primitive
72
76
  def primitive
73
77
  self.class.primitive
74
78
  end
75
-
76
79
  end
77
80
  end
@@ -1,31 +1,31 @@
1
1
  # encoding: binary
2
- module Crypto
3
- # Crypto::Box public key. Send to your friends.
2
+
3
+ module RbNaCl
4
+ # RbNaCl::Box public key. Send it (securely!) to your friends.
4
5
  #
5
- # This class stores the NaCL public key, and provides some convience
6
+ # This class stores the NaCL public key, and provides some convenience
6
7
  # functions for working with it.
7
- class PublicKey
8
+ class Boxes::Curve25519XSalsa20Poly1305::PublicKey
9
+
8
10
  include KeyComparator
9
11
  include Serializable
10
12
 
11
13
  # The size of the key, in bytes
12
- BYTES = NaCl::CURVE25519_XSALSA20_POLY1305_PUBLICKEY_BYTES
14
+ BYTES = Boxes::Curve25519XSalsa20Poly1305::PUBLICKEYBYTES
13
15
 
14
16
  # Initializes a new PublicKey for key operations.
15
17
  #
16
18
  # Takes the (optionally encoded) public key bytes. This can be shared with
17
19
  # many people and used to establish key pairs with their private key, for
18
- # the exchanging of messages using a Crypto::Box
20
+ # the exchanging of messages using a RbNaCl::Box
19
21
  #
20
22
  # @param public_key [String] The public key
21
- # @param key_encoding [Symbol] The encoding of the key
22
23
  #
23
- # @raise [Crypto::LengthError] If the key is not valid after decoding.
24
+ # @raise [RbNaCl::LengthError] If the key is not valid after decoding.
24
25
  #
25
26
  # @return A new PublicKey
26
- def initialize(public_key, key_encoding = :raw)
27
- @public_key = Crypto::Encoder[key_encoding].decode(public_key)
28
- Util.check_length(@public_key, BYTES, "Public key")
27
+ def initialize(public_key)
28
+ @public_key = Util.check_string(public_key, BYTES, "Public key")
29
29
  end
30
30
 
31
31
  # The raw bytes of the key
@@ -39,7 +39,7 @@ module Crypto
39
39
  #
40
40
  # @return [Symbol] The primitive
41
41
  def self.primitive
42
- :curve25519_xsalsa20_poly1305
42
+ :curve25519xsalsa20poly1305
43
43
  end
44
44
 
45
45
  # The crypto primitive this PublicKey is to be used for.
@@ -49,4 +49,5 @@ module Crypto
49
49
  self.class.primitive
50
50
  end
51
51
  end
52
+
52
53
  end
@@ -0,0 +1,81 @@
1
+ # encoding: binary
2
+ module RbNaCl
3
+ module GroupElements
4
+ # Points provide the interface to NaCl's Curve25519 high-speed elliptic
5
+ # curve cryptography, which can be used for implementing Diffie-Hellman
6
+ # and other forms of public key cryptography (e.g. RbNaCl::Box)
7
+ #
8
+ # Objects of the Point class represent points on Edwards curves. NaCl
9
+ # defines a base point (the "standard group element") which we can
10
+ # multiply by an arbitrary integer. This is how NaCl computes public
11
+ # keys from private keys.
12
+ class Curve25519
13
+ # NaCl's Curve25519 base point (a.k.a. standard group element), serialized as hex
14
+ STANDARD_GROUP_ELEMENT = ["0900000000000000000000000000000000000000000000000000000000000000"].pack("H*").freeze
15
+
16
+ # Order of the standard group
17
+ STANDARD_GROUP_ORDER = 2**252 + 27742317777372353535851937790883648493
18
+
19
+ include KeyComparator
20
+ include Serializable
21
+
22
+ extend Sodium
23
+
24
+ sodium_type :scalarmult
25
+ sodium_primitive :curve25519
26
+
27
+ sodium_function :scalarmult_curve25519,
28
+ :crypto_scalarmult_curve25519,
29
+ [:pointer, :pointer, :pointer]
30
+
31
+ # Number of bytes in a scalar on this curve
32
+ SCALARBYTES = 32
33
+ BYTES = 32
34
+
35
+ # Number of bytes in a scalar on this curve
36
+
37
+ # Creates a new Point from the given serialization
38
+ #
39
+ # @param [String] point location of a group element (32-bytes)
40
+ #
41
+ # @return [RbNaCl::Point] the Point at this location
42
+ def initialize(point)
43
+ @point = point.to_str
44
+
45
+ # FIXME: really should have a separate constant here for group element size
46
+ # Group elements and scalars are both 32-bits, but that's for convenience
47
+ Util.check_length(@point, SCALARBYTES, "group element")
48
+ end
49
+
50
+ # Multiply the given integer by this point
51
+ # This ordering is a bit confusing because traditionally the point
52
+ # would be the right-hand operand.
53
+ #
54
+ # @param [String] integer value to multiply with this Point (32-bytes)
55
+ #
56
+ # @return [RbNaCl::Point] result as a Point object
57
+ def mult(integer, encoding = :raw)
58
+ integer = integer.to_str
59
+ Util.check_length(integer, SCALARBYTES, "integer")
60
+
61
+ result = Util.zeros(SCALARBYTES)
62
+ self.class.scalarmult_curve25519(result, integer, @point)
63
+
64
+ self.class.new(result)
65
+ end
66
+
67
+ # Return the point serialized as bytes
68
+ #
69
+ # @return [String] 32-byte string representing this point
70
+ def to_bytes; @point; end
71
+
72
+ @base_point = new(STANDARD_GROUP_ELEMENT)
73
+
74
+ # NaCl's standard base point for all Curve25519 public keys
75
+ #
76
+ # @return [RbNaCl::Point] standard base point (a.k.a. standard group element)
77
+ def self.base; @base_point; end
78
+ def self.base_point; @base_point; end
79
+ end
80
+ end
81
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- module Crypto
2
+ module RbNaCl
3
3
  # Cryptographic hash functions
4
4
  #
5
5
  # Cryptographic hash functions take a variable length message and compute a
@@ -11,38 +11,54 @@ module Crypto
11
11
  # there is no secret involved in the hashing, so anyone can create the hash of
12
12
  # a given message.
13
13
  #
14
- # RbNaCl provides the SHA-256 and SHA-512 hash functions.
14
+ # RbNaCl provides the SHA-256,SHA-512 as well as the Blake2b hash functions.
15
15
  module Hash
16
16
  # Returns the SHA-256 hash of the given data
17
17
  #
18
18
  # There's no streaming done, just pass in the data and be done with it.
19
19
  #
20
- # @param [String] data The data, as a collection of bytes
21
- # @param [#to_sym] encoding Encoding of the returned hash.
20
+ # @param [#to_str] data The data, as a collection of bytes
22
21
  #
23
22
  # @raise [CryptoError] If the hashing fails for some reason.
24
23
  #
25
24
  # @return [String] The SHA-256 hash as raw bytes (Or encoded as per the second argument)
26
- def self.sha256(data, encoding = :raw)
27
- hash = Util.zeros(NaCl::SHA256BYTES)
28
- NaCl.crypto_hash_sha256(hash, data, data.bytesize) || raise(CryptoError, "Hashing failed!")
29
- Encoder[encoding].encode(hash)
25
+ def self.sha256(data)
26
+ data = data.to_str
27
+ digest = Util.zeros(SHA256::BYTES)
28
+ SHA256.hash_sha256(digest, data, data.bytesize) || raise(CryptoError, "Hashing failed!")
29
+ digest
30
30
  end
31
31
 
32
32
  # Returns the SHA-512 hash of the given data
33
33
  #
34
34
  # There's no streaming done, just pass in the data and be done with it.
35
35
  #
36
- # @param [String] data The data, as a collection of bytes
37
- # @param [#to_sym] encoding Encoding of the returned hash.
36
+ # @param [#to_str] data The data, as a collection of bytes
38
37
  #
39
38
  # @raise [CryptoError] If the hashing fails for some reason.
40
39
  #
41
40
  # @return [String] The SHA-512 hash as raw bytes (Or encoded as per the second argument)
42
- def self.sha512(data, encoding = :raw)
43
- hash = Util.zeros(NaCl::SHA512BYTES)
44
- NaCl.crypto_hash_sha512(hash, data, data.bytesize) || raise(CryptoError, "Hashing failed!")
45
- Encoder[encoding].encode(hash)
41
+ def self.sha512(data)
42
+ digest = Util.zeros(SHA512::BYTES)
43
+ SHA512.hash_sha512(digest, data, data.bytesize) || raise(CryptoError, "Hashing failed!")
44
+ digest
45
+ end
46
+
47
+ # Returns the Blake2b hash of the given data
48
+ #
49
+ # There's no streaming done, just pass in the data and be done with it.
50
+ # This method returns a 64-byte hash by default.
51
+ #
52
+ # @param [String] data The data, as a collection of bytes
53
+ # @option options [Fixnum] digest_size Size in bytes (1-64, default 64)
54
+ # @option options [String] key 64-byte (or less) key for keyed mode
55
+ #
56
+ # @raise [CryptoError] If the hashing fails for some reason.
57
+ #
58
+ # @return [String] The blake2b hash as raw bytes (Or encoded as per the second argument)
59
+ def self.blake2b(data, options = {})
60
+ key = options[:key]
61
+ Blake2b.new(options).digest(data)
46
62
  end
47
63
  end
48
64
  end
@@ -0,0 +1,57 @@
1
+ # encoding: binary
2
+ module RbNaCl
3
+ module Hash
4
+ # The Blake2b hash function
5
+ #
6
+ # Blake2b is based on Blake, a SHA3 finalist which was snubbed in favor of
7
+ # Keccak, a much slower hash function but one sufficiently different from
8
+ # SHA2 to let the SHA3 judges panel sleep easy. Back in the real world,
9
+ # it'd be great if we can calculate hashes quickly if possible.
10
+ #
11
+ # Blake2b provides for up to 64-bit digests and also supports a keyed mode
12
+ # similar to HMAC
13
+ class Blake2b
14
+ extend Sodium
15
+
16
+ sodium_type :generichash
17
+ sodium_primitive :blake2b
18
+ sodium_constant :BYTES_MIN
19
+ sodium_constant :BYTES_MAX
20
+ sodium_constant :KEYBYTES_MIN
21
+ sodium_constant :KEYBYTES_MAX
22
+
23
+ sodium_function :generichash_blake2b,
24
+ :crypto_generichash_blake2b,
25
+ [:pointer, :ulong_long, :pointer, :ulong_long, :pointer, :ulong_long]
26
+
27
+ # Create a new Blake2b hash object
28
+ #
29
+ # @param [Hash] opts Blake2b configuration
30
+ # @option opts [String] :key for Blake2b keyed mode
31
+ # @option opts [Integer] :digest_size size of output digest in bytes
32
+ #
33
+ # @raise [RbNaCl::LengthError] Invalid length specified for one or more options
34
+ #
35
+ # @return [RbNaCl::Hash::Blake2b] A Blake2b hasher object
36
+ def initialize(opts = {})
37
+ @key = opts.fetch(:key, nil)
38
+ @key_size = @key ? @key.bytesize : 0
39
+ raise LengthError, "Invalid key size" if (@key_size != 0) && (@key_size < KEYBYTES_MIN || @key_size > KEYBYTES_MAX)
40
+
41
+ @digest_size = opts.fetch(:digest_size, BYTES_MAX)
42
+ raise LengthError, "Invalid digest size" if @digest_size < BYTES_MIN || @digest_size > BYTES_MAX
43
+ end
44
+
45
+ # Calculate a Blake2b digest
46
+ #
47
+ # @param [String] message Message to be hashed
48
+ #
49
+ # @return [String] Blake2b digest of the string as raw bytes
50
+ def digest(message)
51
+ digest = Util.zeros(@digest_size)
52
+ self.class.generichash_blake2b(digest, @digest_size, message, message.bytesize, @key, @key_size) || raise(CryptoError, "Hashing failed!")
53
+ digest
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: binary
2
+ module RbNaCl
3
+ module Hash
4
+ # Provides a binding for the SHA256 function in libsodium
5
+ module SHA256
6
+ extend Sodium
7
+ sodium_type :hash
8
+ sodium_primitive :sha256
9
+ sodium_constant :BYTES
10
+ sodium_function :hash_sha256,
11
+ :crypto_hash_sha256,
12
+ [:pointer, :pointer, :ulong_long]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: binary
2
+ module RbNaCl
3
+ module Hash
4
+ # Provides the binding for the SHA512 hash function
5
+ module SHA512
6
+ extend Sodium
7
+ sodium_type :hash
8
+ sodium_primitive :sha512
9
+ sodium_constant :BYTES
10
+ sodium_function :hash_sha512,
11
+ :crypto_hash_sha512,
12
+ [:pointer, :pointer, :ulong_long]
13
+ end
14
+ end
15
+ end
@@ -1,9 +1,9 @@
1
1
  # encoding: binary
2
- module Crypto
2
+ module RbNaCl
3
3
  module HMAC
4
4
  # Computes an authenticator as HMAC-SHA-256
5
5
  #
6
- # The authenticator can be used at a later time to verify the provenence of
6
+ # The authenticator can be used at a later time to verify the provenance of
7
7
  # the message by recomputing the HMAC over the message and then comparing it to
8
8
  # the provided authenticator. The class provides methods for generating
9
9
  # signatures and also has a constant-time implementation for checking them.
@@ -13,26 +13,28 @@ module Crypto
13
13
  #
14
14
  # @see http://nacl.cr.yp.to/auth.html
15
15
  class SHA256 < Auth
16
- # Number of bytes in a valid key
17
- KEYBYTES = NaCl::HMACSHA256_KEYBYTES
16
+ extend Sodium
18
17
 
19
- # Number of bytes in a valid authenticator
20
- BYTES = NaCl::HMACSHA256_BYTES
21
-
22
- # The crypto primitive for the HMAC::SHA256 class
23
- #
24
- # @return [Symbol] The primitive used
25
- def self.primitive
26
- :hmac_sha256
27
- end
18
+ sodium_type :auth
19
+ sodium_primitive :hmacsha256
20
+ sodium_constant :BYTES
21
+ sodium_constant :KEYBYTES
28
22
 
23
+ sodium_function :auth_hmacsha256,
24
+ :crypto_auth_hmacsha256,
25
+ [:pointer, :pointer, :ulong_long, :pointer]
26
+
27
+ sodium_function :auth_hmacsha256_verify,
28
+ :crypto_auth_hmacsha256_verify,
29
+ [:pointer, :pointer, :ulong_long, :pointer]
30
+
29
31
  private
30
- def compute_authenticator(message, authenticator)
31
- NaCl.crypto_auth_hmacsha256(authenticator, message, message.bytesize, key)
32
+ def compute_authenticator(authenticator, message)
33
+ self.class.auth_hmacsha256(authenticator, message, message.bytesize, key)
32
34
  end
33
35
 
34
- def verify_message(message, authenticator)
35
- NaCl.crypto_auth_hmacsha256_verify(authenticator, message, message.bytesize, key)
36
+ def verify_message(authenticator, message)
37
+ self.class.auth_hmacsha256_verify(authenticator, message, message.bytesize, key)
36
38
  end
37
39
  end
38
40
  end