Skip to content

Commit

Permalink
Some changes are made to fix the issue:
Browse files Browse the repository at this point in the history
"iotaledger#63 Potential for race condition in signing.java". The changes are related
to a problem of race condition in Signing class when using the object
of type ICurl.
  • Loading branch information
githubdevcode authored and frohal committed Dec 24, 2017
1 parent b2f5936 commit c74976b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion jota/src/main/java/jota/utils/Signing.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public int[] key(final int[] inSeed, final int index, int security) throws Argum
}
}

ICurl curl = this.getICurlObject(SpongeFactory.Mode.KERL);
curl.reset();
curl.absorb(seed, 0, seed.length);
// seed[0..HASH_LENGTH] contains subseed
Expand Down Expand Up @@ -97,6 +98,7 @@ public int[] signatureFragment(int[] normalizedBundleFragment, int[] keyFragment

public int[] address(int[] digests) {
int[] address = new int[HASH_LENGTH];
ICurl curl = this.getICurlObject(SpongeFactory.Mode.KERL);
curl.reset()
.absorb(digests)
.squeeze(address);
Expand All @@ -109,6 +111,7 @@ public int[] digests(int[] key) {
int[] digests = new int[security * HASH_LENGTH];
int[] keyFragment = new int[KEY_LENGTH];

ICurl curl = this.getICurlObject(SpongeFactory.Mode.KERL);
for (int i = 0; i < Math.floor(key.length / KEY_LENGTH); i++) {
System.arraycopy(key, i * KEY_LENGTH, keyFragment, 0, KEY_LENGTH);

Expand All @@ -129,7 +132,7 @@ public int[] digests(int[] key) {

public int[] digest(int[] normalizedBundleFragment, int[] signatureFragment) {
curl.reset();
ICurl jCurl = SpongeFactory.create(SpongeFactory.Mode.KERL);
ICurl jCurl = this.getICurlObject(SpongeFactory.Mode.KERL);
int[] buffer = new int[HASH_LENGTH];

for (int i = 0; i < 27; i++) {
Expand Down Expand Up @@ -196,5 +199,9 @@ public Boolean validateSignatures(String expectedAddress, String[] signatureFrag

return (expectedAddress.equals(address));
}

private ICurl getICurlObject(SpongeFactory.Mode mode) {
return SpongeFactory.create(mode);
}
}

0 comments on commit c74976b

Please sign in to comment.