Bouncy Castle Cryptography Library 1.86

org.bouncycastle.crypto.threshold.test
Class ShamirSecretSplitterTest

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.bouncycastle.crypto.threshold.test.ShamirSecretSplitterTest
All Implemented Interfaces:
junit.framework.Test

public class ShamirSecretSplitterTest
extends junit.framework.TestCase


Field Summary
static byte[][] TV011D_TV1_1_2_SPLITS
           
static byte[] TV011D_TV1_SECRET
           
static byte[][] TV011D_TV1_SPLITS
           
static byte[][] TV011D_TV1_SR
           
static byte[][] TV011D_TV2_1_2_SPLITS
           
static byte[][] TV011D_TV2_1_4_SPLITS
           
static byte[][] TV011D_TV2_3_4_SPLITS
           
static byte[] TV011D_TV2_SECRET
           
static byte[][] TV011D_TV2_SPLITS
           
static byte[][] TV011D_TV2_SR
           
static byte[][] TV011D_TV3_1_2_3_SPLITS
           
static byte[][] TV011D_TV3_1_2_4_SPLITS
           
static byte[][] TV011D_TV3_1_3_4_SPLITS
           
static byte[] TV011D_TV3_SECRET
           
static byte[][] TV011D_TV3_SPLITS
           
static byte[][] TV011D_TV3_SR
           
static byte[][] TV011D_TV4_1_2_3_4_SPLITS
           
static byte[] TV011D_TV4_SECRET
           
static byte[][] TV011D_TV4_SPLITS
           
static byte[][] TV011D_TV4_SR
           
static byte[][] TV011D_TV5_1_2_SPLITS
           
static byte[][] TV011D_TV5_8_9_SPLITS
           
static byte[] TV011D_TV5_SECRET
           
static byte[][] TV011D_TV5_SPLITS
           
static byte[][] TV011D_TV5_SR
           
 
Constructor Summary
ShamirSecretSplitterTest()
           
 
Method Summary
static void main(java.lang.String[] args)
           
 void performTest()
           
 void testLargeShareSetRecovery()
          Recovery has to work for any share count the splitter will produce. getSecret counted the Lagrange products into a byte, so from 130 shares up the index wrapped negative and threw an ArrayIndexOutOfBoundsException.
 void testMultipleDivideRejectFieldZero()
          divide() and multiple() rewrite every share in place, so a zero divisor or multiplier would silently overwrite the whole set with zeroes and irreversibly destroy the secret. gfMul reduces its operand modulo 256, so the field's zero element is any value with (v & 0xFF) == 0 - not just an exact 0 - and both methods reject it up front.
 void testPolynomial()
           
 void testPolynomialModeEquivalence()
          The mode-free getInstance and both deprecated Mode values have to be interchangeable, since all three now run the same GF(256) arithmetic.
 void testRecombine(ShamirSplitSecret splitSecret, byte[] secret)
           
 void testRecoveryRejectsEmptyShareSet()
          Nothing can be recovered from no shares at all. getSecret used to size its Lagrange product array at one less than the share count, so an empty set threw a NegativeArraySizeException.
 void testResplitRejectsWrongLengthSecret()
          resplit sizes its coefficient rows by l but took the replacement secret at whatever length it came in at, so a short secret silently produced shares shorter than l and a long one threw an ArrayIndexOutOfBoundsException.
 void testShamirSecretMultipleDivide()
           
 void testShamirSecretResplit()
           
 void testShamirSecretSplitter()
           
 void testShamirSecretSplitterSplitAround()
           
 void testShareCountIndependentOfSecretLength()
          The generated share array is sized by the requested number of shares n, not by the length l of the secret.
 void testSplitAroundRejectsWrongLengthShare()
          splitAround folds the supplied share over the secret length l, so a share of any other length used to fail with an ArrayIndexOutOfBoundsException (short), or be carried into the result at its own length while every other share was l bytes (long).
 void testSplitAroundThresholdOfOne()
          A threshold of one is a degenerate but legal split - every share is the secret. splitAround read the second coefficient row unconditionally, so it threw an ArrayIndexOutOfBoundsException before producing any share.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TV011D_TV1_SR

public static final byte[][] TV011D_TV1_SR

TV011D_TV1_SPLITS

public static final byte[][] TV011D_TV1_SPLITS

TV011D_TV1_1_2_SPLITS

public static final byte[][] TV011D_TV1_1_2_SPLITS

TV011D_TV1_SECRET

public static final byte[] TV011D_TV1_SECRET

TV011D_TV2_SR

public static final byte[][] TV011D_TV2_SR

TV011D_TV2_SPLITS

public static final byte[][] TV011D_TV2_SPLITS

TV011D_TV2_1_2_SPLITS

public static final byte[][] TV011D_TV2_1_2_SPLITS

TV011D_TV2_1_4_SPLITS

public static final byte[][] TV011D_TV2_1_4_SPLITS

TV011D_TV2_3_4_SPLITS

public static final byte[][] TV011D_TV2_3_4_SPLITS

TV011D_TV2_SECRET

public static final byte[] TV011D_TV2_SECRET

TV011D_TV3_SR

public static final byte[][] TV011D_TV3_SR

TV011D_TV3_SPLITS

public static final byte[][] TV011D_TV3_SPLITS

TV011D_TV3_1_2_3_SPLITS

