{"action":"created","comment":{"url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments/45983087","id":45983087,"diff_hunk":"@@ -0,0 +1,44 @@\n+#include \"include/secp256k1_ecdh.h\"\n+#include \"ecmult_const_impl.h\"\n+\n+// adapted from libsecp256k1/src/modules/ecdh/main_impl.h\n+// return x,y right after scalar multiplication\n+int secp256k1_pubkey_scalar_mul(const secp256k1_context* ctx, unsigned char *x_res, unsigned char *y_res, const secp256k1_pubkey *point, const unsigned char *scalar) {\n+    int ret = 0;\n+    int overflow = 0;\n+    secp256k1_gej res;\n+    secp256k1_ge pt;\n+    secp256k1_scalar s;\n+    ARG_CHECK(x_res != NULL);\n+    ARG_CHECK(y_res != NULL);\n+    ARG_CHECK(point != NULL);\n+    ARG_CHECK(scalar != NULL);\n+    (void)ctx;\n+\n+    secp256k1_pubkey_load(ctx, &pt, point);\n+    secp256k1_scalar_set_b32(&s, scalar, &overflow);\n+    if (overflow || secp256k1_scalar_is_zero(&s)) {\n+        ret = 0;\n+    } else {\n+        unsigned char x[32];\n+        unsigned char y[32];\n+\n+        secp256k1_ecmult_const(&res, &pt, &s);\n+        secp256k1_ge_set_gej(&pt, &res);\n+\n+        /* Compute a hash of the point in compressed form\n+         * Note we cannot use secp256k1_eckey_pubkey_serialize here since it does not\n+         * expect its output to be secret and has a timing sidechannel. */\n+        secp256k1_fe_normalize(&pt.x);\n+        secp256k1_fe_normalize(&pt.y);\n+        secp256k1_fe_get_b32(x, &pt.x);\n+        secp256k1_fe_get_b32(y, &pt.y);\n+\n+        memcpy(x_res, &x, 32);\n+        memcpy(y_res, &y, 32);\n+        ret = 1;\n+    }\n+\n+    secp256k1_scalar_clear(&s);\n+    return ret;\n+}","path":"crypto/secp256k1/libsecp256k1/src/modules/ecdh/pubkey_scalar_mul.h","position":44,"original_position":44,"commit_id":"95b23170ebb231e6dae647777ecd2e0ff1d04f0d","original_commit_id":"95b23170ebb231e6dae647777ecd2e0ff1d04f0d","user":{"login":"fjl","id":6915,"avatar_url":"https://avatars.githubusercontent.com/u/6915?v=3","gravatar_id":"","url":"https://api.github.com/users/fjl","html_url":"https://github.com/fjl","followers_url":"https://api.github.com/users/fjl/followers","following_url":"https://api.github.com/users/fjl/following{/other_user}","gists_url":"https://api.github.com/users/fjl/gists{/gist_id}","starred_url":"https://api.github.com/users/fjl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fjl/subscriptions","organizations_url":"https://api.github.com/users/fjl/orgs","repos_url":"https://api.github.com/users/fjl/repos","events_url":"https://api.github.com/users/fjl/events{/privacy}","received_events_url":"https://api.github.com/users/fjl/received_events","type":"User","site_admin":false},"body":"Or just pull these: https://github.com/Gustav-Simonsson/go-ethereum/compare/libsecp256k1_ecdh...fjl:secp256k1-ecdh","created_at":"2015-11-26T14:29:04Z","updated_at":"2015-11-26T14:29:04Z","html_url":"https://github.com/ethereum/go-ethereum/pull/1862#discussion_r45983087","pull_request_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/1862","_links":{"self":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments/45983087"},"html":{"href":"https://github.com/ethereum/go-ethereum/pull/1862#discussion_r45983087"},"pull_request":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/1862"}}},"pull_request":{"url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/1862","id":46516150,"html_url":"https://github.com/ethereum/go-ethereum/pull/1862","diff_url":"https://github.com/ethereum/go-ethereum/pull/1862.diff","patch_url":"https://github.com/ethereum/go-ethereum/pull/1862.patch","issue_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/1862","number":1862,"state":"open","locked":false,"title":"Libsecp256k1 ecdh","user":{"login":"Gustav-Simonsson","id":293096,"avatar_url":"https://avatars.githubusercontent.com/u/293096?v=3","gravatar_id":"","url":"https://api.github.com/users/Gustav-Simonsson","html_url":"https://github.com/Gustav-Simonsson","followers_url":"https://api.github.com/users/Gustav-Simonsson/followers","following_url":"https://api.github.com/users/Gustav-Simonsson/following{/other_user}","gists_url":"https://api.github.com/users/Gustav-Simonsson/gists{/gist_id}","starred_url":"https://api.github.com/users/Gustav-Simonsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gustav-Simonsson/subscriptions","organizations_url":"https://api.github.com/users/Gustav-Simonsson/orgs","repos_url":"https://api.github.com/users/Gustav-Simonsson/repos","events_url":"https://api.github.com/users/Gustav-Simonsson/events{/privacy}","received_events_url":"https://api.github.com/users/Gustav-Simonsson/received_events","type":"User","site_admin":false},"body":"~~**Depends on https://github.com/ethereum/go-ethereum/pull/1853 - please review & merge it first.**~~\r\n\r\nNOTE: package `crypto/ecies` needs some refactoring love - this patch is not ideal as package `ecies` is a bit messy. Discussed with @fjl and we have several ideas around how to refactor it. Would prefer to make that refactoring in a separate PR so it's easier to review separated from this change.\r\n\r\n- [x] Add libsecp256k1 Scalar Multiplication API based on it's ECDH API and use this in the curve interface function `ScalarMult` for this curve.\r\n- [x] Add benchmark of Scalar Multiplication (lib + Go wrapping code)\r\n- [x] Add shared secret test with static values to catch errors when integrating.\r\n- [x] Move Go secp256k1 curve to crypto/secp256k1 so it can be used in crypto/ecies package (needed to run tests with the correct curve - currently tests are run with another curve - P256)\r\n- [x] Fix RLPx test setup to avoid hanging in case of errors returned from crypto libs\r\n- [x] Some boilerplate added to squeeze this curve into current ECIES impl.\r\n\r\nSpeedup:\r\n```\r\nbenchmark                     old ns/op     new ns/op     delta\r\nBenchmarkGenSharedKeyS256     6523809       165052        -97.47%\r\n```\r\n","created_at":"2015-10-01T12:17:52Z","updated_at":"2015-11-26T14:29:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3c478d29a4dedc50d2c0c2e04e64ee544a7ab508","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/1862/commits","review_comments_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/1862/comments","review_comment_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/1862/comments","statuses_url":"https://api.github.com/repos/ethereum/go-ethereum/statuses/95b23170ebb231e6dae647777ecd2e0ff1d04f0d","head":{"label":"Gustav-Simonsson:libsecp256k1_ecdh","ref":"libsecp256k1_ecdh","sha":"95b23170ebb231e6dae647777ecd2e0ff1d04f0d","user":{"login":"Gustav-Simonsson","id":293096,"avatar_url":"https://avatars.githubusercontent.com/u/293096?v=3","gravatar_id":"","url":"https://api.github.com/users/Gustav-Simonsson","html_url":"https://github.com/Gustav-Simonsson","followers_url":"https://api.github.com/users/Gustav-Simonsson/followers","following_url":"https://api.github.com/users/Gustav-Simonsson/following{/other_user}","gists_url":"https://api.github.com/users/Gustav-Simonsson/gists{/gist_id}","starred_url":"https://api.github.com/users/Gustav-Simonsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gustav-Simonsson/subscriptions","organizations_url":"https://api.github.com/users/Gustav-Simonsson/orgs","repos_url":"https://api.github.com/users/Gustav-Simonsson/repos","events_url":"https://api.github.com/users/Gustav-Simonsson/events{/privacy}","received_events_url":"https://api.github.com/users/Gustav-Simonsson/received_events","type":"User","site_admin":false},"repo":{"id":27963592,"name":"go-ethereum","full_name":"Gustav-Simonsson/go-ethereum","owner":{"login":"Gustav-Simonsson","id":293096,"avatar_url":"https://avatars.githubusercontent.com/u/293096?v=3","gravatar_id":"","url":"https://api.github.com/users/Gustav-Simonsson","html_url":"https://github.com/Gustav-Simonsson","followers_url":"https://api.github.com/users/Gustav-Simonsson/followers","following_url":"https://api.github.com/users/Gustav-Simonsson/following{/other_user}","gists_url":"https://api.github.com/users/Gustav-Simonsson/gists{/gist_id}","starred_url":"https://api.github.com/users/Gustav-Simonsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gustav-Simonsson/subscriptions","organizations_url":"https://api.github.com/users/Gustav-Simonsson/orgs","repos_url":"https://api.github.com/users/Gustav-Simonsson/repos","events_url":"https://api.github.com/users/Gustav-Simonsson/events{/privacy}","received_events_url":"https://api.github.com/users/Gustav-Simonsson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Gustav-Simonsson/go-ethereum","description":"Ethereum Go - Mist (Ether Browser)","fork":true,"url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum","forks_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/forks","keys_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/teams","hooks_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/hooks","issue_events_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/issues/events{/number}","events_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/events","assignees_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/assignees{/user}","branches_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/branches{/branch}","tags_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/tags","blobs_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/git/refs{/sha}","trees_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/statuses/{sha}","languages_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/languages","stargazers_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/stargazers","contributors_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/contributors","subscribers_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/subscribers","subscription_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/subscription","commits_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/commits{/sha}","git_commits_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/git/commits{/sha}","comments_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/comments{/number}","issue_comment_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/issues/comments{/number}","contents_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/contents/{+path}","compare_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/merges","archive_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/downloads","issues_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/issues{/number}","pulls_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/pulls{/number}","milestones_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/milestones{/number}","notifications_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/labels{/name}","releases_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/releases{/id}","created_at":"2014-12-13T14:48:30Z","updated_at":"2015-01-19T23:50:05Z","pushed_at":"2015-11-26T01:47:44Z","git_url":"git://github.com/Gustav-Simonsson/go-ethereum.git","ssh_url":"git@github.com:Gustav-Simonsson/go-ethereum.git","clone_url":"https://github.com/Gustav-Simonsson/go-ethereum.git","svn_url":"https://github.com/Gustav-Simonsson/go-ethereum","homepage":"","size":49375,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"ethereum:develop","ref":"develop","sha":"168d0e9e45939b7282204f3f52fe86fc8110cfc7","user":{"login":"ethereum","id":6250754,"avatar_url":"https://avatars.githubusercontent.com/u/6250754?v=3","gravatar_id":"","url":"https://api.github.com/users/ethereum","html_url":"https://github.com/ethereum","followers_url":"https://api.github.com/users/ethereum/followers","following_url":"https://api.github.com/users/ethereum/following{/other_user}","gists_url":"https://api.github.com/users/ethereum/gists{/gist_id}","starred_url":"https://api.github.com/users/ethereum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethereum/subscriptions","organizations_url":"https://api.github.com/users/ethereum/orgs","repos_url":"https://api.github.com/users/ethereum/repos","events_url":"https://api.github.com/users/ethereum/events{/privacy}","received_events_url":"https://api.github.com/users/ethereum/received_events","type":"Organization","site_admin":false},"repo":{"id":15452919,"name":"go-ethereum","full_name":"ethereum/go-ethereum","owner":{"login":"ethereum","id":6250754,"avatar_url":"https://avatars.githubusercontent.com/u/6250754?v=3","gravatar_id":"","url":"https://api.github.com/users/ethereum","html_url":"https://github.com/ethereum","followers_url":"https://api.github.com/users/ethereum/followers","following_url":"https://api.github.com/users/ethereum/following{/other_user}","gists_url":"https://api.github.com/users/ethereum/gists{/gist_id}","starred_url":"https://api.github.com/users/ethereum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethereum/subscriptions","organizations_url":"https://api.github.com/users/ethereum/orgs","repos_url":"https://api.github.com/users/ethereum/repos","events_url":"https://api.github.com/users/ethereum/events{/privacy}","received_events_url":"https://api.github.com/users/ethereum/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ethereum/go-ethereum","description":"Official golang implementation of the Ethereum protocol","fork":false,"url":"https://api.github.com/repos/ethereum/go-ethereum","forks_url":"https://api.github.com/repos/ethereum/go-ethereum/forks","keys_url":"https://api.github.com/repos/ethereum/go-ethereum/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ethereum/go-ethereum/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ethereum/go-ethereum/teams","hooks_url":"https://api.github.com/repos/ethereum/go-ethereum/hooks","issue_events_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/events{/number}","events_url":"https://api.github.com/repos/ethereum/go-ethereum/events","assignees_url":"https://api.github.com/repos/ethereum/go-ethereum/assignees{/user}","branches_url":"https://api.github.com/repos/ethereum/go-ethereum/branches{/branch}","tags_url":"https://api.github.com/repos/ethereum/go-ethereum/tags","blobs_url":"https://api.github.com/repos/ethereum/go-ethereum/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ethereum/go-ethereum/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ethereum/go-ethereum/git/refs{/sha}","trees_url":"https://api.github.com/repos/ethereum/go-ethereum/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ethereum/go-ethereum/statuses/{sha}","languages_url":"https://api.github.com/repos/ethereum/go-ethereum/languages","stargazers_url":"https://api.github.com/repos/ethereum/go-ethereum/stargazers","contributors_url":"https://api.github.com/repos/ethereum/go-ethereum/contributors","subscribers_url":"https://api.github.com/repos/ethereum/go-ethereum/subscribers","subscription_url":"https://api.github.com/repos/ethereum/go-ethereum/subscription","commits_url":"https://api.github.com/repos/ethereum/go-ethereum/commits{/sha}","git_commits_url":"https://api.github.com/repos/ethereum/go-ethereum/git/commits{/sha}","comments_url":"https://api.github.com/repos/ethereum/go-ethereum/comments{/number}","issue_comment_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/comments{/number}","contents_url":"https://api.github.com/repos/ethereum/go-ethereum/contents/{+path}","compare_url":"https://api.github.com/repos/ethereum/go-ethereum/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ethereum/go-ethereum/merges","archive_url":"https://api.github.com/repos/ethereum/go-ethereum/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ethereum/go-ethereum/downloads","issues_url":"https://api.github.com/repos/ethereum/go-ethereum/issues{/number}","pulls_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls{/number}","milestones_url":"https://api.github.com/repos/ethereum/go-ethereum/milestones{/number}","notifications_url":"https://api.github.com/repos/ethereum/go-ethereum/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ethereum/go-ethereum/labels{/name}","releases_url":"https://api.github.com/repos/ethereum/go-ethereum/releases{/id}","created_at":"2013-12-26T13:05:46Z","updated_at":"2015-11-26T07:00:46Z","pushed_at":"2015-11-26T14:13:22Z","git_url":"git://github.com/ethereum/go-ethereum.git","ssh_url":"git@github.com:ethereum/go-ethereum.git","clone_url":"https://github.com/ethereum/go-ethereum.git","svn_url":"https://github.com/ethereum/go-ethereum","homepage":"http://ethereum.github.io/go-ethereum/","size":63736,"stargazers_count":742,"watchers_count":742,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":250,"mirror_url":null,"open_issues_count":126,"forks":250,"open_issues":126,"watchers":742,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/1862"},"html":{"href":"https://github.com/ethereum/go-ethereum/pull/1862"},"issue":{"href":"https://api.github.com/repos/ethereum/go-ethereum/issues/1862"},"comments":{"href":"https://api.github.com/repos/ethereum/go-ethereum/issues/1862/comments"},"review_comments":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/1862/comments"},"review_comment":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/1862/commits"},"statuses":{"href":"https://api.github.com/repos/ethereum/go-ethereum/statuses/95b23170ebb231e6dae647777ecd2e0ff1d04f0d"}}}}