package at.archistar.crypto.secretsharing;

import at.archistar.crypto.data.Share;
import at.archistar.crypto.decode.DecoderFactory;
import at.archistar.crypto.decode.ErasureDecoderFactory;
import at.archistar.crypto.math.GF;
import at.archistar.crypto.math.GFFactory;
import at.archistar.crypto.math.gf256.GF256Factory;
import at.archistar.crypto.random.FakeRandomSource;
import at.archistar.crypto.symmetric.AESEncryptor;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

import static org.fest.assertions.api.Assertions.assertThat;

/**
 * Test for {@link KrawczykCSS}
 */
public class TestKrawczykCSS extends BasicSecretSharingTest {

    public TestKrawczykCSS() {
        super(8, 5);
    }

    /* setup and tear-down */
    @Before
    public void setup() throws WeakSecurityException {

        GFFactory gffactory = new GF256Factory();
        DecoderFactory df = new ErasureDecoderFactory(gffactory);
        GF gf = gffactory.createHelper();

        algorithm = new KrawczykCSS(n, k, new FakeRandomSource(), new AESEncryptor(), df, gf);
    }

    @Test
    public void it_produces_shares_of_the_right_size() throws IOException {
        final Share[] shares = algorithm.share(data);
        final int new_length = data.length % k == 0 ? data.length / k : (data.length / k) + 1;
        for (Share s : shares) {
            assertThat(s.getYValues().length).isEqualTo(new_length);
        }
    }
}

@@ -417,16 +417,72 @@
 ryptor;%0A
+import at.archistar.crypto.symmetric.ChaCha20Encryptor;%0A
 import o
@@ -494,24 +494,24 @@
 nit.Before;%0A
-
 import org.j
@@ -1196,16 +1196,29 @@
 ght_size
+_block_cipher
 () throw
@@ -1233,16 +1233,746 @@
 ption %7B%0A
+        final Share%5B%5D shares = algorithm.share(data);%0A        final int new_data_length = ((data.length / 16) + 1) * 16;%0A        final int new_length = new_data_length %25 k == 0 ? new_data_length / k : (new_data_length / k) + 1;%0A        for (Share s : shares) %7B%0A            assertThat(s.getYValues().length).isEqualTo(new_length);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void it_produces_shares_of_the_right_size_stream_cipher() throws IOException, WeakSecurityException %7B%0A        GFFactory gfFactory = new GF256Factory();%0A        DecoderFactory df = new ErasureDecoderFactory(gfFactory);%0A        GF gf = gfFactory.createHelper();%0A%0A        algorithm = new KrawczykCSS(n, k, new FakeRandomSource(), new ChaCha20Encryptor(), df, gf);%0A%0A
         

fix test to correctly calculate size of shares (and add another test) once again that thing with the block ciphers; added a test using a ChaCha20 stream cipher