public CombineOutput combine ( final List < ShareInfo > usetheseshares ) { CombineOutput ret = null ; sanityCheckPublicInfos ( publicInfo , usetheseshares ) ; if ( true ) { println ( " SOLVING USING THESE SHARES, mod=" + publicInfo . getPrimeModulus ( ) ) ; for ( ShareInfo si : usetheseshares ) { println ( " " + si . share ) ; } println ( "end SOLVING USING THESE SHARES" ) ; } if ( publicInfo . getK ( ) > usetheseshares . size ( ) ) { throw new SecretShareException ( "Must have " + publicInfo . getK ( ) + " shares to solve. Only provided " + usetheseshares . size ( ) ) ; } checkForDuplicatesOrThrow ( usetheseshares ) ; final int size = publicInfo . getK ( ) ; BigInteger [ ] xarray = new BigInteger [ size ] ; BigInteger [ ] fofxarray = new BigInteger [ size ] ; for ( int i = 0 , n = size ; i < n ; i ++ ) { xarray [ i ] = usetheseshares . get ( i ) . getXasBigInteger ( ) ; fofxarray [ i ] = usetheseshares . get ( i ) . getShare ( ) ; } EasyLinearEquation ele = EasyLinearEquation . createForPolynomial ( xarray , fofxarray ) ; if ( publicInfo . getPrimeModulus ( ) != null ) { ele = ele . createWithPrimeModulus ( publicInfo . getPrimeModulus ( ) ) ; } BigInteger solveSecret = null ; if ( false ) { EasyLinearEquation . EasySolve solve = ele . solve ( ) ; solveSecret = solve . getAnswer ( 1 ) ; } else { BigInteger [ ] [ ] matrix = ele . getMatrix ( ) ; NumberMatrix . print ( "SS.java" , matrix , out ) ; println ( "CVT matrix.height=" + matrix . length + " width=" + matrix [ 0 ] . length ) ; BigRationalMatrix brm = BigRationalMatrix . create ( matrix ) ; NumberMatrix . print ( "SS.java brm" , brm . getArray ( ) , out ) ; NumberSimplex < BigRational > simplex = new NumberSimplex < BigRational > ( brm , 0 ) ; simplex . initForSolve ( out ) ; simplex . solve ( out ) ; BigRational answer = simplex . getAnswer ( 0 ) ; if ( publicInfo . getPrimeModulus ( ) != null ) { solveSecret = answer . computeBigIntegerMod ( publicInfo . getPrimeModulus ( ) ) ; } else { solveSecret = answer . bigIntegerValue ( ) ; } } if ( publicInfo . getPrimeModulus ( ) != null ) { solveSecret = solveSecret . mod ( publicInfo . getPrimeModulus ( ) ) ; } ret = new CombineOutput ( solveSecret ) ; return ret ; }
Combine the shares generated by the split to recover the secret .