{"id":19885685,"url":"https://github.com/asmod4n/mruby-secure-compare","last_synced_at":"2026-06-11T17:31:23.445Z","repository":{"id":76216535,"uuid":"62993507","full_name":"Asmod4n/mruby-secure-compare","owner":"Asmod4n","description":"Secure String comparisons for mruby","archived":false,"fork":false,"pushed_at":"2024-11-23T18:33:54.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-01T03:47:13.963Z","etag":null,"topics":["mruby"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Asmod4n.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-10T10:29:03.000Z","updated_at":"2024-11-23T18:33:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"7bb6427c-c3fd-4b41-a671-755a3a81bb7d","html_url":"https://github.com/Asmod4n/mruby-secure-compare","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Asmod4n/mruby-secure-compare","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asmod4n%2Fmruby-secure-compare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asmod4n%2Fmruby-secure-compare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asmod4n%2Fmruby-secure-compare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asmod4n%2Fmruby-secure-compare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Asmod4n","download_url":"https://codeload.github.com/Asmod4n/mruby-secure-compare/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asmod4n%2Fmruby-secure-compare/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34211061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mruby"],"created_at":"2024-11-12T17:35:17.338Z","updated_at":"2026-06-11T17:31:23.428Z","avatar_url":"https://github.com/Asmod4n.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mruby-secure-compare\n**Secure String comparisons for mruby**\n\n## Examples\n**Always use the secret as the first argument.**\n\nC Example\n\n```c\n#include \u003cmruby/secure_compare.h\u003e\n#include \u003cmruby/string.h\u003e\n\nmrb_value secret = mrb_str_new_lit(mrb, \"hallo\");\nmrb_value input = mrb_str_new_lit(mrb, \"hallo\");\n\nif (mrb_secure_memcmp(RSTRING_PTR(secret), RSTRING_LEN(secret), RSTRING_PTR(input), RSTRING_LEN(input))) {\n  puts(\"access granted\");\n}\n```\n\nRuby Example\n\n```ruby\nmy_super_secure_secret = \"hallo\"\nuser_input = \"hallo\"\nif my_super_secure_secret.securecmp(user_input)\n  puts \"access granted\"\nend\n```\n\nThis gem provides a simple, fast way to do string comparisons that resist timing attacks.\n\n## What is a timing attack?\nA timing attack is an attack on a system that determines secret information based on how long an operation takes.\n\nTiming attacks are particularly prevalent (and dangerous) in cryptographic operations, but they can also sneak into other types of operation.\n\nIn particular, any time you are comparing user-specified input with a secret, you should consider whether or not you are exposing yourself to a timing attack.\n\nThe attack is probably best described by [Nate Lawson](http://rdist.root.org/2010/07/19/exploiting-remote-timing-attacks/):\n\n\u003e \"The attack is very simple. You repeatedly send guesses about a secret value to the server, which rejects them as incorrect. However, if your first byte of the guess is correct, it takes a very slightly longer time to return the error. With many measurements and some filtering, you can distinguish this difference.\"\n\nTherefore, it's important that the amount of time these operations take depends only on the length of the user's input, and not on any characteristic of the secret data.\n\n## How does this gem help? Why should I use it rather than rolling my own?\nThis gem provides a secure comparison function that is:\n- **Very simple**: Adds one method to the String class, also exports the C function for other gems to use.\n- **Fast**: It uses a C back-end rather than a pure Ruby implementation.\n- **Portable**: The C code is platform-independent.\n\nFurthermore, unlike some other secure comparison functions, the code does not require that the strings are the same length, and should not leak the length of the string if the string lengths do not match.\n\n## Is there anything else I should know?\n- The gem is **not foolproof**. In particular, it can't protect you against anything designed to exploit cache misses or any other more elaborate form of timing attack. However, none of the existing pure Ruby secure_compare functions do either.\n- **Argument Order**: Putting the arguments around the wrong way may leak the length of your secret.\n- **Length of Secret**: Don't use a secret of length 0.\n\nLicense\n=======\n\nCopyright 2024 Hendrik Beskow\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this project except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\nAcknowledgements\n================\n\nThis is using a variation from sodium_memcmp from libsodium (https://github.com/jedisct1/libsodium)\n\nISC License\n\nCopyright (c) 2013-2016\nFrank Denis \u003cj at pureftpd dot org\u003e\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted, provided that the above\ncopyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\nWITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\nANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\nWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\nACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\nOR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n\n\nIt is also influenced by fast_secure_compare from https://github.com/daxtens/fast_secure_compare\n\nCopyright (c) 2014 Daniel Axtens\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasmod4n%2Fmruby-secure-compare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasmod4n%2Fmruby-secure-compare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasmod4n%2Fmruby-secure-compare/lists"}