{"id":15043064,"url":"https://github.com/codahale/shamir","last_synced_at":"2025-10-04T05:31:30.594Z","repository":{"id":57718337,"uuid":"88182582","full_name":"codahale/shamir","owner":"codahale","description":"A Java implementation of Shamir's Secret Sharing algorithm over GF(256).","archived":true,"fork":false,"pushed_at":"2023-11-12T21:21:08.000Z","size":316,"stargazers_count":213,"open_issues_count":6,"forks_count":85,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-07-04T15:19:50.919Z","etag":null,"topics":["cryptography","java","java-8","shamir","shamir-secret-sharing"],"latest_commit_sha":null,"homepage":null,"language":"Java","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/codahale.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-04-13T15:59:23.000Z","updated_at":"2025-06-27T07:45:42.000Z","dependencies_parsed_at":"2024-06-19T01:52:59.192Z","dependency_job_id":null,"html_url":"https://github.com/codahale/shamir","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/codahale/shamir","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codahale%2Fshamir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codahale%2Fshamir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codahale%2Fshamir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codahale%2Fshamir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codahale","download_url":"https://codeload.github.com/codahale/shamir/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codahale%2Fshamir/sbom","scorecard":{"id":295430,"data":{"date":"2025-08-11","repo":{"name":"github.com/codahale/shamir","commit":"f44e1cec1919103ad942252b42dcdf9630461c0a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 1/29 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T19:22:49.074Z","repository_id":57718337,"created_at":"2025-08-17T19:22:49.074Z","updated_at":"2025-08-17T19:22:49.074Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278267472,"owners_count":25958870,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"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":["cryptography","java","java-8","shamir","shamir-secret-sharing"],"created_at":"2024-09-24T20:48:31.331Z","updated_at":"2025-10-04T05:31:30.342Z","avatar_url":"https://github.com/codahale.png","language":"Java","readme":"# Shamir's Secret Sharing\n\n[![CircleCI](https://circleci.com/gh/codahale/shamir.svg?style=svg)](https://circleci.com/gh/codahale/shamir)\n\nA Java implementation of [Shamir's Secret Sharing\nalgorithm](http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing) over GF(256).\n\n## Add to your project\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.codahale\u003c/groupId\u003e\n  \u003cartifactId\u003eshamir\u003c/artifactId\u003e\n  \u003cversion\u003e0.7.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n*Note: module name for Java 9+ is `com.codahale.shamir`.*\n\n## Use the thing\n\n```java\nimport com.codahale.shamir.Scheme;\nimport java.nio.charset.StandardCharsets;\nimport java.security.SecureRandom;\nimport java.util.Map;\n\nclass Example {\n  void doIt() {\n    final Scheme scheme = new Scheme(new SecureRandom(), 5, 3);\n    final byte[] secret = \"hello there\".getBytes(StandardCharsets.UTF_8);\n    final Map\u003cInteger, byte[]\u003e parts = scheme.split(secret);\n    final byte[] recovered = scheme.join(parts);\n    System.out.println(new String(recovered, StandardCharsets.UTF_8));\n  } \n}\n```\n\n## How it works\n\nShamir's Secret Sharing algorithm is a way to split an arbitrary secret `S` into `N` parts, of which\nat least `K` are required to reconstruct `S`. For example, a root password can be split among five\npeople, and if three or more of them combine their parts, they can recover the root password.\n\n### Splitting secrets\n\nSplitting a secret works by encoding the secret as the constant in a random polynomial of `K`\ndegree. For example, if we're splitting the secret number `42` among five people with a threshold of\nthree (`N=5,K=3`), we might end up with the polynomial:\n\n```\nf(x) = 71x^3 - 87x^2 + 18x + 42\n```\n\nTo generate parts, we evaluate this polynomial for values of `x` greater than zero:\n\n```\nf(1) =   44\nf(2) =  298\nf(3) = 1230\nf(4) = 3266\nf(5) = 6822\n```\n\nThese `(x,y)` pairs are then handed out to the five people. \n\n### Joining parts \n\nWhen three or more of them decide to recover the original secret, they pool their parts together:\n\n```\nf(1) =   44\nf(3) = 1230\nf(4) = 3266\n```\n\nUsing these points, they construct a [Lagrange\npolynomial](https://en.wikipedia.org/wiki/Lagrange_polynomial), `g`, and calculate `g(0)`. If the\nnumber of parts is equal to or greater than the degree of the original polynomial (i.e. `K`), then\n`f` and `g` will be exactly the same, and `f(0) = g(0) = 42`, the encoded secret. If the number of\nparts is less than the threshold `K`, the polynomial will be different and `g(0)` will not be `42`.\n\n### Implementation details\n\nShamir's Secret Sharing algorithm only works for finite fields, and this library performs all\noperations in [GF(256)](http://www.cs.utsa.edu/~wagner/laws/FFM.html). Each byte of a secret is\nencoded as a separate `GF(256)` polynomial, and the resulting parts are the aggregated values of\nthose polynomials.\n\nUsing `GF(256)` allows for secrets of arbitrary length and does not require additional parameters,\nunlike `GF(Q)`, which requires a safe modulus. It's also **much** faster than `GF(Q)`: splitting and\ncombining a 1KiB secret into 8 parts with a threshold of 3 takes single-digit milliseconds, whereas\nperforming the same operation over `GF(Q)` takes several seconds, even using per-byte polynomials.\nTreating the secret as a single `y` coordinate over `GF(Q)` is even slower, and requires a modulus\nlarger than the secret.\n\n## Performance\n\nIt's fast. Plenty fast.\n\nFor a 1KiB secret split with a `n=4,k=3` scheme:\n\n```\nBenchmark         (n)  (secretSize)  Mode  Cnt     Score    Error  Units\nBenchmarks.join     4          1024  avgt  200   196.787 ±  0.974  us/op\nBenchmarks.split    4          1024  avgt  200   396.708 ±  1.520  us/op\n```\n\n**N.B.:** `split` is quadratic with respect to the number of shares being combined.\n\n## Tiered sharing\n\nSome usages of secret sharing involve levels of access: e.g. recovering a secret requires two admin\nshares and three user shares. As @ba1ciu discovered, these can be implemented by building a tree of\nshares:\n\n```java\nclass BuildTree {\n  public static void shareTree(String... args) {\n    final byte[] secret = \"this is a secret\".getBytes(StandardCharsets.UTF_8);\n    \n    // tier 1 of the tree\n    final Scheme adminScheme = new Scheme(new SecureRandom(), 5, 2);\n    final Map\u003cInteger, byte[]\u003e admins = adminScheme.split(secret);\n\n    // tier 2 of the tree\n    final Scheme userScheme = Scheme.of(4, 3);\n    final Map\u003cInteger, Map\u003cInteger, byte[]\u003e\u003e admins =\n        users.entrySet()\n            .stream()\n            .collect(Collectors.toMap(Map.Entry::getKey, e -\u003e userScheme.split(e.getValue())));\n    \n    System.out.println(\"Admin shares:\");\n    System.out.printf(\"%d = %s\\n\", 1, Arrays.toString(admins.get(1)));\n    System.out.printf(\"%d = %s\\n\", 2, Arrays.toString(admins.get(2)));\n\n    System.out.println(\"User shares:\");\n    System.out.printf(\"%d = %s\\n\", 1, Arrays.toString(users.get(3).get(1)));\n    System.out.printf(\"%d = %s\\n\", 2, Arrays.toString(users.get(3).get(2)));\n    System.out.printf(\"%d = %s\\n\", 3, Arrays.toString(users.get(3).get(3)));\n    System.out.printf(\"%d = %s\\n\", 4, Arrays.toString(users.get(3).get(4)));\n  }\n}\n```\n\nBy discarding the third admin share and the first two sets of user shares, we have a set of shares\nwhich can be used to recover the original secret as long as either two admins or one admin and three\nusers agree.\n\n## License\n\nCopyright © 2017 Coda Hale\n\nDistributed under the Apache License 2.0.\n","funding_links":[],"categories":["安全"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodahale%2Fshamir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodahale%2Fshamir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodahale%2Fshamir/lists"}