Package nxt.crypto

Class SecretSharingGenerator

java.lang.Object
nxt.crypto.SecretSharingGenerator

public class SecretSharingGenerator extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    combine(String[] encodedSecretPhrasePieces)
    Given minPieces pieces out of totalPieces of a secretPhrase, combine the pieces into the original phrase.* Pieces are formatted as [version]:[split id]:[total pieces]:[minimum pieces]:[prime field size or zero]:[piece number]:[piece content]
    static byte[]
    combinePrivateKey(String[] encodedSecretPhrasePieces)
    Given minPieces pieces out of totalPieces of a privateKey, combine the pieces into the original.
    static BigInteger
    getModPrime(byte[] privateKey)
    Given a private key calculate the modulo prime finite field size which is sufficiently large to split the key.
    static BigInteger
    getModPrime(String secretPhrase)
    Given a secret phrase calculate the modulo prime finite field size which is sufficiently large to split the shared secrets.
    static boolean
    isPrivateKeySecret(String[] encodedSecretPhrasePieces)
     
    static String[]
    split(byte[] privateKey, int totalPieces, int minPieces, BigInteger declaredModePrime)
    Given a secret byte array split it into totalPieces pieces where each minPieces of them are enough to reproduce the secret.
    static String[]
    split(String secretPhrase, int totalPieces, int minPieces, BigInteger declaredModePrime)
    Given a secretPhrase split it into totalPieces pieces where each minPieces of them are enough to reproduce the secret.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SecretSharingGenerator

      public SecretSharingGenerator()
  • Method Details

    • split

      public static String[] split(String secretPhrase, int totalPieces, int minPieces, BigInteger declaredModePrime)
      Given a secretPhrase split it into totalPieces pieces where each minPieces of them are enough to reproduce the secret. If the secret phrase a is valid BIP39 mnemonic using the english wordlist, it is converted to the corresponding entropy between 128 and 256 bits and a byte to store the number of words on the original mnemonic. If the secret phrase is 12 words from the legacy list, the secret is converted into 128 bit number which is very compact. Otherwise the secret phrase is converted to bytes using UTF8 then to a BigInteger. Every one of these cases is codified into the version integer of the resulting pieces. Pieces are returned with a piece number followed by : and the piece content. The piece number is required when reproducing the secret.
      Parameters:
      secretPhrase - the secret phrase
      totalPieces - the number of generated pieces
      minPieces - the number of pieces needed to reproduce the secret phrase
      declaredModePrime - the modulo prime used for secret sharing calculations. Specify BigInteger.ZERO to calculate automatically
      Returns:
      the secret pieces
    • split

      public static String[] split(byte[] privateKey, int totalPieces, int minPieces, BigInteger declaredModePrime)
      Given a secret byte array split it into totalPieces pieces where each minPieces of them are enough to reproduce the secret. Pieces are returned with a piece number followed by : and the piece content. The piece number is required when reproducing the secret.
      Parameters:
      privateKey - the secret byte array
      totalPieces - the number of generated pieces
      minPieces - the number of pieces needed to reproduce the secret phrase
      declaredModePrime - the modulo prime used for secret sharing calculations. Specify BigInteger.ZERO to calculate automatically
      Returns:
      the secret pieces
    • combinePrivateKey

      public static byte[] combinePrivateKey(String[] encodedSecretPhrasePieces)
      Given minPieces pieces out of totalPieces of a privateKey, combine the pieces into the original. Pieces are formatted as [version]:[split id]:[total pieces]:[minimum pieces]:[prime field size or zero]:[piece number]:[piece content]
      Parameters:
      encodedSecretPhrasePieces - the pieces of the private key formatted as specified above
      Returns:
      the reproduced private key
    • combine

      public static String combine(String[] encodedSecretPhrasePieces)
      Given minPieces pieces out of totalPieces of a secretPhrase, combine the pieces into the original phrase.* Pieces are formatted as [version]:[split id]:[total pieces]:[minimum pieces]:[prime field size or zero]:[piece number]:[piece content]
      Parameters:
      encodedSecretPhrasePieces - the pieces of the secret phrase formatted as specified above
      Returns:
      the reproduced secret phrase
    • isPrivateKeySecret

      public static boolean isPrivateKeySecret(String[] encodedSecretPhrasePieces)
    • getModPrime

      public static BigInteger getModPrime(String secretPhrase)
      Given a secret phrase calculate the modulo prime finite field size which is sufficiently large to split the shared secrets. The specific encoding (version) used is guessed trying to find the best one.
      Parameters:
      secretPhrase - the secret phrase
      Returns:
      the prime number representing the finite field size
    • getModPrime

      public static BigInteger getModPrime(byte[] privateKey)
      Given a private key calculate the modulo prime finite field size which is sufficiently large to split the key.
      Parameters:
      privateKey - the private key
      Returns:
      the prime number representing the finite field size