public static final byte[][] TV011D_TV3_1_2_3_SPLITS

TV011D_TV3_1_2_4_SPLITS

public static final byte[][] TV011D_TV3_1_2_4_SPLITS

TV011D_TV3_1_3_4_SPLITS

public static final byte[][] TV011D_TV3_1_3_4_SPLITS

TV011D_TV3_SECRET

public static final byte[] TV011D_TV3_SECRET

TV011D_TV4_SR

public static final byte[][] TV011D_TV4_SR

TV011D_TV4_SPLITS

public static final byte[][] TV011D_TV4_SPLITS

TV011D_TV4_1_2_3_4_SPLITS

public static final byte[][] TV011D_TV4_1_2_3_4_SPLITS

TV011D_TV4_SECRET

public static final byte[] TV011D_TV4_SECRET

TV011D_TV5_SR

public static final byte[][] TV011D_TV5_SR

TV011D_TV5_SPLITS

public static final byte[][] TV011D_TV5_SPLITS

TV011D_TV5_1_2_SPLITS

public static final byte[][] TV011D_TV5_1_2_SPLITS

TV011D_TV5_8_9_SPLITS

public static final byte[][] TV011D_TV5_8_9_SPLITS

TV011D_TV5_SECRET

public static final byte[] TV011D_TV5_SECRET
Constructor Detail

ShamirSecretSplitterTest

public ShamirSecretSplitterTest()
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException

performTest

public void performTest()
                 throws java.io.IOException
Throws:
java.io.IOException

testResplitRejectsWrongLengthSecret

public void testResplitRejectsWrongLengthSecret()
                                         throws java.io.IOException
resplit sizes its coefficient rows by l but took the replacement secret at whatever length it came in at, so a short secret silently produced shares shorter than l and a long one threw an ArrayIndexOutOfBoundsException. Both are now rejected, as splitAround already rejected a wrong-length share.

Throws:
java.io.IOException

testRecoveryRejectsEmptyShareSet

public void testRecoveryRejectsEmptyShareSet()
                                      throws java.io.IOException
Nothing can be recovered from no shares at all. getSecret used to size its Lagrange product array at one less than the share count, so an empty set threw a NegativeArraySizeException.

Throws:
java.io.IOException

testLargeShareSetRecovery

public void testLargeShareSetRecovery()
                               throws java.io.IOException
Recovery has to work for any share count the splitter will produce. getSecret counted the Lagrange products into a byte, so from 130 shares up the index wrapped negative and threw an ArrayIndexOutOfBoundsException.

Throws:
java.io.IOException

testSplitAroundThresholdOfOne

public void testSplitAroundThresholdOfOne()
                                   throws java.io.IOException
A threshold of one is a degenerate but legal split - every share is the secret. splitAround read the second coefficient row unconditionally, so it threw an ArrayIndexOutOfBoundsException before producing any share.

Throws:
java.io.IOException

testSplitAroundRejectsWrongLengthShare

public void testSplitAroundRejectsWrongLengthShare()
                                            throws java.io.IOException
splitAround folds the supplied share over the secret length l, so a share of any other length used to fail with an ArrayIndexOutOfBoundsException (short), or be carried into the result at its own length while every other share was l bytes (long).

Throws:
java.io.IOException

testShareCountIndependentOfSecretLength

public void testShareCountIndependentOfSecretLength()
                                             throws java.io.IOException
The generated share array is sized by the requested number of shares n, not by the length l of the secret. Prior to this being fixed n < l left trailing nulls in the array (so recovery threw a NullPointerException) and n > l overflowed it, which meant only n == l worked.

Throws:
java.io.IOException

testPolynomialModeEquivalence

public void testPolynomialModeEquivalence()
                                   throws java.io.IOException
The mode-free getInstance and both deprecated Mode values have to be interchangeable, since all three now run the same GF(256) arithmetic. Recombining through each of them must give the same secret, and all three must reject a zero divisor rather than wiping the share set.

Throws:
java.io.IOException

testShamirSecretResplit

public void testShamirSecretResplit()
                             throws java.io.IOException
Throws:
java.io.IOException

testShamirSecretMultipleDivide

public void testShamirSecretMultipleDivide()
                                    throws java.io.IOException
Throws:
java.io.IOException

testMultipleDivideRejectFieldZero

public void testMultipleDivideRejectFieldZero()
                                       throws java.io.IOException
divide() and multiple() rewrite every share in place, so a zero divisor or multiplier would silently overwrite the whole set with zeroes and irreversibly destroy the secret. gfMul reduces its operand modulo 256, so the field's zero element is any value with (v & 0xFF) == 0 - not just an exact 0 - and both methods reject it up front. An in-range re-scale must still be accepted.

Throws:
java.io.IOException

testShamirSecretSplitterSplitAround

public void testShamirSecretSplitterSplitAround()
                                         throws java.io.IOException
Throws:
java.io.IOException

testShamirSecretSplitter

public void testShamirSecretSplitter()
                              throws java.io.IOException
Throws:
java.io.IOException

testPolynomial

public void testPolynomial()
                    throws java.io.IOException
Throws:
java.io.IOException

testRecombine

public void testRecombine(ShamirSplitSecret splitSecret,
                          byte[] secret)
                   throws java.io.IOException
Throws:
java.io.IOException

Bouncy Castle Cryptography Library 1.86