{"id":17295190,"url":"https://github.com/adam-fowler/big-num","last_synced_at":"2025-04-13T02:12:45.220Z","repository":{"id":39921902,"uuid":"222782795","full_name":"adam-fowler/big-num","owner":"adam-fowler","description":"Swift interface BIGNUM functions in BoringSSL","archived":false,"fork":false,"pushed_at":"2024-04-01T07:25:57.000Z","size":768,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T19:47:54.560Z","etag":null,"topics":["bignum","boringssl","ios","linux","macos","swift"],"latest_commit_sha":null,"homepage":"","language":"Assembly","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adam-fowler.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":"2019-11-19T20:24:16.000Z","updated_at":"2024-05-15T08:04:41.000Z","dependencies_parsed_at":"2024-12-05T01:12:16.820Z","dependency_job_id":"801bb2ca-8895-401c-b9d4-95e521ca9c3a","html_url":"https://github.com/adam-fowler/big-num","commit_stats":{"total_commits":41,"total_committers":1,"mean_commits":41.0,"dds":0.0,"last_synced_commit":"38f673d9ab1b6e2899ebeb9ee45b662e5e771e44"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-fowler%2Fbig-num","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-fowler%2Fbig-num/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-fowler%2Fbig-num/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-fowler%2Fbig-num/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adam-fowler","download_url":"https://codeload.github.com/adam-fowler/big-num/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654094,"owners_count":21140236,"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":["bignum","boringssl","ios","linux","macos","swift"],"created_at":"2024-10-15T11:09:41.005Z","updated_at":"2025-04-13T02:12:45.198Z","avatar_url":"https://github.com/adam-fowler.png","language":"Assembly","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BigNum\n\nBigNum provides a Swift wrapper for the BoringSSL BIGNUM library.\n\nIt provides most of the standard library functions\n- Basic arithmetic operators (with and without modulus)\n- Bitwise operators\n- Powers (with and without modulus)\n- Greatest common denominator\n- Prime generation\n- Random number generation\n\n## Examples\n### Factorial\nBelow is a function that creates factorial 1000 and then verifies that for every number from 1 to 1000 the greatest common denominator between the variable `factorial` and that number is equal to that number.\n```swift\n        var factorial = BigNum(1)\n        for i in 1..\u003c1000 {\n            factorial = factorial * BigNum(i)\n        }\n        for i in 1..\u003c1000 {\n            assert(BigNum.gcd(i, factorial) == i)\n        }\n```\nfyi factorial 1000 is quite a big number\n```\n402387260077093773543702433923003985719374864210714632543799910429938512398629020592044208486969404800479988610197196058631666872994808558901323829669944590997424504087073759918823627727188732519779505950995276120874975462497043601418278094646496291056393887437886487337119181045825783647849977012476632889835955735432513185323958463075557409114262417474349347553428646576611667797396668820291207379143853719588249808126867838374559731746136085379534524221586593201928090878297308431392844403281231558611036976801357304216168747609675871348312025478589320767169132448426236131412508780208000261683151027341827977704784635868170164365024153691398281264810213092761244896359928705114964975419909342221566832572080821333186116811553615836546984046708975602900950537616475847728421889679646244945160765353408198901385442487984959953319101723355556602139450399736280750137837615307127761926849034352625200015888535147331611702103968175921510907788019393178114194545257223865541461062892187960223838971476088506276862967146674697562911234082439208160153780889893964518263243671616762179168909779911903754031274622289988005195444414282012187361745992642956581746628302955570299024324153181617210465832036786906117260158783520751516284225540265170483304226143974286933061690897968482590125458327168226458066526769958652682272807075781391858178889652208164348344825993266043367660176999612831860788386150279465955131156552036093988180612138558600301435694527224206344631797460594682573103790084024432438465657245014402821885252470935190620929023136493273497565513958720559654228749774011413346962715422845862377387538230483865688976461927383814900140767310446640259899490222221765904339901886018566526485061799702356193897017860040811889729918311021171229845901641921068884387121855646124960798722908519296819372388642614839657382291123125024186649353143970137428531926649875337218940694281434118520158014123344828015051399694290153483077644569099073152433278288269864602789864321139083506217095002597389863554277196742822248757586765752344220207573630569498825087968928162753848863396909959826280956121450994871701244516461260379029309120889086942028510640182154399457156805941872748998094254742173582401063677404595741785160829230135358081840096996372524230560855903700624271243416909004153690105933983835777939410970027753472000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n```\n\n### Secure Remote Password\n\nAnother standard operation that BigNum can be used for is generating [Secure Remote Password](https://en.wikipedia.org/wiki/Secure_Remote_Password_protocol) keys. Assuming we have the following \n- Safe prime `N`\n- Generator value `g` (very commonly 2)\n- Random number `a`\n- A hashing function `H`\n- username and password\n\nA value `A` is calculated and sent to the server\n```\nA = g.power(a, modulus: N)\n```\nThe server responds with a large value `B` and a `salt` value. Then the client generates the password authentication key\n```\n// calculate u = H(A,B)\nlet u = BigNum(data: H(A.data, B.data))\n\n// calculate x = H(salt , H(userId | \":\" | password))\nlet message = Data(\"\\(username):\\(password)\".utf8)\nlet x = BigNum(data: H(salt, H(message)))\n\n// calculate k = H(N,g)\nlet k = BigNum(data: H(N.data, g.data))\n\n// calculate S\nlet S = (B - k * g.power(x, modulus: N)).power(a + u * x, modulus: N)\n```\nA hashed version of S can be sent back to the server and the server can use that to verify the correct password was provided.\n\n## Compatibility\n\nBigNum uses a vendored cutdown version of BoringSSL (Google's version of OpenSSL) so doesn't require a separate OpenSSL library. This means it can be run on iOS and on macOS and Linux platforms without requiring a separate library to be installed. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadam-fowler%2Fbig-num","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadam-fowler%2Fbig-num","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadam-fowler%2Fbig-num/lists"}