Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.
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
12 changes: 9 additions & 3 deletions src/main/java/com/iota/curl/IotaCurlHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ private static final class CurlState {

private final CurlState curlState = new CurlState();

public static String iotaCurlHash(final String tx, final int len) {
final IotaCurlHash ctx = new IotaCurlHash();
private final int rounds;

public static String iotaCurlHash(final String tx, final int len, int rounds) {
final IotaCurlHash ctx = new IotaCurlHash(rounds);
ctx.doAbsorb(tx.toCharArray(), len);
return ctx.doFinalize();
}

protected IotaCurlHash(int rounds) {
this.rounds = rounds;
}

/**
* Absorb given trytes.
*/
Expand All @@ -51,7 +57,7 @@ protected void doAbsorb(final char [] trytes, final int len) {
protected void doHashTransform(int [] state1) {
int [] state2 = Arrays.copyOf(state1, state1.length);

for(int r=0; r<27; r++) {
for(int r=0; r<rounds; r++) {
state1[0] = IotaCurlUtils.TRUTH_TABLE[state2[0] + (state2[364] << 2) + 5];

// state1[0] = IotaCurlUtils.invokeBinaryTruthOn(state2[0], state2[364]);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/iota/curl/IotaCurlMiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private long doWork(final int minWeightMagnitude, long offset) {

private final char[] powInit(final String tx) {

final IotaCurlHash ctx = new IotaCurlHash();
final IotaCurlHash ctx = new IotaCurlHash(27);
final char[] trx = tx.toCharArray();
ctx.doAbsorb(trx, TX_HEADER_SZ);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/iota/curl/miner/Miner.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void main(final String ... args) {
stdout("txTrytes: %s", tx);

// Print hash.
final String hash = IotaCurlHash.iotaCurlHash(tx, TX_LENGTH);
final String hash = IotaCurlHash.iotaCurlHash(tx, TX_LENGTH, 27);
stdout("hash: %s", hash);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/iota/curl/HashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class HashTest {

@Test
public void shouldHash() {
final String hashed = IotaCurlHash.iotaCurlHash(tx, 2673);
final String hashed = IotaCurlHash.iotaCurlHash(tx, 2673, 27);
System.err.println(hashed);
System.err.println(hash);
Assert.assertEquals(hash, hashed);
}

@Test
public void shouldDoHashTransform() {
IotaCurlHash hash = new IotaCurlHash();
IotaCurlHash hash = new IotaCurlHash(27);
int [] state = IntStream.generate(() -> 0).limit(1000).toArray();
System.err.println(Arrays.toString(state));
hash.doHashTransform(state);
Expand Down