{"id":22912012,"url":"https://github.com/opencoff/mt-arc4random","last_synced_at":"2025-10-29T08:12:50.756Z","repository":{"id":75757110,"uuid":"43846927","full_name":"opencoff/mt-arc4random","owner":"opencoff","description":"Thread-Aware, thread-safe user-space port of OpenBSD arc4random (chacha20)","archived":false,"fork":false,"pushed_at":"2016-06-19T23:14:26.000Z","size":21,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-10T20:21:46.387Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opencoff.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":"2015-10-07T21:54:09.000Z","updated_at":"2023-10-11T06:19:49.000Z","dependencies_parsed_at":"2023-06-07T14:45:06.410Z","dependency_job_id":null,"html_url":"https://github.com/opencoff/mt-arc4random","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencoff%2Fmt-arc4random","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencoff%2Fmt-arc4random/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencoff%2Fmt-arc4random/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencoff%2Fmt-arc4random/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opencoff","download_url":"https://codeload.github.com/opencoff/mt-arc4random/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241072712,"owners_count":19904828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-12-14T04:19:34.342Z","updated_at":"2025-10-29T08:12:45.723Z","avatar_url":"https://github.com/opencoff.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mt-arc4random\nThis is a thread-Aware, thread-safe version of OpenBSD arc4random (chacha20 based).\nI cleaned it up and made it portable to all POSIX like OSes. It\nbuilds cleanly on OS X, Linux and OpenBSD. In theory, it should just\nwork on any modern Unix.\n\n\n## How is it Thread Aware?\nFirst, I converted every internal function to accept a context\nvariable and prevented them from assuming any global state.\n\nNext, I stashed a per-thread context using the pthread TLS API\n`pthread_getspecific()` and `pthread_setspecific()`.\n\nLastly, I rewrote the publicly visible functions to fetch the\ncontext before calling any internal functions.\n\n## How do you provide entropy (seed) in a portable way?\nThis implementation uses an \"external\" function named\n`getentropy()`. On OpenBSD, this is a syscall. \nI have provided an implementation of `getentropy()` for POSIX systems\nvia `/dev/urandom`.\n\n## Building and Using this\nUsing this is very simple:\n\n* If you are on OpenBSD:\n\n   - Include the supplied `arc4random.h` in every place where you expect\n     to call `arc4random()`. This is *mandatory* - otherwise, you\n     will have a fun time debugging crashes.\n\n   - Add `arc4random.c` to your build.\n\n* If you are any Unix like platform:\n\n    - Add the two files `arc4random.c` and `posix_entropy.c` to your\n      build system.\n\n   - Include the supplied `arc4random.h` in every place where you expect\n     to call `arc4random()`\n\n* Use the well-known APIs - `arc4random()` and\n  `arc4random_buf()` as you always do.\n\n## Testing and Performance\n\nThere's a small benchmark program called `t_arcrand`; to build it\njust run `make`. It should work on any modern Unix. Tested on\nOpenBSD, Linux, OS X Darwin.\n\nWhen run on a retina MacBook Pro 13” (2013) running OS X Yosemite:\n\n    ./t_arc4rand 16 32 64 256 512\n    size,      arc4rand,\tsysrand,\tspeed-up\n        16,   12.2966,\t \t279.9628,\t 22.77\n        32,   11.3687,\t \t268.2029,\t 23.59\n        64,    9.9161,\t \t238.8743,\t 24.09\n       256,    9.3164,\t \t217.1194,\t 23.30\n       512,    8.3054,\t \t204.1270,\t 24.58\n\n\nThe results show the CPU cycles consumed by `arc4random_buf()` to\ngenerate \"n\" bytes of random data. The third column labeled\n`sysrand` is the CPU cycles consumed by reading from `/dev/urandom`.\nAnd the last column is the relative speedup between the two.\n\nOn debian Linux (sid) x86_64 on a Core-i7 Laptop running the\nLinux 4.5 kernel, I see:\n\n    ./t_arc4rand 16 32 64 256 512\n    size,      arc4rand,\tsysrand,\tspeed-up\n        16,    9.6997,\t \t255.6211,\t 26.35\n        32,    7.9821,\t \t251.2072,\t 31.47\n        64,    7.5916,\t \t220.8430,\t 29.09\n       256,    7.4764,\t \t206.5079,\t 27.62\n       512,    7.2225,\t \t201.9913,\t 27.97\n\n\n## RFC 4122 UUID Generation\nThere is a short implementatin of RFC 4122\nRandom number based UUID generation in randuuid.c. This \nuses the underlying `arc4random()` implementation. The\nsignature for that function is simple enough\n`void randuuid(uint8_t* buf, size_t n)`. \n\n### Java bindings \nThe UUID generator has a JNI binding specified in the java/\ndirectory.\n\n## How is it licensed?\nI don't have any special licensing terms; my changes are subject to\nthe original licensing terms in the file `arc4random.c`.\n\n--\nSudhi Herle \u003csudhi@herle.net\u003e\nWed Oct  7 15:07:53 PDT 2015\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencoff%2Fmt-arc4random","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopencoff%2Fmt-arc4random","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencoff%2Fmt-arc4random/lists"}