Function shamirsecretsharing::hazmat::combine_keyshares [] [src]

pub fn combine_keyshares(keyshares: &[Vec<u8>]) -> Result<Vec<u8>, SSSError>

Combine a set of key shares and return the original key

keyshares must be a slice of keyshare vectors.

The return type will be a Result which will only be Err(err) of the input key shares were malformed. When the input key shares are of the correct length, this function will always return Ok(_).

Restoring the secret will fail in the same cases as with combine_shares:

  1. More shares were needed to reach the treshold.
  2. Shares of different sets (corresponding to different keys) were supplied or some of the keyshares were tampered with.

Opposed to combine_shares, this function will always return a restored key buffer. This restored key MAY be correct. The function just performs the cryptographic calculation, but does not know if restoration succeeded. However, treat all output from this function as secret. Even if combining the key shares failed, the returned buffer can tell an attacker information of the shares that were used to make it. The best way to secure this is by using a cryptographic integrity check to secure the integrity of the key.

Example

use shamirsecretsharing::hazmat::*;

// When `keyshares` contains a set of valid shares for `key`
let restored = combine_keyshares(&keyshares).unwrap();
assert_eq!(restored, key);

// When `keyshares` contains an invalid set of key shares
let restored = combine_keyshares(&keyshares).unwrap();
assert_ne!(restored, key);