No project description provided
Project description
shamir
''''''
Fast, secure, pure python implementation of Shamir's secret sharing algorithm.
https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing
why to use it
'''''''''''''
Shamir's secret sharing is useful for providing an "N of M" layer.
For example, password recovery security questions could be cryptographically
imeplemented with this algorithm. Security question answers are
put through a key-derivation-function (KDF) or hash and each one is used to
encrypt a different secret. Then, the answer to any say 5 of 11 security
questions would be enouch to recover the secret.
how to use it
'''''''''''''
.. code-block:: python
secret, shares = make_random_secret(3, 5)
# generate shares such that 3 of 5 can recover the secret
secret = recover_secret(shares)
Shamir's secret sharing algorithm operates on integer X, Y points,
and the secret it stores is a random integer. To be useful, it must be
combined with other algorithms. Here's a high level example:
.. code-block:: python
# encrypt, decrypt, hash, and kdf are external functions
def two_of_three_encrypt(plaintext, pw0, pw1, pw2):
'given a plaintext, secure it so that any 2 may access in the future'
secret, shares = shamir.make_random_shares(2, 3)
def encrypt_share(share, pw):
return encrypt(key=kdf(pw), plaintext=repr(share))
return (
encrypt(key=hash(hex(secret)), plaintext=plaintext)) + tuple(
[encrypt(key=kef(pw), plaintext=repr(share))
for pw, share in zip((pw0, pw1, pw2), shares)])
def two_of_three_decrypt(encrypted, pwA, pwB):
'recover the plaintext given 2 of the 3 passwords used to secure'
ciphertext, shares = encrypted[0], encrypted[1:]
keyA, keyB = kdf(pwA), kdf(pwB)
decrypted_shares = []
for share in shares:
for key in (keyA, keyB):
try:
decrypted_shares.append(
decrypt(key=keyA, ciphertext=share))
except Exception:
pass
if len(decrypted_shares) < 2:
raise ValueError('bad password')
return decrypt(
key=hash(hex(shamir.recover_secret(decrypted_shares))),
ciphertext=ciphertext)
''''''
Fast, secure, pure python implementation of Shamir's secret sharing algorithm.
https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing
why to use it
'''''''''''''
Shamir's secret sharing is useful for providing an "N of M" layer.
For example, password recovery security questions could be cryptographically
imeplemented with this algorithm. Security question answers are
put through a key-derivation-function (KDF) or hash and each one is used to
encrypt a different secret. Then, the answer to any say 5 of 11 security
questions would be enouch to recover the secret.
how to use it
'''''''''''''
.. code-block:: python
secret, shares = make_random_secret(3, 5)
# generate shares such that 3 of 5 can recover the secret
secret = recover_secret(shares)
Shamir's secret sharing algorithm operates on integer X, Y points,
and the secret it stores is a random integer. To be useful, it must be
combined with other algorithms. Here's a high level example:
.. code-block:: python
# encrypt, decrypt, hash, and kdf are external functions
def two_of_three_encrypt(plaintext, pw0, pw1, pw2):
'given a plaintext, secure it so that any 2 may access in the future'
secret, shares = shamir.make_random_shares(2, 3)
def encrypt_share(share, pw):
return encrypt(key=kdf(pw), plaintext=repr(share))
return (
encrypt(key=hash(hex(secret)), plaintext=plaintext)) + tuple(
[encrypt(key=kef(pw), plaintext=repr(share))
for pw, share in zip((pw0, pw1, pw2), shares)])
def two_of_three_decrypt(encrypted, pwA, pwB):
'recover the plaintext given 2 of the 3 passwords used to secure'
ciphertext, shares = encrypted[0], encrypted[1:]
keyA, keyB = kdf(pwA), kdf(pwB)
decrypted_shares = []
for share in shares:
for key in (keyA, keyB):
try:
decrypted_shares.append(
decrypt(key=keyA, ciphertext=share))
except Exception:
pass
if len(decrypted_shares) < 2:
raise ValueError('bad password')
return decrypt(
key=hash(hex(shamir.recover_secret(decrypted_shares))),
ciphertext=ciphertext)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
shamir-17.12.0.tar.gz
(3.4 kB
view details)
Built Distribution
File details
Details for the file shamir-17.12.0.tar.gz
.
File metadata
- Download URL: shamir-17.12.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b355c78c810e75ee9a140b07aeebac66ef2f623fbc77da612a8b20c5697c043 |
|
MD5 | 9811f01f64e303069601fcec1e813cb6 |
|
BLAKE2b-256 | 946509838fa1463f36141b63a914ffcd5d488d90214d7ede609ef6d423c00f01 |
File details
Details for the file shamir-17.12.0-py2.py3-none-any.whl
.
File metadata
- Download URL: shamir-17.12.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0d7433faa914e7ebfe10c96577221b31fe00ae0cce9f391c29cf63855a246c1 |
|
MD5 | 26388ef015bffcf1f96ab69a2d1a4dd4 |
|
BLAKE2b-256 | 5fd48b6dd0cfb3e9a94f5364a2b857dd4467f063b7d7273a0f8b32d251694dd1 |