How do I generate a HMAC code? How can I generate a HMAC code in Drupal 8?

In plain PHP, I would use hash_hmac(). Is there a more specific method/function, in Drupal 8?
You could still hash_hmac() in Drupal 8. Drupal 8 has a static function that returns the HMAC given a couple of data and key arguments (Drupal\Component\Utility\Crypt::hmacBase64()). The differences are the following.

Crypt::hmacBase64() returns the Base64-encoded HMAC value
Crypt::hmacBase64() replaces some characters to make the string safe to use in URLs
Crypt::hmacBase64() raises an exception when the arguments are not using the expected datatype

If you don't need to encode the HMAC value in Base64, or to pass the HMAC value in URLs, you can use hash_hmac(). You could consider Drupal\Component\Utility\Crypt::hmacBase64() a wrapper around two PHP functions, since its code is the following one.
if (!is_scalar($data) || !is_scalar($key)) {
  throw new \InvalidArgumentException('Both parameters passed to \Drupal\Component\Utility\Crypt::hmacBase64 must be scalar values.');
}

$hmac = base64_encode(hash_hmac('sha256', $data, $key, TRUE));
return str_replace(['+', '/', '='], ['-', '_', ''], $hmac);