{"action":"created","comment":{"url":"https://api.github.com/repos/runtimejs/runtime/pulls/comments/34286774","id":34286774,"diff_hunk":"@@ -0,0 +1,168 @@\n+// Copyright 2015 runtime.js project authors\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+'use strict';\n+\n+var isaac = require('../../deps/isaac/isaac');\n+\n+// isaac.js returns crazy numbers, both positive and negative.\n+// This function is called on an isaac.rand() call,\n+// It gets the number to qualify for all of the following:\n+//  * Positive,\n+//  * Whole number,\n+//  * 0 < n < 256\n+// This ensures the numbers are similar to the numbers\n+// generated by VirtioRNG.\n+function isaacRound(n) {\n+  // Ensure it's positive\n+  if (n < 0) n = -n;\n+  // 0 < n < 256\n+  while (n > 256) n /= 4;\n+  // Whole number\n+  n = Math.round(n);\n+\n+  return n;\n+}\n+\n+var def = 'none';\n+var sources = {\n+  // If there are no methods specified and someone requests randomness,\n+  // use the default 'none' method which uses isaac.rand().\n+  // isaac.js uses Math.random as the initial seed (which does not use true\n+  // randomness), that's why as soon as the VirtioRNG device loads,\n+  // it sets itself as the default, since it uses true randomness.\n+  'none': {\n+    queue: [],\n+    init: function() {\n+      for (var i = 0; i < 256; i++) {\n+        sources['none'].queue.push(isaacRound(isaac.rand()));\n+      }\n+    },\n+    realRand: function(cb) {\n+      for (var i = 0; i < 256; i++) {\n+        sources['none'].queue.push(isaacRound(isaac.rand()));\n+      }\n+      cb();\n+    },\n+    seed: function() {\n+      return isaacRound(isaac.rand());\n+    },\n+    fillQueue: function() {\n+      for (var i = 0; i < 256; i++) {\n+        sources['none'].queue.push(isaacRound(isaac.rand()));\n+      }\n+    }\n+  }\n+};\n+\n+sources['none'].init();\n+\n+module.exports = {\n+  addSource: function(name, obj) {\n+    sources[name] = obj;\n+    sources[name].init();\n+  },\n+  setDefault: function(name) {\n+    if (!sources[name]) {\n+      return false;\n+    }\n+\n+    def = name;\n+    return true;\n+  },\n+  rand: function(length, cb) {","path":"js/core/random/index.js","position":84,"original_position":84,"commit_id":"d4c70029c26f7843572c74afe91e78f683e470f4","original_commit_id":"d4c70029c26f7843572c74afe91e78f683e470f4","user":{"login":"ArielAbreu","id":11756574,"avatar_url":"https://avatars.githubusercontent.com/u/11756574?v=3","gravatar_id":"","url":"https://api.github.com/users/ArielAbreu","html_url":"https://github.com/ArielAbreu","followers_url":"https://api.github.com/users/ArielAbreu/followers","following_url":"https://api.github.com/users/ArielAbreu/following{/other_user}","gists_url":"https://api.github.com/users/ArielAbreu/gists{/gist_id}","starred_url":"https://api.github.com/users/ArielAbreu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArielAbreu/subscriptions","organizations_url":"https://api.github.com/users/ArielAbreu/orgs","repos_url":"https://api.github.com/users/ArielAbreu/repos","events_url":"https://api.github.com/users/ArielAbreu/events{/privacy}","received_events_url":"https://api.github.com/users/ArielAbreu/received_events","type":"User","site_admin":false},"body":"For `urand()`, it could possibly write the values into it, if the parameter is given, otherwise, it returns a new buffer. And yes i'll, rename the functions.","created_at":"2015-07-09T18:25:32Z","updated_at":"2015-07-09T18:25:32Z","html_url":"https://github.com/runtimejs/runtime/pull/73#discussion_r34286774","pull_request_url":"https://api.github.com/repos/runtimejs/runtime/pulls/73","_links":{"self":{"href":"https://api.github.com/repos/runtimejs/runtime/pulls/comments/34286774"},"html":{"href":"https://github.com/runtimejs/runtime/pull/73#discussion_r34286774"},"pull_request":{"href":"https://api.github.com/repos/runtimejs/runtime/pulls/73"}}},"pull_request":{"url":"https://api.github.com/repos/runtimejs/runtime/pulls/73","id":39225089,"html_url":"https://github.com/runtimejs/runtime/pull/73","diff_url":"https://github.com/runtimejs/runtime/pull/73.diff","patch_url":"https://github.com/runtimejs/runtime/pull/73.patch","issue_url":"https://api.github.com/repos/runtimejs/runtime/issues/73","number":73,"state":"open","locked":false,"title":"Add RNG driver","user":{"login":"ArielAbreu","id":11756574,"avatar_url":"https://avatars.githubusercontent.com/u/11756574?v=3","gravatar_id":"","url":"https://api.github.com/users/ArielAbreu","html_url":"https://github.com/ArielAbreu","followers_url":"https://api.github.com/users/ArielAbreu/followers","following_url":"https://api.github.com/users/ArielAbreu/following{/other_user}","gists_url":"https://api.github.com/users/ArielAbreu/gists{/gist_id}","starred_url":"https://api.github.com/users/ArielAbreu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArielAbreu/subscriptions","organizations_url":"https://api.github.com/users/ArielAbreu/orgs","repos_url":"https://api.github.com/users/ArielAbreu/repos","events_url":"https://api.github.com/users/ArielAbreu/events{/privacy}","received_events_url":"https://api.github.com/users/ArielAbreu/received_events","type":"User","site_admin":false},"body":"This PR adds a VirtioRNG driver. Exposes `getRand(cb)` and `getRandLength(length, cb)` in `runtime.driver.rng` (though, i'm pretty sure you'll want to change that, seems like a bad place for it). I had to remove the PCI debug info iterator, because for some reason, having it there prevented the PCI lister function from reading the RNG device (in fact, it hung the system and didn't even load the shell). I know that's a bug, but for now that's the alternative I could find. Now someone just needs to provide an interface for libsodium 😄. I'm working on a custom (no libsodium) `randomBytes` implementation.","created_at":"2015-07-05T18:53:36Z","updated_at":"2015-07-09T18:25:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6b2efd8933c7acb9e18c432870cffdd9bf888ff0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/runtimejs/runtime/pulls/73/commits","review_comments_url":"https://api.github.com/repos/runtimejs/runtime/pulls/73/comments","review_comment_url":"https://api.github.com/repos/runtimejs/runtime/pulls/comments{/number}","comments_url":"https://api.github.com/repos/runtimejs/runtime/issues/73/comments","statuses_url":"https://api.github.com/repos/runtimejs/runtime/statuses/d4c70029c26f7843572c74afe91e78f683e470f4","head":{"label":"ArielAbreu:virtiorng","ref":"virtiorng","sha":"d4c70029c26f7843572c74afe91e78f683e470f4","user":{"login":"ArielAbreu","id":11756574,"avatar_url":"https://avatars.githubusercontent.com/u/11756574?v=3","gravatar_id":"","url":"https://api.github.com/users/ArielAbreu","html_url":"https://github.com/ArielAbreu","followers_url":"https://api.github.com/users/ArielAbreu/followers","following_url":"https://api.github.com/users/ArielAbreu/following{/other_user}","gists_url":"https://api.github.com/users/ArielAbreu/gists{/gist_id}","starred_url":"https://api.github.com/users/ArielAbreu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArielAbreu/subscriptions","organizations_url":"https://api.github.com/users/ArielAbreu/orgs","repos_url":"https://api.github.com/users/ArielAbreu/repos","events_url":"https://api.github.com/users/ArielAbreu/events{/privacy}","received_events_url":"https://api.github.com/users/ArielAbreu/received_events","type":"User","site_admin":false},"repo":{"id":38538108,"name":"runtime","full_name":"ArielAbreu/runtime","owner":{"login":"ArielAbreu","id":11756574,"avatar_url":"https://avatars.githubusercontent.com/u/11756574?v=3","gravatar_id":"","url":"https://api.github.com/users/ArielAbreu","html_url":"https://github.com/ArielAbreu","followers_url":"https://api.github.com/users/ArielAbreu/followers","following_url":"https://api.github.com/users/ArielAbreu/following{/other_user}","gists_url":"https://api.github.com/users/ArielAbreu/gists{/gist_id}","starred_url":"https://api.github.com/users/ArielAbreu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArielAbreu/subscriptions","organizations_url":"https://api.github.com/users/ArielAbreu/orgs","repos_url":"https://api.github.com/users/ArielAbreu/repos","events_url":"https://api.github.com/users/ArielAbreu/events{/privacy}","received_events_url":"https://api.github.com/users/ArielAbreu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ArielAbreu/runtime","description":"JavaScript library operating system for the cloud","fork":true,"url":"https://api.github.com/repos/ArielAbreu/runtime","forks_url":"https://api.github.com/repos/ArielAbreu/runtime/forks","keys_url":"https://api.github.com/repos/ArielAbreu/runtime/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ArielAbreu/runtime/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ArielAbreu/runtime/teams","hooks_url":"https://api.github.com/repos/ArielAbreu/runtime/hooks","issue_events_url":"https://api.github.com/repos/ArielAbreu/runtime/issues/events{/number}","events_url":"https://api.github.com/repos/ArielAbreu/runtime/events","assignees_url":"https://api.github.com/repos/ArielAbreu/runtime/assignees{/user}","branches_url":"https://api.github.com/repos/ArielAbreu/runtime/branches{/branch}","tags_url":"https://api.github.com/repos/ArielAbreu/runtime/tags","blobs_url":"https://api.github.com/repos/ArielAbreu/runtime/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ArielAbreu/runtime/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ArielAbreu/runtime/git/refs{/sha}","trees_url":"https://api.github.com/repos/ArielAbreu/runtime/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ArielAbreu/runtime/statuses/{sha}","languages_url":"https://api.github.com/repos/ArielAbreu/runtime/languages","stargazers_url":"https://api.github.com/repos/ArielAbreu/runtime/stargazers","contributors_url":"https://api.github.com/repos/ArielAbreu/runtime/contributors","subscribers_url":"https://api.github.com/repos/ArielAbreu/runtime/subscribers","subscription_url":"https://api.github.com/repos/ArielAbreu/runtime/subscription","commits_url":"https://api.github.com/repos/ArielAbreu/runtime/commits{/sha}","git_commits_url":"https://api.github.com/repos/ArielAbreu/runtime/git/commits{/sha}","comments_url":"https://api.github.com/repos/ArielAbreu/runtime/comments{/number}","issue_comment_url":"https://api.github.com/repos/ArielAbreu/runtime/issues/comments{/number}","contents_url":"https://api.github.com/repos/ArielAbreu/runtime/contents/{+path}","compare_url":"https://api.github.com/repos/ArielAbreu/runtime/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ArielAbreu/runtime/merges","archive_url":"https://api.github.com/repos/ArielAbreu/runtime/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ArielAbreu/runtime/downloads","issues_url":"https://api.github.com/repos/ArielAbreu/runtime/issues{/number}","pulls_url":"https://api.github.com/repos/ArielAbreu/runtime/pulls{/number}","milestones_url":"https://api.github.com/repos/ArielAbreu/runtime/milestones{/number}","notifications_url":"https://api.github.com/repos/ArielAbreu/runtime/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ArielAbreu/runtime/labels{/name}","releases_url":"https://api.github.com/repos/ArielAbreu/runtime/releases{/id}","created_at":"2015-07-04T15:20:41Z","updated_at":"2015-07-04T15:20:42Z","pushed_at":"2015-07-09T16:58:51Z","git_url":"git://github.com/ArielAbreu/runtime.git","ssh_url":"git@github.com:ArielAbreu/runtime.git","clone_url":"https://github.com/ArielAbreu/runtime.git","svn_url":"https://github.com/ArielAbreu/runtime","homepage":"http://runtimejs.org","size":62612,"stargazers_count":0,"watchers_count":0,"language":"C++","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":"master"}},"base":{"label":"runtimejs:master","ref":"master","sha":"42ccf7c20978c1d41a285318b636a7120b8e31cb","user":{"login":"runtimejs","id":7094989,"avatar_url":"https://avatars.githubusercontent.com/u/7094989?v=3","gravatar_id":"","url":"https://api.github.com/users/runtimejs","html_url":"https://github.com/runtimejs","followers_url":"https://api.github.com/users/runtimejs/followers","following_url":"https://api.github.com/users/runtimejs/following{/other_user}","gists_url":"https://api.github.com/users/runtimejs/gists{/gist_id}","starred_url":"https://api.github.com/users/runtimejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/runtimejs/subscriptions","organizations_url":"https://api.github.com/users/runtimejs/orgs","repos_url":"https://api.github.com/users/runtimejs/repos","events_url":"https://api.github.com/users/runtimejs/events{/privacy}","received_events_url":"https://api.github.com/users/runtimejs/received_events","type":"Organization","site_admin":false},"repo":{"id":20153919,"name":"runtime","full_name":"runtimejs/runtime","owner":{"login":"runtimejs","id":7094989,"avatar_url":"https://avatars.githubusercontent.com/u/7094989?v=3","gravatar_id":"","url":"https://api.github.com/users/runtimejs","html_url":"https://github.com/runtimejs","followers_url":"https://api.github.com/users/runtimejs/followers","following_url":"https://api.github.com/users/runtimejs/following{/other_user}","gists_url":"https://api.github.com/users/runtimejs/gists{/gist_id}","starred_url":"https://api.github.com/users/runtimejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/runtimejs/subscriptions","organizations_url":"https://api.github.com/users/runtimejs/orgs","repos_url":"https://api.github.com/users/runtimejs/repos","events_url":"https://api.github.com/users/runtimejs/events{/privacy}","received_events_url":"https://api.github.com/users/runtimejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/runtimejs/runtime","description":"JavaScript library operating system for the cloud","fork":false,"url":"https://api.github.com/repos/runtimejs/runtime","forks_url":"https://api.github.com/repos/runtimejs/runtime/forks","keys_url":"https://api.github.com/repos/runtimejs/runtime/keys{/key_id}","collaborators_url":"https://api.github.com/repos/runtimejs/runtime/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/runtimejs/runtime/teams","hooks_url":"https://api.github.com/repos/runtimejs/runtime/hooks","issue_events_url":"https://api.github.com/repos/runtimejs/runtime/issues/events{/number}","events_url":"https://api.github.com/repos/runtimejs/runtime/events","assignees_url":"https://api.github.com/repos/runtimejs/runtime/assignees{/user}","branches_url":"https://api.github.com/repos/runtimejs/runtime/branches{/branch}","tags_url":"https://api.github.com/repos/runtimejs/runtime/tags","blobs_url":"https://api.github.com/repos/runtimejs/runtime/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/runtimejs/runtime/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/runtimejs/runtime/git/refs{/sha}","trees_url":"https://api.github.com/repos/runtimejs/runtime/git/trees{/sha}","statuses_url":"https://api.github.com/repos/runtimejs/runtime/statuses/{sha}","languages_url":"https://api.github.com/repos/runtimejs/runtime/languages","stargazers_url":"https://api.github.com/repos/runtimejs/runtime/stargazers","contributors_url":"https://api.github.com/repos/runtimejs/runtime/contributors","subscribers_url":"https://api.github.com/repos/runtimejs/runtime/subscribers","subscription_url":"https://api.github.com/repos/runtimejs/runtime/subscription","commits_url":"https://api.github.com/repos/runtimejs/runtime/commits{/sha}","git_commits_url":"https://api.github.com/repos/runtimejs/runtime/git/commits{/sha}","comments_url":"https://api.github.com/repos/runtimejs/runtime/comments{/number}","issue_comment_url":"https://api.github.com/repos/runtimejs/runtime/issues/comments{/number}","contents_url":"https://api.github.com/repos/runtimejs/runtime/contents/{+path}","compare_url":"https://api.github.com/repos/runtimejs/runtime/compare/{base}...{head}","merges_url":"https://api.github.com/repos/runtimejs/runtime/merges","archive_url":"https://api.github.com/repos/runtimejs/runtime/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/runtimejs/runtime/downloads","issues_url":"https://api.github.com/repos/runtimejs/runtime/issues{/number}","pulls_url":"https://api.github.com/repos/runtimejs/runtime/pulls{/number}","milestones_url":"https://api.github.com/repos/runtimejs/runtime/milestones{/number}","notifications_url":"https://api.github.com/repos/runtimejs/runtime/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/runtimejs/runtime/labels{/name}","releases_url":"https://api.github.com/repos/runtimejs/runtime/releases{/id}","created_at":"2014-05-25T12:26:29Z","updated_at":"2015-07-08T02:12:57Z","pushed_at":"2015-07-09T16:58:52Z","git_url":"git://github.com/runtimejs/runtime.git","ssh_url":"git@github.com:runtimejs/runtime.git","clone_url":"https://github.com/runtimejs/runtime.git","svn_url":"https://github.com/runtimejs/runtime","homepage":"http://runtimejs.org","size":63731,"stargazers_count":1090,"watchers_count":1090,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":61,"mirror_url":null,"open_issues_count":14,"forks":61,"open_issues":14,"watchers":1090,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/runtimejs/runtime/pulls/73"},"html":{"href":"https://github.com/runtimejs/runtime/pull/73"},"issue":{"href":"https://api.github.com/repos/runtimejs/runtime/issues/73"},"comments":{"href":"https://api.github.com/repos/runtimejs/runtime/issues/73/comments"},"review_comments":{"href":"https://api.github.com/repos/runtimejs/runtime/pulls/73/comments"},"review_comment":{"href":"https://api.github.com/repos/runtimejs/runtime/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/runtimejs/runtime/pulls/73/commits"},"statuses":{"href":"https://api.github.com/repos/runtimejs/runtime/statuses/d4c70029c26f7843572c74afe91e78f683e470f4"}}}}