{"action":"created","comment":{"url":"https://api.github.com/repos/pyca/cryptography/pulls/comments/175300278","pull_request_review_id":104808008,"id":175300278,"diff_hunk":"@@ -68,6 +68,62 @@ def _unwrap_core(wrapping_key, a, r, backend):\n     return a, r\n \n \n+def aes_key_wrap_with_padding(wrapping_key, key_to_wrap, backend):\n+    if len(wrapping_key) not in [16, 24, 32]:\n+        raise ValueError(\"The wrapping key must be a valid AES key length\")\n+\n+    aiv = b\"\\xA6\\x59\\x59\\xA6\" + struct.pack(\">i\", len(key_to_wrap))\n+    # pad the key to wrap if necessary\n+    pad = (8 - (len(key_to_wrap) % 8)) % 8\n+    key_to_wrap = key_to_wrap + b\"\\x00\" * pad\n+    r = [key_to_wrap[i:i + 8] for i in range(0, len(key_to_wrap), 8)]\n+    if len(r) == 1:\n+        # RFC 5649 - 4.1 - exactly 8 octets after padding\n+        encryptor = Cipher(AES(wrapping_key), ECB(), backend).encryptor()\n+        b = encryptor.update(aiv + r[0])\n+        assert encryptor.finalize() == b\"\"\n+        return b\n+    else:\n+        return _wrap_core(wrapping_key, aiv, r, backend)\n+\n+\n+def aes_key_unwrap_with_padding(wrapping_key, wrapped_key, backend):\n+    if len(wrapped_key) < 16:\n+        raise ValueError(\"Must be at least 16 bytes\")\n+\n+    if len(wrapping_key) not in [16, 24, 32]:\n+        raise ValueError(\"The wrapping key must be a valid AES key length\")\n+\n+    r = [wrapped_key[i:i + 8] for i in range(0, len(wrapped_key), 8)]\n+    encrypted_aiv = r.pop(0)\n+    n = len(r)\n+    if n == 1:\n+        # RFC 5649 - 4.2 - exactly two 64-bit blocks\n+        decryptor = Cipher(AES(wrapping_key), ECB(), backend).decryptor()\n+        b = decryptor.update(encrypted_aiv + r[0])\n+        assert decryptor.finalize() == b\"\"\n+        a = b[:8]\n+        data = b[8:]\n+    else:\n+        a, r = _unwrap_core(wrapping_key, encrypted_aiv, r, backend)\n+        data = b\"\".join(r)\n+\n+    # 1) Check that MSB(32,A) = A65959A6.\n+    # 2) Check that 8*(n-1) < LSB(32,A) <= 8*n.  If so, let\n+    #    MLI = LSB(32,A).\n+    # 3) Let b = (8*n)-MLI, and then check that the rightmost b octets of\n+    #    the output data are zero.\n+    mli = struct.unpack(\">I\", a[4:])[0]","path":"src/cryptography/hazmat/primitives/keywrap.py","position":49,"original_position":49,"commit_id":"cc91dc1d5b8af942497791bbdb41f8cbf13f0f10","original_commit_id":"cc91dc1d5b8af942497791bbdb41f8cbf13f0f10","user":{"login":"alex","id":772,"avatar_url":"https://avatars2.githubusercontent.com/u/772?v=4","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":"Use tuple unpacking, instead of indexing","created_at":"2018-03-18T19:16:11Z","updated_at":"2018-03-18T19:16:20Z","html_url":"https://github.com/pyca/cryptography/pull/3880#discussion_r175300278","pull_request_url":"https://api.github.com/repos/pyca/cryptography/pulls/3880","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/comments/175300278"},"html":{"href":"https://github.com/pyca/cryptography/pull/3880#discussion_r175300278"},"pull_request":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/3880"}}},"pull_request":{"url":"https://api.github.com/repos/pyca/cryptography/pulls/3880","id":138589874,"html_url":"https://github.com/pyca/cryptography/pull/3880","diff_url":"https://github.com/pyca/cryptography/pull/3880.diff","patch_url":"https://github.com/pyca/cryptography/pull/3880.patch","issue_url":"https://api.github.com/repos/pyca/cryptography/issues/3880","number":3880,"state":"open","locked":false,"title":"implement AES KW with padding (RFC 5649)","user":{"login":"reaperhulk","id":161495,"avatar_url":"https://avatars2.githubusercontent.com/u/161495?v=4","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},"body":"fixes #3791\r\n  ","created_at":"2017-08-31T06:31:52Z","updated_at":"2018-03-18T19:16:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3f12d2e3a665efc2cf4585243da453a069345063","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":{"url":"https://api.github.com/repos/pyca/cryptography/milestones/24","html_url":"https://github.com/pyca/cryptography/milestone/24","labels_url":"https://api.github.com/repos/pyca/cryptography/milestones/24/labels","id":2751962,"number":24,"title":"Twenty second release","description":"","creator":{"login":"reaperhulk","id":161495,"avatar_url":"https://avatars2.githubusercontent.com/u/161495?v=4","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":2,"closed_issues":19,"state":"open","created_at":"2017-09-08T02:13:27Z","updated_at":"2018-03-18T19:02:57Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/pyca/cryptography/pulls/3880/commits","review_comments_url":"https://api.github.com/repos/pyca/cryptography/pulls/3880/comments","review_comment_url":"https://api.github.com/repos/pyca/cryptography/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pyca/cryptography/issues/3880/comments","statuses_url":"https://api.github.com/repos/pyca/cryptography/statuses/cc91dc1d5b8af942497791bbdb41f8cbf13f0f10","head":{"label":"reaperhulk:aeskw-padding","ref":"aeskw-padding","sha":"cc91dc1d5b8af942497791bbdb41f8cbf13f0f10","user":{"login":"reaperhulk","id":161495,"avatar_url":"https://avatars2.githubusercontent.com/u/161495?v=4","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},"repo":{"id":12704352,"name":"cryptography","full_name":"reaperhulk/cryptography","owner":{"login":"reaperhulk","id":161495,"avatar_url":"https://avatars2.githubusercontent.com/u/161495?v=4","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},"private":false,"html_url":"https://github.com/reaperhulk/cryptography","description":"cryptography is a package designed to expose cryptographic primitives and recipes to Python developers.","fork":true,"url":"https://api.github.com/repos/reaperhulk/cryptography","forks_url":"https://api.github.com/repos/reaperhulk/cryptography/forks","keys_url":"https://api.github.com/repos/reaperhulk/cryptography/keys{/key_id}","collaborators_url":"https://api.github.com/repos/reaperhulk/cryptography/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/reaperhulk/cryptography/teams","hooks_url":"https://api.github.com/repos/reaperhulk/cryptography/hooks","issue_events_url":"https://api.github.com/repos/reaperhulk/cryptography/issues/events{/number}","events_url":"https://api.github.com/repos/reaperhulk/cryptography/events","assignees_url":"https://api.github.com/repos/reaperhulk/cryptography/assignees{/user}","branches_url":"https://api.github.com/repos/reaperhulk/cryptography/branches{/branch}","tags_url":"https://api.github.com/repos/reaperhulk/cryptography/tags","blobs_url":"https://api.github.com/repos/reaperhulk/cryptography/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/reaperhulk/cryptography/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/reaperhulk/cryptography/git/refs{/sha}","trees_url":"https://api.github.com/repos/reaperhulk/cryptography/git/trees{/sha}","statuses_url":"https://api.github.com/repos/reaperhulk/cryptography/statuses/{sha}","languages_url":"https://api.github.com/repos/reaperhulk/cryptography/languages","stargazers_url":"https://api.github.com/repos/reaperhulk/cryptography/stargazers","contributors_url":"https://api.github.com/repos/reaperhulk/cryptography/contributors","subscribers_url":"https://api.github.com/repos/reaperhulk/cryptography/subscribers","subscription_url":"https://api.github.com/repos/reaperhulk/cryptography/subscription","commits_url":"https://api.github.com/repos/reaperhulk/cryptography/commits{/sha}","git_commits_url":"https://api.github.com/repos/reaperhulk/cryptography/git/commits{/sha}","comments_url":"https://api.github.com/repos/reaperhulk/cryptography/comments{/number}","issue_comment_url":"https://api.github.com/repos/reaperhulk/cryptography/issues/comments{/number}","contents_url":"https://api.github.com/repos/reaperhulk/cryptography/contents/{+path}","compare_url":"https://api.github.com/repos/reaperhulk/cryptography/compare/{base}...{head}","merges_url":"https://api.github.com/repos/reaperhulk/cryptography/merges","archive_url":"https://api.github.com/repos/reaperhulk/cryptography/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/reaperhulk/cryptography/downloads","issues_url":"https://api.github.com/repos/reaperhulk/cryptography/issues{/number}","pulls_url":"https://api.github.com/repos/reaperhulk/cryptography/pulls{/number}","milestones_url":"https://api.github.com/repos/reaperhulk/cryptography/milestones{/number}","notifications_url":"https://api.github.com/repos/reaperhulk/cryptography/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/reaperhulk/cryptography/labels{/name}","releases_url":"https://api.github.com/repos/reaperhulk/cryptography/releases{/id}","deployments_url":"https://api.github.com/repos/reaperhulk/cryptography/deployments","created_at":"2013-09-09T14:59:27Z","updated_at":"2016-11-22T05:10:43Z","pushed_at":"2018-03-18T19:05:41Z","git_url":"git://github.com/reaperhulk/cryptography.git","ssh_url":"git@github.com:reaperhulk/cryptography.git","clone_url":"https://github.com/reaperhulk/cryptography.git","svn_url":"https://github.com/reaperhulk/cryptography","homepage":"","size":36045,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":1,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"pyca:master","ref":"master","sha":"a522f9cc0e6f09d530dffce6b1902257366eb68b","user":{"login":"pyca","id":5615737,"avatar_url":"https://avatars1.githubusercontent.com/u/5615737?v=4","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://avatars1.githubusercontent.com/u/5615737?v=4","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}","deployments_url":"https://api.github.com/repos/pyca/cryptography/deployments","created_at":"2013-08-07T02:23:38Z","updated_at":"2018-03-18T19:02:53Z","pushed_at":"2018-03-18T19:02:50Z","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":36291,"stargazers_count":1991,"watchers_count":1991,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":460,"mirror_url":null,"archived":false,"open_issues_count":65,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":460,"open_issues":65,"watchers":1991,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/3880"},"html":{"href":"https://github.com/pyca/cryptography/pull/3880"},"issue":{"href":"https://api.github.com/repos/pyca/cryptography/issues/3880"},"comments":{"href":"https://api.github.com/repos/pyca/cryptography/issues/3880/comments"},"review_comments":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/3880/comments"},"review_comment":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/3880/commits"},"statuses":{"href":"https://api.github.com/repos/pyca/cryptography/statuses/cc91dc1d5b8af942497791bbdb41f8cbf13f0f10"}},"author_association":"OWNER"}}
{"actor":{"display_login":"alex"}}