Skip to main content

GitHub license PyPI pyversions PyPI version GitHub release GitHub version Updates Build Status

SecretShare

A simple library implementing Adi Shamir's "How to share a secret" algorithm. It is currently very limited since it uses integer arithmetic with primes, thus limiting the size of the shared secret to 512 bits (64 bytes). It is however very useful for cryptographic applications (which is the intended goal).

Requirements

Installation

Clone the repo an run make package-install or, for development purposes, make devenvironment. Install dependencies with pipenv install or pip install -r requirements.txt.

Usage

from secretshare import SecretShare, Secret, Share


def email(recipient, body):
    print(f'Recipient: {recipient} - Body: {body}')


# Generate a new secret
secret = Secret()
# Or use an existing one
secret.value = b'...'
# Or directly: secret = Secret(b'...')
# If your secret is not a byte stream, you can use the methods
# from_int
# from_base64
# from_hex

# Share the secret
share_count = 5  # How many pieces will be secret be split into?
threshold = 3    # How many pieces are required to recover the secret?
shamir = SecretShare(threshold, share_count, secret=secret)
shares = shamir.split()

# Now deliver the shares to each recipient
recipients = ('r1@email.com', 'r2@email.com', 'r3@email.com', 'r4@email.com',
              'r5@email.com')
for i, share in enumerate(shares):
    email(recipients[i], str(share))  # Send in base64
# A Share can be converted to several convenient formats:
# int(share)
# bytes(share)
# str(share)
# hexlify(bytes(share))
# Note: a Secret can be converted the very same way

# ...

# To recover the secret, get the share from each holder 
s1 = Share()
s1.from_int(1100362525301)
# A Share has a point and a value
s2 = Share(2, b'l\xa1J\xd7')
s3 = Share()
# They are both encoded together for convenience
s3.from_base64('BAD2lPfs')
# The share count and threshold information is NOT saved anywhere
# so the developer must save it somewhere as it is public
# information and there's no risk in storing it.
shamir = SecretShare(share_count, threshold, shares=[s1, s2, s3])
secret = shamir.combine()
print(bytes(secret))  # b'...'
# If the wrong number of shares is provided, an incorrect result
# is obtained.
# This is because this algorithm can't validate the result.
# The developer should verify the secret obtained by comparing into
# a hash, preferably using a secure KDF such as Argon2.
# Alternatively, it might be more convenient to verify each share
# against a hash: if the provided shares are correct, the result
# will be correct.

Developing

Install the development requirements, run tests with make test and lint with make lint. Check for tests coverage with make coverage (currently 100%).

License

SecretShare is made by HacKan under GNU GPL v3.0+. You are free to use, share, modify and share modifications under the terms of that license.

Copyright (C) 2018 HacKan (https://hackan.net)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Metadata

Release files for secretshare 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for secretshare 0.5.0
File Size Uploaded Provenance Actions
secretshare-0.5.0.tar.gz 22.6 kB Without provenance Details for secretshare-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for secretshare 0.5.0
File Interpreter ABI Platform Actions
secretshare-0.5.0-py3-none-any.whl Python 3 none any Details for secretshare-0.5.0-py3-none-any.whl

Total release size: 45.5 kB

Release files / secretshare-0.5.0.tar.gz

Download URL secretshare-0.5.0.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fd4d51fd775178e1b74fa684c82567aed7a1c5f9f7b09e30242453b07f97d82c
BLAKE2b-256 checksum
How to use checksums
34d67d6c7122b581dcf0480c72c82341188a1d5c569aef4ac52969aed9fc1add
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release files / secretshare-0.5.0-py3-none-any.whl

Download URL secretshare-0.5.0-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
936e77d38048d2ef46e8422ffd4ddd9bccf02e2dac9925822a79526662bcd7db
BLAKE2b-256 checksum
How to use checksums
80566746e244a85795794adce34ee44d55419aeedf72d7727252ddb2f58981f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Security for secretshare 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page