Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>net.openhft</groupId>
<artifactId>java-parent-pom</artifactId>
<version>1.25.4</version>
<relativePath />
<relativePath/>
</parent>

<artifactId>chronicle-salt</artifactId>
Expand Down Expand Up @@ -107,8 +108,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

Expand Down
27 changes: 10 additions & 17 deletions src/test/java/net/openhft/chronicle/salt/BatchSha256Rc4Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,27 @@
import net.openhft.chronicle.bytes.BytesUtil;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.wire.TextWire;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeFalse;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*;

@RunWith(Parameterized.class)
public class BatchSha256Rc4Test {
private static final ThreadLocal<Bytes<?>> hash256Bytes = ThreadLocal.withInitial(() -> Bytes.allocateDirect(SHA2.HASH_SHA256_BYTES));
static BytesForTesting bft = new BytesForTesting();
static int testCounter = 0;
static long timePassed = 0;
private static Bytes<?> testDataBytes;
@Parameter(0) public String name;
@Parameter(1) public long size;
@Parameter(2) public String sha256;

@SuppressWarnings("unchecked")
@Parameters(name = "{0}")
public static Collection<Object[]> data() throws IOException {
String paramFile = "test-vectors/sha256-shadd256.yaml";
ArrayList<Object[]> params = new ArrayList<>();
Expand All @@ -74,21 +66,22 @@ public static Collection<Object[]> data() throws IOException {
return params;
}

@AfterClass
@AfterAll
public static void after() {
bft.cleanup();
}

public static Bytes<?> generateRc4(long len) {
int[] key = new int[] { 0 };
int[] key = new int[]{0};
Rc4Cipher cipher = new Rc4Cipher(key);
Bytes<?> bytes = Bytes.allocateDirect(len);
cipher.prga(bytes, len);
return bytes;
}

@Test
public void testHash() {
@ParameterizedTest(name = "{0}")
@MethodSource("data")
public void testHash(String name, long size, String sha256) {
assumeFalse(OS.isWindows());

if ((testCounter % 250) == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,27 @@
import net.openhft.chronicle.bytes.BytesUtil;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.wire.TextWire;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeFalse;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*;

@RunWith(Parameterized.class)
public class BatchSha256Sha512RandomTest {
private static final ThreadLocal<Bytes<?>> hash256Bytes = ThreadLocal.withInitial(() -> Bytes.allocateDirect(SHA2.HASH_SHA256_BYTES));
private static final ThreadLocal<Bytes<?>> hash512Bytes = ThreadLocal.withInitial(() -> Bytes.allocateDirect(SHA2.HASH_SHA512_BYTES));
static BytesForTesting bft = new BytesForTesting();
@Parameter(0) public String data;
@Parameter(1) public int size;
@Parameter(2) public String sha256;
@Parameter(3) public String sha512;

@SuppressWarnings("unchecked")
@Parameters(name = "{1}")
public static Collection<Object[]> data() throws IOException {
String[] paramInput = { "test-vectors/random-sha256_sha512.yaml" };
String[] paramInput = {"test-vectors/random-sha256_sha512.yaml"};
ArrayList<Object[]> params = new ArrayList<>();
for (String paramFile : paramInput) {
Bytes<?> bytes = BytesUtil.readFile(paramFile);
Expand All @@ -70,13 +61,14 @@ public static Collection<Object[]> data() throws IOException {
return params;
}

@AfterClass
@AfterAll
public static void after() {
bft.cleanup();
}

@Test
public void testHash() {
@ParameterizedTest(name = "{1}")
@MethodSource("data")
public void testHash(String data, int size, String sha256, String sha512) {
assumeFalse(OS.isWindows());

Bytes<?> bytesMessage = bft.fromHex(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
import net.openhft.chronicle.bytes.BytesUtil;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.wire.TextWire;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import javax.xml.bind.DatatypeConverter;
import java.io.IOException;
Expand All @@ -36,24 +33,16 @@
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*;

@RunWith(Parameterized.class)
@SuppressWarnings("rawtypes")
public class BatchSignAndVerifyEd25519Test {
static final BytesForTesting bft = new BytesForTesting();
@Parameter(0) public String privateOrSecretKey;
@Parameter(1) public String publicKey;
@Parameter(2) public String message;
@Parameter(3) public String signExpected;
@Parameter(4) public String testName;

@SuppressWarnings("unchecked")
@Parameters(name = "{4}")
public static Collection<Object[]> data() throws IOException {
String[] paramInput = { "test-vectors/ed25519-rfc-8032.yaml", "test-vectors/ed25519-python.yaml" };
String[] paramInput = {"test-vectors/ed25519-rfc-8032.yaml", "test-vectors/ed25519-python.yaml"};
ArrayList<Object[]> params = new ArrayList<>();
for (String paramFile : paramInput) {
TextWire textWire = new TextWire(BytesUtil.readFile(paramFile)).useTextDocuments();
Expand All @@ -71,13 +60,14 @@ public static Collection<Object[]> data() throws IOException {
return params;
}

@AfterClass
@AfterAll
public static void teardownClass() {
bft.cleanup();
}

@Test
public void signAndVerify() {
@ParameterizedTest(name = "{4}")
@MethodSource("data")
public void signAndVerify(String privateOrSecretKey, String publicKey, String message, String signExpected, String testName) {
assumeFalse(OS.isWindows());

Bytes<?> privateKeyBuffer = null;
Expand Down Expand Up @@ -112,8 +102,9 @@ public void signAndVerify() {
assertTrue(Ed25519.verify(signedMsgBuffer, publicKeyBuffer));
}

@Test
public void signAndVerifyDetached() {
@ParameterizedTest(name = "{4}")
@MethodSource("data")
public void signAndVerifyDetached(String privateOrSecretKey, String publicKey, String message, String signExpected, String testName) {
assumeFalse(OS.isWindows());

Bytes<?> privateKeyBuffer = null;
Expand Down Expand Up @@ -141,4 +132,4 @@ public void signAndVerifyDetached() {
publicKeyBuffer.readPositionRemaining(0, Ed25519.PUBLIC_KEY_LENGTH);
assertTrue(Ed25519.verify(messageBuffer, length, 0, length, publicKeyBuffer));
}
}
}
34 changes: 17 additions & 17 deletions src/test/java/net/openhft/chronicle/salt/Blake2bTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
import net.openhft.chronicle.bytes.BytesStore;
import net.openhft.chronicle.bytes.internal.NativeBytesStore;
import net.openhft.chronicle.core.OS;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import javax.xml.bind.DatatypeConverter;

import static net.openhft.chronicle.salt.TestUtil.nativeBytesStore;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeFalse;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*;

public class Blake2bTest {
@Before
@BeforeEach
public void before() {
assumeFalse(OS.isWindows());
}
Expand Down Expand Up @@ -96,20 +96,20 @@ public void testMultiPart256() {
Blake2b.MultiPart256 multi = new Blake2b.MultiPart256();
assertMultiPart256(multi, "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8", NativeBytesStore.from(new byte[0]));

assertMultiPart256(multi, "03170A2E7597B7B7E3D84C05391D139A62B157E78786D8C082F29DCF4C111314", NativeBytesStore.from(new byte[] { 0 }));
assertMultiPart256(multi, "03170A2E7597B7B7E3D84C05391D139A62B157E78786D8C082F29DCF4C111314", NativeBytesStore.from(new byte[]{0}));

assertMultiPart256(multi, "117AD6B940F5E8292C007D9C7E7350CD33CF85B5887E8DA71C7957830F536E7C", nativeBytesStore("abcdefgh"),
nativeBytesStore("ijklmnop"), nativeBytesStore("qrstuvwxyz"));

// hypercore leaf batch example
assertMultiPart256(multi, "CCFA4259EE7C41E411E5770973A49C5CEFFB5272D6A37F2C6F2DAC2190F7E2B7", NativeBytesStore.from(new byte[] { 0 }), // leafy
// type
NativeBytesStore.from(new byte[] { 0, 0, 0, 0, 0, 0, 0, 11 }), // message length
assertMultiPart256(multi, "CCFA4259EE7C41E411E5770973A49C5CEFFB5272D6A37F2C6F2DAC2190F7E2B7", NativeBytesStore.from(new byte[]{0}), // leafy
// type
NativeBytesStore.from(new byte[]{0, 0, 0, 0, 0, 0, 0, 11}), // message length
nativeBytesStore("hello world")); // message

assertMultiPart256(multi, "BAB07BD8DB18F6431170DF84DCFED749D7FA9EAC9E2C6BFE346F26453A65EAFC", NativeBytesStore.from(new byte[] { 0 }), // leafy
// type
NativeBytesStore.from(new byte[] { 0, 0, 0, 0, 0, 0, 0, 11 }), // message length
assertMultiPart256(multi, "BAB07BD8DB18F6431170DF84DCFED749D7FA9EAC9E2C6BFE346F26453A65EAFC", NativeBytesStore.from(new byte[]{0}), // leafy
// type
NativeBytesStore.from(new byte[]{0, 0, 0, 0, 0, 0, 0, 11}), // message length
nativeBytesStore("world hello")); // message
}

Expand Down Expand Up @@ -154,7 +154,7 @@ public void testMultiPart512() {

assertMultiPart512(multi,
"2FA3F686DF876995167E7C2E5D74C4C7B6E48F8068FE0E44208344D480F7904C36963E44115FE3EB2A3AC8694C28BCB4F5A0F3276F2E79487D8219057A506E4B",
NativeBytesStore.from(new byte[] { 0 }));
NativeBytesStore.from(new byte[]{0}));

assertMultiPart512(multi,
"C68EDE143E416EB7B4AAAE0D8E48E55DD529EAFED10B1DF1A61416953A2B0A5666C761E7D412E6709E31FFE221B7A7A73908CB95A4D120B8B090A87D1FBEDB4C",
Expand All @@ -163,14 +163,14 @@ public void testMultiPart512() {
// hypercore leaf batch example
assertMultiPart512(multi,
"E623E28724C7815EB82FAE2F32A186EB6B70C3DA63B721D7B16094EB0DE6FF29969079BAC8F7DEA85CFCB24226775BAAEC2FE27F09B55BA477FEED41DEE36712",
NativeBytesStore.from(new byte[] { 0 }), // leafy type
NativeBytesStore.from(new byte[] { 0, 0, 0, 0, 0, 0, 0, 11 }), // message length
NativeBytesStore.from(new byte[]{0}), // leafy type
NativeBytesStore.from(new byte[]{0, 0, 0, 0, 0, 0, 0, 11}), // message length
nativeBytesStore("hello world")); // message

assertMultiPart512(multi,
"0B0595CB66B3E920FFF80F33441FF7A2CE3E269B7B4DCBF24065B87AEA43B31D5763EFD62E512F416D931C6904C852D403F23738DD33F72062EA209FA0265A49",
NativeBytesStore.from(new byte[] { 0 }), // leafy type
NativeBytesStore.from(new byte[] { 0, 0, 0, 0, 0, 0, 0, 11 }), // message length
NativeBytesStore.from(new byte[]{0}), // leafy type
NativeBytesStore.from(new byte[]{0, 0, 0, 0, 0, 0, 0, 11}), // message length
nativeBytesStore("world hello")); // message
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import java.util.ArrayList;
import java.util.List;

import static junit.framework.TestCase.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

@SuppressWarnings("rawtypes")
public class BytesForTesting {
Expand Down
Loading