{"action":"created","comment":{"url":"https://api.github.com/repos/openssl/openssl/pulls/comments/226494856","pull_request_review_id":166332009,"id":226494856,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNjQ5NDg1Ng==","diff_hunk":"@@ -163,6 +163,139 @@ void *RSA_get_ex_data(const RSA *r, int idx)\n     return CRYPTO_get_ex_data(&r->ex_data, idx);\n }\n \n+/*\n+ * Define a scaling constant for our fixed point arithmetic.\n+ * This value must be a power of two because the base two logarithm code\n+ * makes this assumption.  The exponent must also be a multiple of three so\n+ * that the scale factor has an exact cube root.  Finally, the scale factor\n+ * should not be so large that a multiplication of two scaled numbers\n+ * overflows a 64 bit unsigned integer.\n+ */\n+static const unsigned int scale = 1 << 18;\n+static const unsigned int cbrt_scale = 1 << (2 * 18 / 3);\n+\n+/* Define some constants, none exceed 32 bits */\n+static const unsigned int log_2  = 0x02c5c8;    /* scale * log(2) */\n+static const unsigned int log_e  = 0x05c551;    /* scale * log2(M_E) */\n+static const unsigned int c1_923 = 0x07b126;    /* scale * 1.923 */\n+static const unsigned int c4_690 = 0x12c28f;    /* scale * 4.690 */\n+\n+/*\n+ * Multiply two scale integers together and rescale the result.\n+ */\n+static ossl_inline uint64_t mul2(uint64_t a, uint64_t b)\n+{\n+    /*\n+     * If correct rounded is desired, enable this define.\n+     * Correct rounding being:\n+     *      1) if the fractional part is less than one half, round down.\n+     *      2) if the fractional part is greater than one half, round up.\n+     *      3) if the fractional part is exactly one half, round to even.\n+     * This very slightly increases accuracy.\n+     */\n+#ifdef OSSL_CORRECT_ROUNDING\n+    uint64_t m = a * b;\n+    uint32_t f = m & (scale - 1);\n+\n+    m /= scale;\n+    if (f == scale / 2)         /* Round to even */\n+        m &= ~1;\n+    else if (f >= scale / 2)    /* Round up */\n+        m++;\n+    return m;\n+#else\n+    return a * b / scale;\n+#endif\n+}\n+\n+/*\n+ * Calculate the cube root of a 64 bit scaled integer.\n+ * Although the cube root of a 64 bit number does fit into a 32 bit unsigned\n+ * integer, this is not guaranteed after scaling, so this function has a\n+ * 64 bit return.  This uses the shifting nth root algorithm.\n+ */\n+static uint64_t icbrt64(uint64_t x)\n+{\n+    uint32_t r = 0;","path":"crypto/rsa/rsa_lib.c","position":57,"original_position":57,"commit_id":"bcbe068b504b55004c64f34bc7b9b876a7409b2b","original_commit_id":"bcbe068b504b55004c64f34bc7b9b876a7409b2b","user":{"login":"paulidale","id":17916609,"node_id":"MDQ6VXNlcjE3OTE2NjA5","avatar_url":"https://avatars1.githubusercontent.com/u/17916609?v=4","gravatar_id":"","url":"https://api.github.com/users/paulidale","html_url":"https://github.com/paulidale","followers_url":"https://api.github.com/users/paulidale/followers","following_url":"https://api.github.com/users/paulidale/following{/other_user}","gists_url":"https://api.github.com/users/paulidale/gists{/gist_id}","starred_url":"https://api.github.com/users/paulidale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulidale/subscriptions","organizations_url":"https://api.github.com/users/paulidale/orgs","repos_url":"https://api.github.com/users/paulidale/repos","events_url":"https://api.github.com/users/paulidale/events{/privacy}","received_events_url":"https://api.github.com/users/paulidale/received_events","type":"User","site_admin":false},"body":"My reasoning was that `uint32_t` will be more efficient on some platforms.  Specifically, a 32x32 bit multiplication giving a 64 bit result.  Is this efficiency a concern?\r\n\r\nOne of the casts is easy to avoid, the other not so since r<sup>2</sup> does not fit in 32 bits.\r\n\r\nWould a floating point version of the code be acceptable?  I tried to avoid it.","created_at":"2018-10-18T23:19:51Z","updated_at":"2018-10-18T23:19:51Z","html_url":"https://github.com/openssl/openssl/pull/7352#discussion_r226494856","pull_request_url":"https://api.github.com/repos/openssl/openssl/pulls/7352","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/openssl/openssl/pulls/comments/226494856"},"html":{"href":"https://github.com/openssl/openssl/pull/7352#discussion_r226494856"},"pull_request":{"href":"https://api.github.com/repos/openssl/openssl/pulls/7352"}},"in_reply_to_id":226372276},"pull_request":{"url":"https://api.github.com/repos/openssl/openssl/pulls/7352","id":220546004,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIwNTQ2MDA0","html_url":"https://github.com/openssl/openssl/pull/7352","diff_url":"https://github.com/openssl/openssl/pull/7352.diff","patch_url":"https://github.com/openssl/openssl/pull/7352.patch","issue_url":"https://api.github.com/repos/openssl/openssl/issues/7352","number":7352,"state":"open","locked":false,"title":"RSA security bits calculation","user":{"login":"paulidale","id":17916609,"node_id":"MDQ6VXNlcjE3OTE2NjA5","avatar_url":"https://avatars1.githubusercontent.com/u/17916609?v=4","gravatar_id":"","url":"https://api.github.com/users/paulidale","html_url":"https://github.com/paulidale","followers_url":"https://api.github.com/users/paulidale/followers","following_url":"https://api.github.com/users/paulidale/following{/other_user}","gists_url":"https://api.github.com/users/paulidale/gists{/gist_id}","starred_url":"https://api.github.com/users/paulidale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulidale/subscriptions","organizations_url":"https://api.github.com/users/paulidale/orgs","repos_url":"https://api.github.com/users/paulidale/repos","events_url":"https://api.github.com/users/paulidale/events{/privacy}","received_events_url":"https://api.github.com/users/paulidale/received_events","type":"User","site_admin":false},"body":"NIST has updated their guidelines in [SP 800-56B rev2 (draft)](https://csrc.nist.gov/publications/detail/sp/800-56b/rev-2/draft) providing a formula for the number of security bits it terms of the length of the RSA key in appendix D, rather than relying on a tabulation of values.\r\n\r\nThis is an implementation of this formula using fixed point arithmetic.  For integers 1 .. 100,000 it rounds down to the next smaller 8 bit strength 270 times.  It never errs to the high side.  The errors do not occur near any of the commonly selected RSA lengths.\r\n\r\n- [x] tests are added or updated\r\n\r\n","created_at":"2018-10-04T23:28:41Z","updated_at":"2018-10-18T23:19:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d338dc51c0e419729b9d96f16ff41113ddad9ffa","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":673605928,"node_id":"MDU6TGFiZWw2NzM2MDU5Mjg=","url":"https://api.github.com/repos/openssl/openssl/labels/FIPS","name":"FIPS","color":"bfdadc","default":false},{"id":441165144,"node_id":"MDU6TGFiZWw0NDExNjUxNDQ=","url":"https://api.github.com/repos/openssl/openssl/labels/master","name":"master","color":"bfdadc","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/openssl/openssl/pulls/7352/commits","review_comments_url":"https://api.github.com/repos/openssl/openssl/pulls/7352/comments","review_comment_url":"https://api.github.com/repos/openssl/openssl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openssl/openssl/issues/7352/comments","statuses_url":"https://api.github.com/repos/openssl/openssl/statuses/bcbe068b504b55004c64f34bc7b9b876a7409b2b","head":{"label":"paulidale:800_56b_rsa","ref":"800_56b_rsa","sha":"bcbe068b504b55004c64f34bc7b9b876a7409b2b","user":{"login":"paulidale","id":17916609,"node_id":"MDQ6VXNlcjE3OTE2NjA5","avatar_url":"https://avatars1.githubusercontent.com/u/17916609?v=4","gravatar_id":"","url":"https://api.github.com/users/paulidale","html_url":"https://github.com/paulidale","followers_url":"https://api.github.com/users/paulidale/followers","following_url":"https://api.github.com/users/paulidale/following{/other_user}","gists_url":"https://api.github.com/users/paulidale/gists{/gist_id}","starred_url":"https://api.github.com/users/paulidale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulidale/subscriptions","organizations_url":"https://api.github.com/users/paulidale/orgs","repos_url":"https://api.github.com/users/paulidale/repos","events_url":"https://api.github.com/users/paulidale/events{/privacy}","received_events_url":"https://api.github.com/users/paulidale/received_events","type":"User","site_admin":false},"repo":{"id":80574431,"node_id":"MDEwOlJlcG9zaXRvcnk4MDU3NDQzMQ==","name":"openssl","full_name":"paulidale/openssl","private":false,"owner":{"login":"paulidale","id":17916609,"node_id":"MDQ6VXNlcjE3OTE2NjA5","avatar_url":"https://avatars1.githubusercontent.com/u/17916609?v=4","gravatar_id":"","url":"https://api.github.com/users/paulidale","html_url":"https://github.com/paulidale","followers_url":"https://api.github.com/users/paulidale/followers","following_url":"https://api.github.com/users/paulidale/following{/other_user}","gists_url":"https://api.github.com/users/paulidale/gists{/gist_id}","starred_url":"https://api.github.com/users/paulidale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulidale/subscriptions","organizations_url":"https://api.github.com/users/paulidale/orgs","repos_url":"https://api.github.com/users/paulidale/repos","events_url":"https://api.github.com/users/paulidale/events{/privacy}","received_events_url":"https://api.github.com/users/paulidale/received_events","type":"User","site_admin":false},"html_url":"https://github.com/paulidale/openssl","description":"TLS/SSL and crypto library","fork":true,"url":"https://api.github.com/repos/paulidale/openssl","forks_url":"https://api.github.com/repos/paulidale/openssl/forks","keys_url":"https://api.github.com/repos/paulidale/openssl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paulidale/openssl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paulidale/openssl/teams","hooks_url":"https://api.github.com/repos/paulidale/openssl/hooks","issue_events_url":"https://api.github.com/repos/paulidale/openssl/issues/events{/number}","events_url":"https://api.github.com/repos/paulidale/openssl/events","assignees_url":"https://api.github.com/repos/paulidale/openssl/assignees{/user}","branches_url":"https://api.github.com/repos/paulidale/openssl/branches{/branch}","tags_url":"https://api.github.com/repos/paulidale/openssl/tags","blobs_url":"https://api.github.com/repos/paulidale/openssl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paulidale/openssl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paulidale/openssl/git/refs{/sha}","trees_url":"https://api.github.com/repos/paulidale/openssl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paulidale/openssl/statuses/{sha}","languages_url":"https://api.github.com/repos/paulidale/openssl/languages","stargazers_url":"https://api.github.com/repos/paulidale/openssl/stargazers","contributors_url":"https://api.github.com/repos/paulidale/openssl/contributors","subscribers_url":"https://api.github.com/repos/paulidale/openssl/subscribers","subscription_url":"https://api.github.com/repos/paulidale/openssl/subscription","commits_url":"https://api.github.com/repos/paulidale/openssl/commits{/sha}","git_commits_url":"https://api.github.com/repos/paulidale/openssl/git/commits{/sha}","comments_url":"https://api.github.com/repos/paulidale/openssl/comments{/number}","issue_comment_url":"https://api.github.com/repos/paulidale/openssl/issues/comments{/number}","contents_url":"https://api.github.com/repos/paulidale/openssl/contents/{+path}","compare_url":"https://api.github.com/repos/paulidale/openssl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paulidale/openssl/merges","archive_url":"https://api.github.com/repos/paulidale/openssl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paulidale/openssl/downloads","issues_url":"https://api.github.com/repos/paulidale/openssl/issues{/number}","pulls_url":"https://api.github.com/repos/paulidale/openssl/pulls{/number}","milestones_url":"https://api.github.com/repos/paulidale/openssl/milestones{/number}","notifications_url":"https://api.github.com/repos/paulidale/openssl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paulidale/openssl/labels{/name}","releases_url":"https://api.github.com/repos/paulidale/openssl/releases{/id}","deployments_url":"https://api.github.com/repos/paulidale/openssl/deployments","created_at":"2017-01-31T23:53:16Z","updated_at":"2018-10-18T03:17:03Z","pushed_at":"2018-10-18T03:16:57Z","git_url":"git://github.com/paulidale/openssl.git","ssh_url":"git@github.com:paulidale/openssl.git","clone_url":"https://github.com/paulidale/openssl.git","svn_url":"https://github.com/paulidale/openssl","homepage":"https://www.openssl.org","size":151647,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openssl:master","ref":"master","sha":"b770a80f6d0b08659cd03f26388b45512adb84f3","user":{"login":"openssl","id":3279138,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyNzkxMzg=","avatar_url":"https://avatars2.githubusercontent.com/u/3279138?v=4","gravatar_id":"","url":"https://api.github.com/users/openssl","html_url":"https://github.com/openssl","followers_url":"https://api.github.com/users/openssl/followers","following_url":"https://api.github.com/users/openssl/following{/other_user}","gists_url":"https://api.github.com/users/openssl/gists{/gist_id}","starred_url":"https://api.github.com/users/openssl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openssl/subscriptions","organizations_url":"https://api.github.com/users/openssl/orgs","repos_url":"https://api.github.com/users/openssl/repos","events_url":"https://api.github.com/users/openssl/events{/privacy}","received_events_url":"https://api.github.com/users/openssl/received_events","type":"Organization","site_admin":false},"repo":{"id":7634677,"node_id":"MDEwOlJlcG9zaXRvcnk3NjM0Njc3","name":"openssl","full_name":"openssl/openssl","private":false,"owner":{"login":"openssl","id":3279138,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyNzkxMzg=","avatar_url":"https://avatars2.githubusercontent.com/u/3279138?v=4","gravatar_id":"","url":"https://api.github.com/users/openssl","html_url":"https://github.com/openssl","followers_url":"https://api.github.com/users/openssl/followers","following_url":"https://api.github.com/users/openssl/following{/other_user}","gists_url":"https://api.github.com/users/openssl/gists{/gist_id}","starred_url":"https://api.github.com/users/openssl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openssl/subscriptions","organizations_url":"https://api.github.com/users/openssl/orgs","repos_url":"https://api.github.com/users/openssl/repos","events_url":"https://api.github.com/users/openssl/events{/privacy}","received_events_url":"https://api.github.com/users/openssl/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/openssl/openssl","description":"TLS/SSL and crypto library","fork":false,"url":"https://api.github.com/repos/openssl/openssl","forks_url":"https://api.github.com/repos/openssl/openssl/forks","keys_url":"https://api.github.com/repos/openssl/openssl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openssl/openssl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openssl/openssl/teams","hooks_url":"https://api.github.com/repos/openssl/openssl/hooks","issue_events_url":"https://api.github.com/repos/openssl/openssl/issues/events{/number}","events_url":"https://api.github.com/repos/openssl/openssl/events","assignees_url":"https://api.github.com/repos/openssl/openssl/assignees{/user}","branches_url":"https://api.github.com/repos/openssl/openssl/branches{/branch}","tags_url":"https://api.github.com/repos/openssl/openssl/tags","blobs_url":"https://api.github.com/repos/openssl/openssl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openssl/openssl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openssl/openssl/git/refs{/sha}","trees_url":"https://api.github.com/repos/openssl/openssl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openssl/openssl/statuses/{sha}","languages_url":"https://api.github.com/repos/openssl/openssl/languages","stargazers_url":"https://api.github.com/repos/openssl/openssl/stargazers","contributors_url":"https://api.github.com/repos/openssl/openssl/contributors","subscribers_url":"https://api.github.com/repos/openssl/openssl/subscribers","subscription_url":"https://api.github.com/repos/openssl/openssl/subscription","commits_url":"https://api.github.com/repos/openssl/openssl/commits{/sha}","git_commits_url":"https://api.github.com/repos/openssl/openssl/git/commits{/sha}","comments_url":"https://api.github.com/repos/openssl/openssl/comments{/number}","issue_comment_url":"https://api.github.com/repos/openssl/openssl/issues/comments{/number}","contents_url":"https://api.github.com/repos/openssl/openssl/contents/{+path}","compare_url":"https://api.github.com/repos/openssl/openssl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openssl/openssl/merges","archive_url":"https://api.github.com/repos/openssl/openssl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openssl/openssl/downloads","issues_url":"https://api.github.com/repos/openssl/openssl/issues{/number}","pulls_url":"https://api.github.com/repos/openssl/openssl/pulls{/number}","milestones_url":"https://api.github.com/repos/openssl/openssl/milestones{/number}","notifications_url":"https://api.github.com/repos/openssl/openssl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openssl/openssl/labels{/name}","releases_url":"https://api.github.com/repos/openssl/openssl/releases{/id}","deployments_url":"https://api.github.com/repos/openssl/openssl/deployments","created_at":"2013-01-15T22:34:48Z","updated_at":"2018-10-18T22:33:38Z","pushed_at":"2018-10-18T22:42:47Z","git_url":"git://github.com/openssl/openssl.git","ssh_url":"git@github.com:openssl/openssl.git","clone_url":"https://github.com/openssl/openssl.git","svn_url":"https://github.com/openssl/openssl","homepage":"https://www.openssl.org","size":159232,"stargazers_count":8472,"watchers_count":8472,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3895,"mirror_url":null,"archived":false,"open_issues_count":551,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":3895,"open_issues":551,"watchers":8472,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openssl/openssl/pulls/7352"},"html":{"href":"https://github.com/openssl/openssl/pull/7352"},"issue":{"href":"https://api.github.com/repos/openssl/openssl/issues/7352"},"comments":{"href":"https://api.github.com/repos/openssl/openssl/issues/7352/comments"},"review_comments":{"href":"https://api.github.com/repos/openssl/openssl/pulls/7352/comments"},"review_comment":{"href":"https://api.github.com/repos/openssl/openssl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openssl/openssl/pulls/7352/commits"},"statuses":{"href":"https://api.github.com/repos/openssl/openssl/statuses/bcbe068b504b55004c64f34bc7b9b876a7409b2b"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"paulidale"}}