HMACs should be used when producing a cookie or hash based on data and a key. Simple mechanisms for using SHA1 and other algorithms to digest a key and data together are vulnerable to various security issues. HMAC uses algorithms like SHA1 in a secure way to produce a digest of a key and data.
Both the key and data are arbitrary byte arrays of bytes or characters.
Support for HMAC Digests has been added in GLib 2.30, and support for SHA-512 in GLib 2.42. Support for SHA-384 was added in GLib 2.52.
To create a new <GHmac>, use hmac:new. To free a <GHmac>, use
hmac:unref.
Copies a <GHmac>. If self has been closed, by
calling hmac:get-string or hmac:get-digest, the copied HMAC will be closed as well.
Passed: a <GHmac>.
the <GHmac> to copy
Returned: a <GHmac>.
the copy of the passed <GHmac>. Use hmac:unref when finished using it.
Gets the digest from checksum as a raw binary array and places it into buffer. The size of the digest depends on the type of checksum.
Once this function has been called, the <GHmac> is
closed and can no longer be updated with checksum:update.
Passed: a <GHmac>.
a <GHmac>
Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.
output buffer
Not passed: guile-gi gives the length of buffer.
an inout parameter. The caller initializes it to the size of buffer. After the call it contains the length of the digest
Gets the HMAC as a hexadecimal string.
Once this function has been called the <GHmac> can no
longer be updated with hmac:update.
The hexadecimal characters will be lower case.
Creates a new <GHmac>, using the digest algorithm
digest-type. If the digest-type is not known, #f is
returned. A <GHmac> can be used to compute the HMAC
of a key and an arbitrary binary blob, using different hashing
algorithms.
A <GHmac> works by feeding a binary blob through
hmac:update until the data is complete; the
digest can then be extracted using hmac:get-string, which will return the checksum as a
hexadecimal string; or hmac:get-digest,
which will return a array of raw bytes. Once either hmac:get-string or hmac:get-digest have been called on a
<GHmac>, the HMAC will be closed and it won’t be
possible to call hmac:update on it anymore.
Support for digests of type sha512 has been
added in GLib 2.42. Support for sha384 was
added in GLib 2.52.
Passed: a <%GChecksumType>, or one of its
symbols.
the desired type of digest
Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.
the key for the HMAC
Returned: a <GHmac>, or #f.
the newly created <GHmac>, or #f. Use
hmac:unref to free the memory allocated by it.
Not passed: guile-gi gives the length of key.
the length of the keys
Atomically increments the reference count of self by one.
This function is MT-safe and may be called from any thread.
Atomically decrements the reference count of self by one.
If the reference count drops to 0, all keys and values will be destroyed, and all memory allocated by the hash table is released. This function is MT-safe and may be called from any thread. Frees the memory allocated for self.
Feeds data into an existing <GHmac>.
The HMAC must still be open, that is hmac:get-string or hmac:get-digest must not have been called on self.