We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Cannot use BLAKE2b or BLAKE2s with HMAC
Python 3.6.2 on Ubuntu 17.10
Cryptography and dependencies installed via pip in virtualenv
cffi==1.10.0
cryptography==2.0.3
pip==9.0.1
setuptools==36.2.7

Steps to reproduce:
```
In [1]: from cryptography.hazmat.backends import default_backend
   ...: from cryptography.hazmat.primitives import hashes
   ...: from cryptography.hazmat.primitives.hmac import HMAC
   ...: 
   ...: backend = default_backend()
   ...: 

In [2]: hmac = HMAC(b'\x00'*32, hashes.SHA256(), backend)  # just fine

In [3]: hmac = HMAC(b'\x00'*32, hashes.BLAKE2s(digest_size=32), backend)
---------------------------------------------------------------------------
UnsupportedAlgorithm                      Traceback (most recent call last)
<ipython-input-3-61f273a52c45> in <module>()
----> 1 hmac = HMAC(b'\x00'*32, hashes.BLAKE2s(digest_size=32), backend)

~/.venvs/master/lib/python3.6/site-packages/cryptography/hazmat/primitives/hmac.py in __init__(self, key, algorithm, backend, ctx)
     30         self._key = key
     31         if ctx is None:
---> 32             self._ctx = self._backend.create_hmac_ctx(key, self.algorithm)
     33         else:
     34             self._ctx = ctx

~/.venvs/master/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py in create_hmac_ctx(self, key, algorithm)
    176 
    177     def create_hmac_ctx(self, key, algorithm):
--> 178         return _HMACContext(self, key, algorithm)
    179 
    180     def _build_openssl_digest_name(self, algorithm):

~/.venvs/master/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/hmac.py in __init__(self, backend, key, algorithm, ctx)
     32                     "{0} is not a supported hash on this backend.".format(
     33                         algorithm.name),
---> 34                     _Reasons.UNSUPPORTED_HASH
     35                 )
     36             res = self._backend._lib.HMAC_Init_ex(

UnsupportedAlgorithm: blake2s is not a supported hash on this backend.
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/cryptography/hazmat/backends/openssl/hmac.py`
Content:
```
1 # This file is dual licensed under the terms of the Apache License, Version
2 # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3 # for complete details.
4 
5 from __future__ import absolute_import, division, print_function
6 
7 
8 from cryptography import utils
9 from cryptography.exceptions import (
10     InvalidSignature, UnsupportedAlgorithm, _Reasons
11 )
12 from cryptography.hazmat.primitives import constant_time, hashes, mac
13 
14 
15 @utils.register_interface(mac.MACContext)
16 @utils.register_interface(hashes.HashContext)
17 class _HMACContext(object):
18     def __init__(self, backend, key, algorithm, ctx=None):
19         self._algorithm = algorithm
20         self._backend = backend
21 
22         if ctx is None:
23             ctx = self._backend._lib.Cryptography_HMAC_CTX_new()
24             self._backend.openssl_assert(ctx != self._backend._ffi.NULL)
25             ctx = self._backend._ffi.gc(
26                 ctx, self._backend._lib.Cryptography_HMAC_CTX_free
27             )
28             evp_md = self._backend._lib.EVP_get_digestbyname(
29                 algorithm.name.encode('ascii'))
30             if evp_md == self._backend._ffi.NULL:
31                 raise UnsupportedAlgorithm(
32                     "{0} is not a supported hash on this backend.".format(
33                         algorithm.name),
34                     _Reasons.UNSUPPORTED_HASH
35                 )
36             res = self._backend._lib.HMAC_Init_ex(
37                 ctx, key, len(key), evp_md, self._backend._ffi.NULL
38             )
39             self._backend.openssl_assert(res != 0)
40 
41         self._ctx = ctx
42         self._key = key
43 
44     algorithm = utils.read_only_property("_algorithm")
45 
46     def copy(self):
47         copied_ctx = self._backend._lib.Cryptography_HMAC_CTX_new()
48         self._backend.openssl_assert(copied_ctx != self._backend._ffi.NULL)
49         copied_ctx = self._backend._ffi.gc(
50             copied_ctx, self._backend._lib.Cryptography_HMAC_CTX_free
51         )
52         res = self._backend._lib.HMAC_CTX_copy(copied_ctx, self._ctx)
53         self._backend.openssl_assert(res != 0)
54         return _HMACContext(
55             self._backend, self._key, self.algorithm, ctx=copied_ctx
56         )
57 
58     def update(self, data):
59         res = self._backend._lib.HMAC_Update(self._ctx, data, len(data))
60         self._backend.openssl_assert(res != 0)
61 
62     def finalize(self):
63         buf = self._backend._ffi.new("unsigned char[]",
64                                      self._backend._lib.EVP_MAX_MD_SIZE)
65         outlen = self._backend._ffi.new("unsigned int *")
66         res = self._backend._lib.HMAC_Final(self._ctx, buf, outlen)
67         self._backend.openssl_assert(res != 0)
68         self._backend.openssl_assert(outlen[0] == self.algorithm.digest_size)
69         return self._backend._ffi.buffer(buf)[:outlen[0]]
70 
71     def verify(self, signature):
72         digest = self.finalize()
73         if not constant_time.bytes_eq(digest, signature):
74             raise InvalidSignature("Signature did not match digest.")
75
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/cryptography/hazmat/backends/openssl/hmac.py b/src/cryptography/hazmat/backends/openssl/hmac.py
--- a/src/cryptography/hazmat/backends/openssl/hmac.py
+++ b/src/cryptography/hazmat/backends/openssl/hmac.py
@@ -25,12 +25,11 @@
             ctx = self._backend._ffi.gc(
                 ctx, self._backend._lib.Cryptography_HMAC_CTX_free
             )
-            evp_md = self._backend._lib.EVP_get_digestbyname(
-                algorithm.name.encode('ascii'))
+            name = self._backend._build_openssl_digest_name(algorithm)
+            evp_md = self._backend._lib.EVP_get_digestbyname(name)
             if evp_md == self._backend._ffi.NULL:
                 raise UnsupportedAlgorithm(
-                    "{0} is not a supported hash on this backend.".format(
-                        algorithm.name),
+                    "{0} is not a supported hash on this backend".format(name),
                     _Reasons.UNSUPPORTED_HASH
                 )
             res = self._backend._lib.HMAC_Init_ex(

{"golden_diff": "diff --git a/src/cryptography/hazmat/backends/openssl/hmac.py b/src/cryptography/hazmat/backends/openssl/hmac.py\n--- a/src/cryptography/hazmat/backends/openssl/hmac.py\n+++ b/src/cryptography/hazmat/backends/openssl/hmac.py\n@@ -25,12 +25,11 @@\n             ctx = self._backend._ffi.gc(\n                 ctx, self._backend._lib.Cryptography_HMAC_CTX_free\n             )\n-            evp_md = self._backend._lib.EVP_get_digestbyname(\n-                algorithm.name.encode('ascii'))\n+            name = self._backend._build_openssl_digest_name(algorithm)\n+            evp_md = self._backend._lib.EVP_get_digestbyname(name)\n             if evp_md == self._backend._ffi.NULL:\n                 raise UnsupportedAlgorithm(\n-                    \"{0} is not a supported hash on this backend.\".format(\n-                        algorithm.name),\n+                    \"{0} is not a supported hash on this backend\".format(name),\n                     _Reasons.UNSUPPORTED_HASH\n                 )\n             res = self._backend._lib.HMAC_Init_ex(\n", "issue": "Cannot use BLAKE2b or BLAKE2s with HMAC\nPython 3.6.2 on Ubuntu 17.10\r\nCryptography and dependencies installed via pip in virtualenv\r\ncffi==1.10.0\r\ncryptography==2.0.3\r\npip==9.0.1\r\nsetuptools==36.2.7\r\n\r\nSteps to reproduce:\r\n```\r\nIn [1]: from cryptography.hazmat.backends import default_backend\r\n   ...: from cryptography.hazmat.primitives import hashes\r\n   ...: from cryptography.hazmat.primitives.hmac import HMAC\r\n   ...: \r\n   ...: backend = default_backend()\r\n   ...: \r\n\r\nIn [2]: hmac = HMAC(b'\\x00'*32, hashes.SHA256(), backend)  # just fine\r\n\r\nIn [3]: hmac = HMAC(b'\\x00'*32, hashes.BLAKE2s(digest_size=32), backend)\r\n---------------------------------------------------------------------------\r\nUnsupportedAlgorithm                      Traceback (most recent call last)\r\n<ipython-input-3-61f273a52c45> in <module>()\r\n----> 1 hmac = HMAC(b'\\x00'*32, hashes.BLAKE2s(digest_size=32), backend)\r\n\r\n~/.venvs/master/lib/python3.6/site-packages/cryptography/hazmat/primitives/hmac.py in __init__(self, key, algorithm, backend, ctx)\r\n     30         self._key = key\r\n     31         if ctx is None:\r\n---> 32             self._ctx = self._backend.create_hmac_ctx(key, self.algorithm)\r\n     33         else:\r\n     34             self._ctx = ctx\r\n\r\n~/.venvs/master/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py in create_hmac_ctx(self, key, algorithm)\r\n    176 \r\n    177     def create_hmac_ctx(self, key, algorithm):\r\n--> 178         return _HMACContext(self, key, algorithm)\r\n    179 \r\n    180     def _build_openssl_digest_name(self, algorithm):\r\n\r\n~/.venvs/master/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/hmac.py in __init__(self, backend, key, algorithm, ctx)\r\n     32                     \"{0} is not a supported hash on this backend.\".format(\r\n     33                         algorithm.name),\r\n---> 34                     _Reasons.UNSUPPORTED_HASH\r\n     35                 )\r\n     36             res = self._backend._lib.HMAC_Init_ex(\r\n\r\nUnsupportedAlgorithm: blake2s is not a supported hash on this backend.\r\n```\r\n\n", "before_files": [{"content": "# This file is dual licensed under the terms of the Apache License, Version\n# 2.0, and the BSD License. See the LICENSE file in the root of this repository\n# for complete details.\n\nfrom __future__ import absolute_import, division, print_function\n\n\nfrom cryptography import utils\nfrom cryptography.exceptions import (\n    InvalidSignature, UnsupportedAlgorithm, _Reasons\n)\nfrom cryptography.hazmat.primitives import constant_time, hashes, mac\n\n\n@utils.register_interface(mac.MACContext)\n@utils.register_interface(hashes.HashContext)\nclass _HMACContext(object):\n    def __init__(self, backend, key, algorithm, ctx=None):\n        self._algorithm = algorithm\n        self._backend = backend\n\n        if ctx is None:\n            ctx = self._backend._lib.Cryptography_HMAC_CTX_new()\n            self._backend.openssl_assert(ctx != self._backend._ffi.NULL)\n            ctx = self._backend._ffi.gc(\n                ctx, self._backend._lib.Cryptography_HMAC_CTX_free\n            )\n            evp_md = self._backend._lib.EVP_get_digestbyname(\n                algorithm.name.encode('ascii'))\n            if evp_md == self._backend._ffi.NULL:\n                raise UnsupportedAlgorithm(\n                    \"{0} is not a supported hash on this backend.\".format(\n                        algorithm.name),\n                    _Reasons.UNSUPPORTED_HASH\n                )\n            res = self._backend._lib.HMAC_Init_ex(\n                ctx, key, len(key), evp_md, self._backend._ffi.NULL\n            )\n            self._backend.openssl_assert(res != 0)\n\n        self._ctx = ctx\n        self._key = key\n\n    algorithm = utils.read_only_property(\"_algorithm\")\n\n    def copy(self):\n        copied_ctx = self._backend._lib.Cryptography_HMAC_CTX_new()\n        self._backend.openssl_assert(copied_ctx != self._backend._ffi.NULL)\n        copied_ctx = self._backend._ffi.gc(\n            copied_ctx, self._backend._lib.Cryptography_HMAC_CTX_free\n        )\n        res = self._backend._lib.HMAC_CTX_copy(copied_ctx, self._ctx)\n        self._backend.openssl_assert(res != 0)\n        return _HMACContext(\n            self._backend, self._key, self.algorithm, ctx=copied_ctx\n        )\n\n    def update(self, data):\n        res = self._backend._lib.HMAC_Update(self._ctx, data, len(data))\n        self._backend.openssl_assert(res != 0)\n\n    def finalize(self):\n        buf = self._backend._ffi.new(\"unsigned char[]\",\n                                     self._backend._lib.EVP_MAX_MD_SIZE)\n        outlen = self._backend._ffi.new(\"unsigned int *\")\n        res = self._backend._lib.HMAC_Final(self._ctx, buf, outlen)\n        self._backend.openssl_assert(res != 0)\n        self._backend.openssl_assert(outlen[0] == self.algorithm.digest_size)\n        return self._backend._ffi.buffer(buf)[:outlen[0]]\n\n    def verify(self, signature):\n        digest = self.finalize()\n        if not constant_time.bytes_eq(digest, signature):\n            raise InvalidSignature(\"Signature did not match digest.\")\n", "path": "src/cryptography/hazmat/backends/openssl/hmac.py"}], "after_files": [{"content": "# This file is dual licensed under the terms of the Apache License, Version\n# 2.0, and the BSD License. See the LICENSE file in the root of this repository\n# for complete details.\n\nfrom __future__ import absolute_import, division, print_function\n\n\nfrom cryptography import utils\nfrom cryptography.exceptions import (\n    InvalidSignature, UnsupportedAlgorithm, _Reasons\n)\nfrom cryptography.hazmat.primitives import constant_time, hashes, mac\n\n\n@utils.register_interface(mac.MACContext)\n@utils.register_interface(hashes.HashContext)\nclass _HMACContext(object):\n    def __init__(self, backend, key, algorithm, ctx=None):\n        self._algorithm = algorithm\n        self._backend = backend\n\n        if ctx is None:\n            ctx = self._backend._lib.Cryptography_HMAC_CTX_new()\n            self._backend.openssl_assert(ctx != self._backend._ffi.NULL)\n            ctx = self._backend._ffi.gc(\n                ctx, self._backend._lib.Cryptography_HMAC_CTX_free\n            )\n            name = self._backend._build_openssl_digest_name(algorithm)\n            evp_md = self._backend._lib.EVP_get_digestbyname(name)\n            if evp_md == self._backend._ffi.NULL:\n                raise UnsupportedAlgorithm(\n                    \"{0} is not a supported hash on this backend\".format(name),\n                    _Reasons.UNSUPPORTED_HASH\n                )\n            res = self._backend._lib.HMAC_Init_ex(\n                ctx, key, len(key), evp_md, self._backend._ffi.NULL\n            )\n            self._backend.openssl_assert(res != 0)\n\n        self._ctx = ctx\n        self._key = key\n\n    algorithm = utils.read_only_property(\"_algorithm\")\n\n    def copy(self):\n        copied_ctx = self._backend._lib.Cryptography_HMAC_CTX_new()\n        self._backend.openssl_assert(copied_ctx != self._backend._ffi.NULL)\n        copied_ctx = self._backend._ffi.gc(\n            copied_ctx, self._backend._lib.Cryptography_HMAC_CTX_free\n        )\n        res = self._backend._lib.HMAC_CTX_copy(copied_ctx, self._ctx)\n        self._backend.openssl_assert(res != 0)\n        return _HMACContext(\n            self._backend, self._key, self.algorithm, ctx=copied_ctx\n        )\n\n    def update(self, data):\n        res = self._backend._lib.HMAC_Update(self._ctx, data, len(data))\n        self._backend.openssl_assert(res != 0)\n\n    def finalize(self):\n        buf = self._backend._ffi.new(\"unsigned char[]\",\n                                     self._backend._lib.EVP_MAX_MD_SIZE)\n        outlen = self._backend._ffi.new(\"unsigned int *\")\n        res = self._backend._lib.HMAC_Final(self._ctx, buf, outlen)\n        self._backend.openssl_assert(res != 0)\n        self._backend.openssl_assert(outlen[0] == self.algorithm.digest_size)\n        return self._backend._ffi.buffer(buf)[:outlen[0]]\n\n    def verify(self, signature):\n        digest = self.finalize()\n        if not constant_time.bytes_eq(digest, signature):\n            raise InvalidSignature(\"Signature did not match digest.\")\n", "path": "src/cryptography/hazmat/backends/openssl/hmac.py"}]}