Beryl::Crypto::V1::HashBasedMessageAuthenticationCode(D)
HMAC (RFC 2104, FIPS 198-1): a message authentication code built on the
hash function D. Someone who holds the key can produce the tag for a
message; nobody else can produce or alter one.
D is any hash of this shard, for example HMAC(SHA256). The instance
streams like a ::Digest: update any number of times, then final for
the tag or verify to check a tag received from outside.
tag = Beryl::Crypto::V1::HMAC(Beryl::Crypto::V1::SHA256).authenticate("message", key: "secret key")
authentication = Beryl::Crypto::V1::HMAC(Beryl::Crypto::V1::SHA256).new("secret key")
authentication.update("mess").update("age")
authentication.verify(tag) # => true
The key is never kept: construction turns it into two keyed hash states and wipes the working copies. Checking a tag takes the same time whatever the key, the message or the candidate tag hold.
Constants
The shortest truncated tag verify accepts, in bytes: 80 bits
(RFC 2104 §5).
Constructors
Class methods
Returns the authentication tag of message under key in one call.
Instance methods
Returns an independent authentication under the same key that continues from the point this one has reached.
Finishes the authentication and returns whether authentication_tag is
the tag of everything passed to update.
The comparison runs in constant time, and a tag of the wrong length is refused only after the same hashing and the same comparison as a tag of the right length.
truncated_to_bytesize checks a tag that the protocol cuts to its
leading bytes (RFC 2104 §5). It must be at least half the full tag and
at least MINIMUM_TRUNCATED_TAG_BYTESIZE; anything shorter raises
TruncatedTagTooShort.