{"action":"created","comment":{"url":"https://api.github.com/repos/pyca/cryptography/pulls/comments/42080047","id":42080047,"diff_hunk":"@@ -749,3 +765,99 @@ def test_signature_not_bytes(self, backend):\n         public_key = key.public_key()\n         with pytest.raises(TypeError):\n             public_key.verifier(1234, ec.ECDSA(hashes.SHA256()))\n+\n+\n+@utils.register_interface(ec.EllipticCurveKeyExchangeAlgorithm)\n+class DummyKeyExchange(object):\n+    algorithm = \"dummy\"\n+\n+\n+@utils.register_interface(KeyDerivationFunction)\n+class NullKDF(object):\n+    def derive(self, key_material):\n+        return key_material\n+\n+    def verify(self, key_material, expected_key):\n+        if not constant_time.bytes_eq(key_material, expected_key):\n+            raise exceptions.InvalidKey\n+\n+\n+@pytest.mark.requires_backend_interface(interface=EllipticCurveBackend)\n+class TestECDHVectors(object):\n+\n+    def test_unsupported_exchange_algorithm(self, backend):\n+        curve = ec.SECP521R1()\n+        exchange_alg = DummyKeyExchange()\n+        _skip_exchange_algorithm_unsupported(backend, exchange_alg, curve)\n+\n+    def test_invalid_exchange_algorithm(self, backend):\n+        curve = ec.SECP521R1\n+        _skip_curve_unsupported(backend, curve)\n+        key = ec.generate_private_key(curve, backend)\n+        with pytest.raises(exceptions.UnsupportedAlgorithm):\n+            key.exchange(DummyKeyExchange())\n+\n+    def test_unsupported_key_derivation_function(self, backend):\n+        curve = ec.SECP521R1\n+        _skip_curve_unsupported(backend, curve)\n+        key = ec.generate_private_key(curve, backend)\n+        with pytest.raises(TypeError):\n+            key.exchange(ec.ECDH(DummyKeyExchange()))\n+\n+    def test_invalid_key_verification(self, backend):\n+        with pytest.raises(exceptions.InvalidKey):\n+            NullKDF().verify(b'a', b'b')\n+        NullKDF().verify(b'a', b'a')\n+\n+    def key_exchange(self, backend, vector):\n+        key_numbers = vector['IUT']\n+        peer_numbers = vector['CAVS']\n+\n+        key = ec.EllipticCurvePrivateNumbers(\n+            key_numbers['d'],\n+            ec.EllipticCurvePublicNumbers(\n+                key_numbers['x'],\n+                key_numbers['y'],\n+                ec._CURVE_TYPES[vector['curve']]()\n+            )\n+        ).private_key(backend)\n+\n+        peerkey = ec.EllipticCurvePrivateNumbers(\n+            peer_numbers['d'],\n+            ec.EllipticCurvePublicNumbers(\n+                peer_numbers['x'],\n+                peer_numbers['y'],\n+                ec._CURVE_TYPES[vector['curve']]()\n+            )\n+        ).private_key(backend)\n+        pubkey = peerkey.public_key()\n+\n+        keyex = key.exchange(ec.ECDH(NullKDF()))\n+        z = keyex.agree(pubkey)\n+\n+        return int(hexlify(z).decode('ascii'), 16)\n+\n+    @pytest.mark.parametrize(\n+        \"vector\",\n+        load_vectors_from_file(\n+            os.path.join(\n+                \"asymmetric\", \"ECDH\",\n+                \"KASValidityTest_ECCStaticUnified_NOKC_ZZOnly_init.fax\"),\n+            load_kasvs_ecdh_vectors\n+        )\n+    )\n+    def test_key_exchange_with_vectors(self, backend, vector):\n+        _skip_curve_unsupported(backend, ec._CURVE_TYPES[vector['curve']])\n+        _skip_exchange_algorithm_unsupported(backend, ec.ECDH(NullKDF()),\n+                                             ec._CURVE_TYPES[vector['curve']])\n+\n+        try:\n+            z = self.key_exchange(backend, vector)\n+        except ValueError:\n+            assert vector['fail'] is True","path":"tests/hazmat/primitives/test_ec.py","position":140,"original_position":140,"commit_id":"1e60a859c7ec1a20039249ee5cb934010744903a","original_commit_id":"1e60a859c7ec1a20039249ee5cb934010744903a","user":{"login":"alex","id":772,"avatar_url":"https://avatars.githubusercontent.com/u/772?v=3","gravatar_id":"","url":"https://api.github.com/users/alex","html_url":"https://github.com/alex","followers_url":"https://api.github.com/users/alex/followers","following_url":"https://api.github.com/users/alex/following{/other_user}","gists_url":"https://api.github.com/users/alex/gists{/gist_id}","starred_url":"https://api.github.com/users/alex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex/subscriptions","organizations_url":"https://api.github.com/users/alex/orgs","repos_url":"https://api.github.com/users/alex/repos","events_url":"https://api.github.com/users/alex/events{/privacy}","received_events_url":"https://api.github.com/users/alex/received_events","type":"User","site_admin":false},"body":"Are these errors coming from `agree()`, or from turning the numbers into\nkeys?\n\nOn Wed, Oct 14, 2015 at 11:19 PM, simo5 <notifications@github.com> wrote:\n\n> In tests/hazmat/primitives/test_ec.py\n> <https://github.com/pyca/cryptography/pull/2398#discussion_r42079921>:\n>\n> > +        load_vectors_from_file(\n> > +            os.path.join(\n> > +                \"asymmetric\", \"ECDH\",\n> > +                \"KASValidityTest_ECCStaticUnified_NOKC_ZZOnly_init.fax\"),\n> > +            load_kasvs_ecdh_vectors\n> > +        )\n> > +    )\n> > +    def test_key_exchange_with_vectors(self, backend, vector):\n> > +        _skip_curve_unsupported(backend, ec._CURVE_TYPES[vector['curve']])\n> > +        _skip_exchange_algorithm_unsupported(backend, ec.ECDH(NullKDF()),\n> > +                                             ec._CURVE_TYPES[vector['curve']])\n> > +\n> > +        try:\n> > +            z = self.key_exchange(backend, vector)\n> > +        except ValueError:\n> > +            assert vector['fail'] is True\n>\n> Any failure to create a key (due to invalid numbers) will cause a\n> ValueError exception in key_exchange() that will bubble up.\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/pyca/cryptography/pull/2398/files#r42079921>.\n>\n\n\n\n-- \n\"I disapprove of what you say, but I will defend to the death your right to\nsay it.\" -- Evelyn Beatrice Hall (summarizing Voltaire)\n\"The people's good is the highest law.\" -- Cicero\nGPG Key fingerprint: 125F 5C67 DFE9 4084\n","created_at":"2015-10-15T03:22:32Z","updated_at":"2015-10-15T03:22:32Z","html_url":"https://github.com/pyca/cryptography/pull/2398#discussion_r42080047","pull_request_url":"https://api.github.com/repos/pyca/cryptography/pulls/2398","_links":{"self":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/comments/42080047"},"html":{"href":"https://github.com/pyca/cryptography/pull/2398#discussion_r42080047"},"pull_request":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/2398"}}},"pull_request":{"url":"https://api.github.com/repos/pyca/cryptography/pulls/2398","id":47100273,"html_url":"https://github.com/pyca/cryptography/pull/2398","diff_url":"https://github.com/pyca/cryptography/pull/2398.diff","patch_url":"https://github.com/pyca/cryptography/pull/2398.patch","issue_url":"https://api.github.com/repos/pyca/cryptography/issues/2398","number":2398,"state":"open","locked":false,"title":"ECDH Exchange implementation","user":{"login":"simo5","id":8332609,"avatar_url":"https://avatars.githubusercontent.com/u/8332609?v=3","gravatar_id":"","url":"https://api.github.com/users/simo5","html_url":"https://github.com/simo5","followers_url":"https://api.github.com/users/simo5/followers","following_url":"https://api.github.com/users/simo5/following{/other_user}","gists_url":"https://api.github.com/users/simo5/gists{/gist_id}","starred_url":"https://api.github.com/users/simo5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simo5/subscriptions","organizations_url":"https://api.github.com/users/simo5/orgs","repos_url":"https://api.github.com/users/simo5/repos","events_url":"https://api.github.com/users/simo5/events{/privacy}","received_events_url":"https://api.github.com/users/simo5/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-08T00:41:46Z","updated_at":"2015-10-15T03:22:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a9486ef7fb271e7c1358d5fe9c00fa2b73a9fb16","assignee":null,"milestone":{"url":"https://api.github.com/repos/pyca/cryptography/milestones/12","html_url":"https://github.com/pyca/cryptography/milestones/Eleventh%20Release","labels_url":"https://api.github.com/repos/pyca/cryptography/milestones/12/labels","id":1189721,"number":12,"title":"Eleventh Release","description":"","creator":{"login":"reaperhulk","id":161495,"avatar_url":"https://avatars.githubusercontent.com/u/161495?v=3","gravatar_id":"","url":"https://api.github.com/users/reaperhulk","html_url":"https://github.com/reaperhulk","followers_url":"https://api.github.com/users/reaperhulk/followers","following_url":"https://api.github.com/users/reaperhulk/following{/other_user}","gists_url":"https://api.github.com/users/reaperhulk/gists{/gist_id}","starred_url":"https://api.github.com/users/reaperhulk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reaperhulk/subscriptions","organizations_url":"https://api.github.com/users/reaperhulk/orgs","repos_url":"https://api.github.com/users/reaperhulk/repos","events_url":"https://api.github.com/users/reaperhulk/events{/privacy}","received_events_url":"https://api.github.com/users/reaperhulk/received_events","type":"User","site_admin":false},"open_issues":9,"closed_issues":19,"state":"open","created_at":"2015-07-01T21:03:39Z","updated_at":"2015-10-14T04:33:03Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/pyca/cryptography/pulls/2398/commits","review_comments_url":"https://api.github.com/repos/pyca/cryptography/pulls/2398/comments","review_comment_url":"https://api.github.com/repos/pyca/cryptography/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pyca/cryptography/issues/2398/comments","statuses_url":"https://api.github.com/repos/pyca/cryptography/statuses/1e60a859c7ec1a20039249ee5cb934010744903a","head":{"label":"simo5:ECDHexchange","ref":"ECDHexchange","sha":"1e60a859c7ec1a20039249ee5cb934010744903a","user":{"login":"simo5","id":8332609,"avatar_url":"https://avatars.githubusercontent.com/u/8332609?v=3","gravatar_id":"","url":"https://api.github.com/users/simo5","html_url":"https://github.com/simo5","followers_url":"https://api.github.com/users/simo5/followers","following_url":"https://api.github.com/users/simo5/following{/other_user}","gists_url":"https://api.github.com/users/simo5/gists{/gist_id}","starred_url":"https://api.github.com/users/simo5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simo5/subscriptions","organizations_url":"https://api.github.com/users/simo5/orgs","repos_url":"https://api.github.com/users/simo5/repos","events_url":"https://api.github.com/users/simo5/events{/privacy}","received_events_url":"https://api.github.com/users/simo5/received_events","type":"User","site_admin":false},"repo":{"id":34753046,"name":"cryptography","full_name":"simo5/cryptography","owner":{"login":"simo5","id":8332609,"avatar_url":"https://avatars.githubusercontent.com/u/8332609?v=3","gravatar_id":"","url":"https://api.github.com/users/simo5","html_url":"https://github.com/simo5","followers_url":"https://api.github.com/users/simo5/followers","following_url":"https://api.github.com/users/simo5/following{/other_user}","gists_url":"https://api.github.com/users/simo5/gists{/gist_id}","starred_url":"https://api.github.com/users/simo5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simo5/subscriptions","organizations_url":"https://api.github.com/users/simo5/orgs","repos_url":"https://api.github.com/users/simo5/repos","events_url":"https://api.github.com/users/simo5/events{/privacy}","received_events_url":"https://api.github.com/users/simo5/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/simo5/cryptography","description":"cryptography is a package designed to expose cryptographic primitives and recipes to Python developers.","fork":true,"url":"https://api.github.com/repos/simo5/cryptography","forks_url":"https://api.github.com/repos/simo5/cryptography/forks","keys_url":"https://api.github.com/repos/simo5/cryptography/keys{/key_id}","collaborators_url":"https://api.github.com/repos/simo5/cryptography/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/simo5/cryptography/teams","hooks_url":"https://api.github.com/repos/simo5/cryptography/hooks","issue_events_url":"https://api.github.com/repos/simo5/cryptography/issues/events{/number}","events_url":"https://api.github.com/repos/simo5/cryptography/events","assignees_url":"https://api.github.com/repos/simo5/cryptography/assignees{/user}","branches_url":"https://api.github.com/repos/simo5/cryptography/branches{/branch}","tags_url":"https://api.github.com/repos/simo5/cryptography/tags","blobs_url":"https://api.github.com/repos/simo5/cryptography/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/simo5/cryptography/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/simo5/cryptography/git/refs{/sha}","trees_url":"https://api.github.com/repos/simo5/cryptography/git/trees{/sha}","statuses_url":"https://api.github.com/repos/simo5/cryptography/statuses/{sha}","languages_url":"https://api.github.com/repos/simo5/cryptography/languages","stargazers_url":"https://api.github.com/repos/simo5/cryptography/stargazers","contributors_url":"https://api.github.com/repos/simo5/cryptography/contributors","subscribers_url":"https://api.github.com/repos/simo5/cryptography/subscribers","subscription_url":"https://api.github.com/repos/simo5/cryptography/subscription","commits_url":"https://api.github.com/repos/simo5/cryptography/commits{/sha}","git_commits_url":"https://api.github.com/repos/simo5/cryptography/git/commits{/sha}","comments_url":"https://api.github.com/repos/simo5/cryptography/comments{/number}","issue_comment_url":"https://api.github.com/repos/simo5/cryptography/issues/comments{/number}","contents_url":"https://api.github.com/repos/simo5/cryptography/contents/{+path}","compare_url":"https://api.github.com/repos/simo5/cryptography/compare/{base}...{head}","merges_url":"https://api.github.com/repos/simo5/cryptography/merges","archive_url":"https://api.github.com/repos/simo5/cryptography/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/simo5/cryptography/downloads","issues_url":"https://api.github.com/repos/simo5/cryptography/issues{/number}","pulls_url":"https://api.github.com/repos/simo5/cryptography/pulls{/number}","milestones_url":"https://api.github.com/repos/simo5/cryptography/milestones{/number}","notifications_url":"https://api.github.com/repos/simo5/cryptography/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/simo5/cryptography/labels{/name}","releases_url":"https://api.github.com/repos/simo5/cryptography/releases{/id}","created_at":"2015-04-28T20:04:21Z","updated_at":"2015-04-28T20:04:28Z","pushed_at":"2015-10-14T17:01:06Z","git_url":"git://github.com/simo5/cryptography.git","ssh_url":"git@github.com:simo5/cryptography.git","clone_url":"https://github.com/simo5/cryptography.git","svn_url":"https://github.com/simo5/cryptography","homepage":"https://cryptography.io/","size":31366,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pyca:master","ref":"master","sha":"af3ea78c9ad85cc0688797eb0da8f828812f3f49","user":{"login":"pyca","id":5615737,"avatar_url":"https://avatars.githubusercontent.com/u/5615737?v=3","gravatar_id":"","url":"https://api.github.com/users/pyca","html_url":"https://github.com/pyca","followers_url":"https://api.github.com/users/pyca/followers","following_url":"https://api.github.com/users/pyca/following{/other_user}","gists_url":"https://api.github.com/users/pyca/gists{/gist_id}","starred_url":"https://api.github.com/users/pyca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pyca/subscriptions","organizations_url":"https://api.github.com/users/pyca/orgs","repos_url":"https://api.github.com/users/pyca/repos","events_url":"https://api.github.com/users/pyca/events{/privacy}","received_events_url":"https://api.github.com/users/pyca/received_events","type":"Organization","site_admin":false},"repo":{"id":11939484,"name":"cryptography","full_name":"pyca/cryptography","owner":{"login":"pyca","id":5615737,"avatar_url":"https://avatars.githubusercontent.com/u/5615737?v=3","gravatar_id":"","url":"https://api.github.com/users/pyca","html_url":"https://github.com/pyca","followers_url":"https://api.github.com/users/pyca/followers","following_url":"https://api.github.com/users/pyca/following{/other_user}","gists_url":"https://api.github.com/users/pyca/gists{/gist_id}","starred_url":"https://api.github.com/users/pyca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pyca/subscriptions","organizations_url":"https://api.github.com/users/pyca/orgs","repos_url":"https://api.github.com/users/pyca/repos","events_url":"https://api.github.com/users/pyca/events{/privacy}","received_events_url":"https://api.github.com/users/pyca/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pyca/cryptography","description":"cryptography is a package designed to expose cryptographic primitives and recipes to Python developers.","fork":false,"url":"https://api.github.com/repos/pyca/cryptography","forks_url":"https://api.github.com/repos/pyca/cryptography/forks","keys_url":"https://api.github.com/repos/pyca/cryptography/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pyca/cryptography/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pyca/cryptography/teams","hooks_url":"https://api.github.com/repos/pyca/cryptography/hooks","issue_events_url":"https://api.github.com/repos/pyca/cryptography/issues/events{/number}","events_url":"https://api.github.com/repos/pyca/cryptography/events","assignees_url":"https://api.github.com/repos/pyca/cryptography/assignees{/user}","branches_url":"https://api.github.com/repos/pyca/cryptography/branches{/branch}","tags_url":"https://api.github.com/repos/pyca/cryptography/tags","blobs_url":"https://api.github.com/repos/pyca/cryptography/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pyca/cryptography/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pyca/cryptography/git/refs{/sha}","trees_url":"https://api.github.com/repos/pyca/cryptography/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pyca/cryptography/statuses/{sha}","languages_url":"https://api.github.com/repos/pyca/cryptography/languages","stargazers_url":"https://api.github.com/repos/pyca/cryptography/stargazers","contributors_url":"https://api.github.com/repos/pyca/cryptography/contributors","subscribers_url":"https://api.github.com/repos/pyca/cryptography/subscribers","subscription_url":"https://api.github.com/repos/pyca/cryptography/subscription","commits_url":"https://api.github.com/repos/pyca/cryptography/commits{/sha}","git_commits_url":"https://api.github.com/repos/pyca/cryptography/git/commits{/sha}","comments_url":"https://api.github.com/repos/pyca/cryptography/comments{/number}","issue_comment_url":"https://api.github.com/repos/pyca/cryptography/issues/comments{/number}","contents_url":"https://api.github.com/repos/pyca/cryptography/contents/{+path}","compare_url":"https://api.github.com/repos/pyca/cryptography/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pyca/cryptography/merges","archive_url":"https://api.github.com/repos/pyca/cryptography/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pyca/cryptography/downloads","issues_url":"https://api.github.com/repos/pyca/cryptography/issues{/number}","pulls_url":"https://api.github.com/repos/pyca/cryptography/pulls{/number}","milestones_url":"https://api.github.com/repos/pyca/cryptography/milestones{/number}","notifications_url":"https://api.github.com/repos/pyca/cryptography/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pyca/cryptography/labels{/name}","releases_url":"https://api.github.com/repos/pyca/cryptography/releases{/id}","created_at":"2013-08-07T02:23:38Z","updated_at":"2015-10-14T14:02:01Z","pushed_at":"2015-10-15T03:07:04Z","git_url":"git://github.com/pyca/cryptography.git","ssh_url":"git@github.com:pyca/cryptography.git","clone_url":"https://github.com/pyca/cryptography.git","svn_url":"https://github.com/pyca/cryptography","homepage":"https://cryptography.io/","size":46595,"stargazers_count":840,"watchers_count":840,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":201,"mirror_url":null,"open_issues_count":91,"forks":201,"open_issues":91,"watchers":840,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/2398"},"html":{"href":"https://github.com/pyca/cryptography/pull/2398"},"issue":{"href":"https://api.github.com/repos/pyca/cryptography/issues/2398"},"comments":{"href":"https://api.github.com/repos/pyca/cryptography/issues/2398/comments"},"review_comments":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/2398/comments"},"review_comment":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/2398/commits"},"statuses":{"href":"https://api.github.com/repos/pyca/cryptography/statuses/1e60a859c7ec1a20039249ee5cb934010744903a"}}}}