Class: RbNaCl::HMAC::SHA512256
- Extended by:
- Sodium
- Defined in:
- lib/rbnacl/hmac/sha512256.rb
Overview
Computes an authenticator as HMAC-SHA-512 truncated to 256-bits
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.
Defined Under Namespace
Classes: SHA512256State, State
Constant Summary
Constants inherited from Auth
Instance Method Summary collapse
-
#digest ⇒ String
Return the authenticator, as raw bytes.
-
#hexdigest ⇒ String
Return the authenticator, as hex string.
-
#initialize(key) ⇒ SHA512256
constructor
Create instance without checking key length.
-
#update(message) ⇒ Object
Compute authenticator for message.
Methods included from Sodium
primitive, sodium_constant, sodium_function, sodium_function_with_return_code, sodium_primitive, sodium_type
Methods inherited from Auth
auth, #auth, #key_bytes, key_bytes, #primitive, #tag_bytes, tag_bytes, #verify, verify
Constructor Details
#initialize(key) ⇒ SHA512256
Create instance without checking key length
RFC 2104 HMAC The key for HMAC can be of any length.
43 44 45 46 47 48 49 |
# File 'lib/rbnacl/hmac/sha512256.rb', line 43 def initialize(key) @key = Util.check_hmac_key(key, "#{self.class} key") @state = State.new @authenticator = Util.zeros(tag_bytes) self.class.auth_hmacsha512256_init(@state, key, key.bytesize) end |
Instance Method Details
#digest ⇒ String
Return the authenticator, as raw bytes
64 65 66 |
# File 'lib/rbnacl/hmac/sha512256.rb', line 64 def digest @authenticator end |
#hexdigest ⇒ String
Return the authenticator, as hex string
71 72 73 |
# File 'lib/rbnacl/hmac/sha512256.rb', line 71 def hexdigest @authenticator.unpack("H*").last end |
#update(message) ⇒ Object
Compute authenticator for message
54 55 56 57 58 59 |
# File 'lib/rbnacl/hmac/sha512256.rb', line 54 def update() self.class.auth_hmacsha512256_update(@state, , .bytesize) self.class.auth_hmacsha512256_final(@state.clone, @authenticator) hexdigest end |