{"action":"created","comment":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/comments/31587702","id":31587702,"diff_hunk":"@@ -0,0 +1,168 @@\n+/*\n+ * Copyright (c) 2015, DiUS Computing Pty Ltd (jmattsson@dius.com.au)\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ * 1. Redistributions of source code must retain the above copyright\n+ *    notice, this list of conditions and the following disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ *    notice, this list of conditions and the following disclaimer in the\n+ *    documentation and/or other materials provided with the distribution.\n+ * 3. Neither the name of the copyright holder nor the names of contributors\n+ *    may be used to endorse or promote products derived from this software\n+ *    without specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND\n+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE\n+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n+ * SUCH DAMAGE.\n+ *\n+ */\n+#include \"digests.h\"\n+#include \"lwip/mem.h\"\n+#include \"lwip/arch.h\"\n+#include \"ssl/ssl_crypto.h\"\n+#include \"sha2.h\"\n+#include <string.h>\n+#include <c_errno.h>\n+\n+typedef char ensure_int_and_size_t_same[(sizeof(int)==sizeof(size_t)) ? 0 : -1];\n+\n+/* None of the functions match the prototype fully due to the void *, and in\n+   some cases also the int vs size_t len, so wrap declarations in a macro. */\n+#define MECH(pfx, ds, bs) \\\n+  { #pfx, \\\n+    (create_ctx_fn)pfx ## _Init, \\\n+    (update_ctx_fn)pfx ## _Update, \\\n+    (finalize_ctx_fn)pfx ## _Final, \\\n+    sizeof(pfx ## _CTX), \\\n+    ds, \\\n+    bs }\n+\n+static const digest_mech_info_t hash_mechs[] =\n+{\n+   MECH(MD2,  MD2_SIZE,  16)\n+  ,MECH(MD5,  MD5_SIZE,  64)\n+  ,MECH(SHA1, SHA1_SIZE, 64)\n+#ifndef WITHOUT_SHA2\n+  ,MECH(SHA256, SHA256_DIGEST_LENGTH, SHA256_BLOCK_LENGTH)\n+  ,MECH(SHA384, SHA384_DIGEST_LENGTH, SHA384_BLOCK_LENGTH)\n+  ,MECH(SHA512, SHA512_DIGEST_LENGTH, SHA512_BLOCK_LENGTH)\n+#endif\n+};\n+\n+#undef MECH\n+\n+const digest_mech_info_t *crypto_digest_mech (const char *mech)\n+{\n+  if (!mech)\n+    return 0;\n+\n+  size_t i;\n+  for (i = 0; i < (sizeof (hash_mechs) / sizeof (digest_mech_info_t)); ++i)\n+  {\n+    const digest_mech_info_t *mi = hash_mechs + i;\n+    if (strcasecmp (mech, mi->name) == 0)\n+      return mi;\n+  }\n+  return 0;\n+}\n+\n+static const char hex[] = \"0123456789abcdef\";","path":"app/crypto/digests.c","position":81,"original_position":80,"commit_id":"06724fbb1771386cae73d0dd1387a48384282fbd","original_commit_id":"2d1e69151e251bcd371201b2dd3ad30a7defd2c6","user":{"login":"jmattsson","id":869607,"avatar_url":"https://avatars.githubusercontent.com/u/869607?v=3","gravatar_id":"","url":"https://api.github.com/users/jmattsson","html_url":"https://github.com/jmattsson","followers_url":"https://api.github.com/users/jmattsson/followers","following_url":"https://api.github.com/users/jmattsson/following{/other_user}","gists_url":"https://api.github.com/users/jmattsson/gists{/gist_id}","starred_url":"https://api.github.com/users/jmattsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmattsson/subscriptions","organizations_url":"https://api.github.com/users/jmattsson/orgs","repos_url":"https://api.github.com/users/jmattsson/repos","events_url":"https://api.github.com/users/jmattsson/events{/privacy}","received_events_url":"https://api.github.com/users/jmattsson/received_events","type":"User","site_admin":false},"body":"Yeah, I'm using it from another module I'm writing. I did see your hex encoder function, but it looked small enough that it didn't seem worthwhile to replace its internals with a call to mine. I figured in most cases mine would go unused and the linker would omit it altogether.","created_at":"2015-06-03T01:31:15Z","updated_at":"2015-06-03T01:31:15Z","html_url":"https://github.com/nodemcu/nodemcu-firmware/pull/463#discussion_r31587702","pull_request_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/463","_links":{"self":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/comments/31587702"},"html":{"href":"https://github.com/nodemcu/nodemcu-firmware/pull/463#discussion_r31587702"},"pull_request":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/463"}}},"pull_request":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/463","id":36704838,"html_url":"https://github.com/nodemcu/nodemcu-firmware/pull/463","diff_url":"https://github.com/nodemcu/nodemcu-firmware/pull/463.diff","patch_url":"https://github.com/nodemcu/nodemcu-firmware/pull/463.patch","issue_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/463","number":463,"state":"open","locked":false,"title":"Crypto module, take 2","user":{"login":"jmattsson","id":869607,"avatar_url":"https://avatars.githubusercontent.com/u/869607?v=3","gravatar_id":"","url":"https://api.github.com/users/jmattsson","html_url":"https://github.com/jmattsson","followers_url":"https://api.github.com/users/jmattsson/followers","following_url":"https://api.github.com/users/jmattsson/following{/other_user}","gists_url":"https://api.github.com/users/jmattsson/gists{/gist_id}","starred_url":"https://api.github.com/users/jmattsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmattsson/subscriptions","organizations_url":"https://api.github.com/users/jmattsson/orgs","repos_url":"https://api.github.com/users/jmattsson/repos","events_url":"https://api.github.com/users/jmattsson/events{/privacy}","received_events_url":"https://api.github.com/users/jmattsson/received_events","type":"User","site_admin":false},"body":"Hello again,\r\n\r\nSince there's clearly interest in a Lua crypto module, I reworked my earlier stuff to integrate with creationix's crypto module instead. This branch now extends it to provide the .hash() and .hmac() functions, and also introduces support for SHA{256,384,512} through the newly created libcrypto.a. This is using Aaron Gifford's SHA256 implementation. The whole thing can be built without the SHA256 support if WITHOUT_SHA2 is defined, for those wishing to conserve space and not needing any of the SHA2 stuff.\r\n\r\nExample usage:\r\n\r\nlocal rawhash = crypto.hash('MD5', \"abc\")\r\nlocal rawsignature = crypto.hmac('SHA256', \"abc\", \"mysecretkey\")\r\n","created_at":"2015-06-02T08:30:05Z","updated_at":"2015-06-03T01:31:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3588845e4fbb6da1d717204d9d6ebcbc2ac8f9fe","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/463/commits","review_comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/463/comments","review_comment_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/463/comments","statuses_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/statuses/06724fbb1771386cae73d0dd1387a48384282fbd","head":{"label":"DiUS:newcrypto","ref":"newcrypto","sha":"06724fbb1771386cae73d0dd1387a48384282fbd","user":{"login":"DiUS","id":164113,"avatar_url":"https://avatars.githubusercontent.com/u/164113?v=3","gravatar_id":"","url":"https://api.github.com/users/DiUS","html_url":"https://github.com/DiUS","followers_url":"https://api.github.com/users/DiUS/followers","following_url":"https://api.github.com/users/DiUS/following{/other_user}","gists_url":"https://api.github.com/users/DiUS/gists{/gist_id}","starred_url":"https://api.github.com/users/DiUS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DiUS/subscriptions","organizations_url":"https://api.github.com/users/DiUS/orgs","repos_url":"https://api.github.com/users/DiUS/repos","events_url":"https://api.github.com/users/DiUS/events{/privacy}","received_events_url":"https://api.github.com/users/DiUS/received_events","type":"Organization","site_admin":false},"repo":{"id":36700318,"name":"nodemcu-firmware","full_name":"DiUS/nodemcu-firmware","owner":{"login":"DiUS","id":164113,"avatar_url":"https://avatars.githubusercontent.com/u/164113?v=3","gravatar_id":"","url":"https://api.github.com/users/DiUS","html_url":"https://github.com/DiUS","followers_url":"https://api.github.com/users/DiUS/followers","following_url":"https://api.github.com/users/DiUS/following{/other_user}","gists_url":"https://api.github.com/users/DiUS/gists{/gist_id}","starred_url":"https://api.github.com/users/DiUS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DiUS/subscriptions","organizations_url":"https://api.github.com/users/DiUS/orgs","repos_url":"https://api.github.com/users/DiUS/repos","events_url":"https://api.github.com/users/DiUS/events{/privacy}","received_events_url":"https://api.github.com/users/DiUS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DiUS/nodemcu-firmware","description":"lua based interactive firmware for mcu like esp8266","fork":true,"url":"https://api.github.com/repos/DiUS/nodemcu-firmware","forks_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/forks","keys_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/teams","hooks_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/hooks","issue_events_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/issues/events{/number}","events_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/events","assignees_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/assignees{/user}","branches_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/branches{/branch}","tags_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/tags","blobs_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/languages","stargazers_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/stargazers","contributors_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/contributors","subscribers_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/subscribers","subscription_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/subscription","commits_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/contents/{+path}","compare_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/merges","archive_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/downloads","issues_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/issues{/number}","pulls_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/labels{/name}","releases_url":"https://api.github.com/repos/DiUS/nodemcu-firmware/releases{/id}","created_at":"2015-06-02T01:38:16Z","updated_at":"2015-06-02T01:38:19Z","pushed_at":"2015-06-03T01:20:27Z","git_url":"git://github.com/DiUS/nodemcu-firmware.git","ssh_url":"git@github.com:DiUS/nodemcu-firmware.git","clone_url":"https://github.com/DiUS/nodemcu-firmware.git","svn_url":"https://github.com/DiUS/nodemcu-firmware","homepage":"http://nodemcu.com","size":14907,"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":"nodemcu:dev","ref":"dev","sha":"d8a8746b9ecb33a46909c334a25d0779709437ed","user":{"login":"nodemcu","id":9865736,"avatar_url":"https://avatars.githubusercontent.com/u/9865736?v=3","gravatar_id":"","url":"https://api.github.com/users/nodemcu","html_url":"https://github.com/nodemcu","followers_url":"https://api.github.com/users/nodemcu/followers","following_url":"https://api.github.com/users/nodemcu/following{/other_user}","gists_url":"https://api.github.com/users/nodemcu/gists{/gist_id}","starred_url":"https://api.github.com/users/nodemcu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodemcu/subscriptions","organizations_url":"https://api.github.com/users/nodemcu/orgs","repos_url":"https://api.github.com/users/nodemcu/repos","events_url":"https://api.github.com/users/nodemcu/events{/privacy}","received_events_url":"https://api.github.com/users/nodemcu/received_events","type":"User","site_admin":false},"repo":{"id":26917568,"name":"nodemcu-firmware","full_name":"nodemcu/nodemcu-firmware","owner":{"login":"nodemcu","id":9865736,"avatar_url":"https://avatars.githubusercontent.com/u/9865736?v=3","gravatar_id":"","url":"https://api.github.com/users/nodemcu","html_url":"https://github.com/nodemcu","followers_url":"https://api.github.com/users/nodemcu/followers","following_url":"https://api.github.com/users/nodemcu/following{/other_user}","gists_url":"https://api.github.com/users/nodemcu/gists{/gist_id}","starred_url":"https://api.github.com/users/nodemcu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodemcu/subscriptions","organizations_url":"https://api.github.com/users/nodemcu/orgs","repos_url":"https://api.github.com/users/nodemcu/repos","events_url":"https://api.github.com/users/nodemcu/events{/privacy}","received_events_url":"https://api.github.com/users/nodemcu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nodemcu/nodemcu-firmware","description":"lua based interactive firmware for mcu like esp8266","fork":false,"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware","forks_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/forks","keys_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/teams","hooks_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/hooks","issue_events_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/events{/number}","events_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/events","assignees_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/assignees{/user}","branches_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/branches{/branch}","tags_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/tags","blobs_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/languages","stargazers_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/stargazers","contributors_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/contributors","subscribers_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/subscribers","subscription_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/subscription","commits_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/contents/{+path}","compare_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/merges","archive_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/downloads","issues_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues{/number}","pulls_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/labels{/name}","releases_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/releases{/id}","created_at":"2014-11-20T15:06:45Z","updated_at":"2015-06-02T21:07:25Z","pushed_at":"2015-06-03T01:20:28Z","git_url":"git://github.com/nodemcu/nodemcu-firmware.git","ssh_url":"git@github.com:nodemcu/nodemcu-firmware.git","clone_url":"https://github.com/nodemcu/nodemcu-firmware.git","svn_url":"https://github.com/nodemcu/nodemcu-firmware","homepage":"http://nodemcu.com","size":14907,"stargazers_count":875,"watchers_count":875,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":352,"mirror_url":null,"open_issues_count":128,"forks":352,"open_issues":128,"watchers":875,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/463"},"html":{"href":"https://github.com/nodemcu/nodemcu-firmware/pull/463"},"issue":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/463"},"comments":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/463/comments"},"review_comments":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/463/comments"},"review_comment":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/463/commits"},"statuses":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/statuses/06724fbb1771386cae73d0dd1387a48384282fbd"}}}}