Sha256: a020e30ad62cf47a99d2de81d869503e7bbae5f010a2f019ca2a852fb90d170d

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

# encoding: binary
# frozen_string_literal: true

module RbNaCl
  module HMAC
    # Computes an authenticator as HMAC-SHA-256
    #
    # The authenticator can be used at a later time to verify the provenance of
    # the message by recomputing the HMAC over the message and then comparing it to
    # the provided authenticator.  The class provides methods for generating
    # signatures and also has a constant-time implementation for checking them.
    #
    # This is a secret key authenticator, i.e. anyone who can verify signatures
    # can also create them.
    #
    # @see http://nacl.cr.yp.to/auth.html
    class SHA256 < Auth
      extend Sodium

      sodium_type :auth
      sodium_primitive :hmacsha256
      sodium_constant :BYTES
      sodium_constant :KEYBYTES

      sodium_function :auth_hmacsha256,
                      :crypto_auth_hmacsha256,
                      [:pointer, :pointer, :ulong_long, :pointer]

      sodium_function :auth_hmacsha256_verify,
                      :crypto_auth_hmacsha256_verify,
                      [:pointer, :pointer, :ulong_long, :pointer]

      private

      def compute_authenticator(authenticator, message)
        self.class.auth_hmacsha256(authenticator, message, message.bytesize, key)
      end

      def verify_message(authenticator, message)
        self.class.auth_hmacsha256_verify(authenticator, message, message.bytesize, key)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rbnacl-5.0.0 lib/rbnacl/hmac/sha256.rb
rbnacl-4.0.2 lib/rbnacl/hmac/sha256.rb
rbnacl-4.0.1 lib/rbnacl/hmac/sha256.rb
rbnacl-4.0.0 lib/rbnacl/hmac/sha256.rb
rbnacl-4.0.0.pre lib/rbnacl/hmac/sha256.rb