{"id":13546162,"url":"https://github.com/snipsco/rust-threshold-secret-sharing","last_synced_at":"2025-07-16T12:44:18.453Z","repository":{"id":57669726,"uuid":"62790774","full_name":"snipsco/rust-threshold-secret-sharing","owner":"snipsco","description":"A pure-Rust implementation of various threshold secret sharing schemes","archived":false,"fork":false,"pushed_at":"2018-10-28T23:17:30.000Z","size":106,"stargazers_count":162,"open_issues_count":5,"forks_count":35,"subscribers_count":37,"default_branch":"master","last_synced_at":"2025-03-05T17:52:02.734Z","etag":null,"topics":["cryptography","rust","secret-sharing","secure-computation"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/snipsco.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}},"created_at":"2016-07-07T08:47:44.000Z","updated_at":"2025-01-21T04:12:50.000Z","dependencies_parsed_at":"2022-09-26T20:40:35.180Z","dependency_job_id":null,"html_url":"https://github.com/snipsco/rust-threshold-secret-sharing","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snipsco%2Frust-threshold-secret-sharing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snipsco%2Frust-threshold-secret-sharing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snipsco%2Frust-threshold-secret-sharing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snipsco%2Frust-threshold-secret-sharing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/snipsco","download_url":"https://codeload.github.com/snipsco/rust-threshold-secret-sharing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246860281,"owners_count":20845637,"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":["cryptography","rust","secret-sharing","secure-computation"],"created_at":"2024-08-01T12:00:32.711Z","updated_at":"2025-04-02T17:32:38.734Z","avatar_url":"https://github.com/snipsco.png","language":"Rust","funding_links":[],"categories":["Cryptography","Software"],"sub_categories":["Frameworks","Primitives"],"readme":"# Threshold Secret Sharing\n\n[![Build Status](https://travis-ci.org/snipsco/rust-threshold-secret-sharing.svg?branch=master)](https://travis-ci.org/snipsco/rust-threshold-secret-sharing)\n[![Latest version](https://img.shields.io/crates/v/threshold-secret-sharing.svg)](https://img.shields.io/crates/v/threshold-secret-sharing.svg)\n[![License: MIT/Apache2](https://img.shields.io/badge/license-MIT%2fApache2-blue.svg)](https://img.shields.io/badge/license-MIT%2fApache2-blue.svg)\n\nEfficient pure-Rust library for [secret sharing](https://en.wikipedia.org/wiki/Secret_sharing), offering efficient share generation and reconstruction for both traditional Shamir sharing and packet sharing. For now, secrets and shares are fixed as prime field elements represented by `i64` values.\n\n\n# Installation\n\n\n## Cargo\n```toml\n[dependencies]\nthreshold-secret-sharing = \"0.2\"\n```\n\n\n## GitHub\n```bash\ngit clone https://github.com/snipsco/rust-threshold-secret-sharing\ncd rust-threshold-secret-sharing\ncargo build --release\n```\n\n\n# Examples\nSeveral examples are included in the `examples/` directory. Run each with `cargo` using e.g.\n```sh\ncargo run --example shamir\n```\nfor the Shamir example below.\n\n\n## Shamir sharing\nUsing the Shamir scheme is relatively straight-forward.\n\nWhen choosing parameters, `threshold` and `share_count` must be chosen to satisfy security requirements, and `prime` must be large enough to correctly encode the value to be shared (and such that `prime \u003e= share_count + 1`).\n\nWhen reconstructing the secret, indices must be explicitly provided to identify the shares; these correspond to the indices the shares had in the vector returned by `share()`.\n\n```rust\nextern crate threshold_secret_sharing as tss;\n\nfn main() {\n  // create instance of the Shamir scheme\n  let ref tss = tss::shamir::ShamirSecretSharing {\n    threshold: 8,           // privacy threshold\n    share_count: 20,        // total number of shares to generate\n    prime: 41               // prime field to use\n  };\n\n  let secret = 5;\n\n  // generate shares for secret\n  let all_shares = tss.share(secret);\n\n  // artificially remove some of the shares\n  let number_of_recovered_shared = 10;\n  assert!(number_of_recovered_shared \u003e= tss.reconstruct_limit());\n  let recovered_indices: Vec\u003cusize\u003e = (0..number_of_recovered_shared).collect();\n  let recovered_shares: \u0026[i64] = \u0026all_shares[0..number_of_recovered_shared];\n\n  // reconstruct using remaining subset of shares\n  let reconstructed_secret = tss.reconstruct(\u0026recovered_indices, recovered_shares);\n  assert_eq!(reconstructed_secret, secret);\n}\n```\n\n\n## Packed sharing\nIf many secrets are to be secret shared, it may be beneficial to use the packed scheme where several secrets are packed into each share. While still very computational efficient, one downside is that the parameters are somewhat restricted.\n\nSpecifically, the parameters are split in *scheme parameters* and *implementation parameters*:\n- the former, like in Shamir sharing, determines the abstract properties of the scheme, yet now also with a `secret_count` specifying how many secrets are to be packed into each share; the reconstruction limit is implicitly defined as `secret_count + threshold + 1`\n- the latter is related to the implementation (currently based on the Fast Fourier Transform) and requires not only a `prime` specifying the field, but also two principal roots of unity within that field, which must be respectively a power of 2 and a power of 3\n\nDue to this increased complexity, providing helper functions for finding suitable parameters are in progress. For now, a few fixed fields are included in the `packed` module as illustrated in the example below:\n\n- `PSS_4_8_3`, `PSS_4_26_3`, `PSS_155_728_100`, `PSS_155_19682_100`\n\nwith format `PSS_T_N_D` for sharing `D` secrets into `N` shares with a threshold of `T`.\n\n```rust\nextern crate threshold_secret_sharing as tss;\n\nfn main() {\n  // use predefined parameters\n  let ref tss = tss::packed::PSS_4_26_3;\n\n  // generate shares for a vector of secrets\n  let secrets = [1, 2, 3];\n  let all_shares = tss.share(\u0026secrets);\n\n  // artificially remove some of the shares; keep only the first 8\n  let indices: Vec\u003cusize\u003e = (0..8).collect();\n  let shares = \u0026all_shares[0..8];\n\n  // reconstruct using remaining subset of shares\n  let recovered_secrets = tss.reconstruct(\u0026indices, shares);\n  assert_eq!(recovered_secrets, vec![1, 2, 3]);\n}\n```\n\n\n## Homomorphic properties\nBoth the Shamir and the packed scheme enjoy certain homomorphic properties: shared secrets can be transformed by manipulating the shares. Both addition and multiplications work, yet notice that the reconstruction limit in the case of multiplication goes up by a factor of two for each application.\n\n```rust\nextern crate threshold_secret_sharing as tss;\n\nfn main() {\n  // use predefined parameters\n  let ref tss = tss::PSS_4_26_3;\n\n  // generate shares for first vector of secrets\n  let secrets_1 = [1, 2, 3];\n  let shares_1 = tss.share(\u0026secrets_1);\n\n  // generate shares for second vector of secrets\n  let secrets_2 = [4, 5, 6];\n  let shares_2 = tss.share(\u0026secrets_2);\n\n  // combine shares pointwise to get shares of the sum of the secrets\n  let shares_sum: Vec\u003ci64\u003e = shares_1.iter().zip(\u0026shares_2)\n    .map(|(a, b)| (a + b) % tss.prime).collect();\n\n  // artificially remove some of the shares; keep only the first 8\n  let indices: Vec\u003cusize\u003e = (0..8).collect();\n  let shares = \u0026shares_sum[0..8];\n\n  // reconstruct using remaining subset of shares\n  let recovered_secrets = tss.reconstruct(\u0026indices, shares);\n  assert_eq!(recovered_secrets, vec![5, 7, 9]);\n}\n```\n\n# Parameter generation\nWhile it's straight-forward to instantiate the Shamir scheme, as mentioned above the packed scheme is more tricky and a few helper methods are provided as a result. Since some applications needs only a fixed choice of parameters, these helper methods are optional and only included if the `paramgen` feature is activated during compilation:\n```\ncargo build --features paramgen\n```\nwhich also adds several extra dependencies.\n\n\n# Performance\nSo far most performance efforts has been focused on share generation for the packed scheme, with some obvious enhancements for reconstruction in the process of being implemented. As an example, sharing 100 secrets into approximately 20,000 shares with the packed scheme runs in around 31ms on a recent laptop, and in around 590ms on a Raspberry Pi 3.\n\nThese numbers were obtained by running\n```\ncargo bench\n```\nusing the nightly toolchain.\n\n# License\n\nLicensed under either of\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnipsco%2Frust-threshold-secret-sharing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnipsco%2Frust-threshold-secret-sharing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnipsco%2Frust-threshold-secret-sharing/lists"}