signing: bugfix for key generation for seeds >81 trytes

This commit is contained in:
Andreas C. Osowski 2017-11-05 23:55:00 +01:00
parent 7525934a41
commit 022f1665aa
2 changed files with 15 additions and 2 deletions

View File

@ -39,7 +39,7 @@ public class Signing {
* @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
*/
public int[] key(final int[] inSeed, final int index, int security) throws InvalidSecurityLevelException {
if (security < 1 || security > 3) {
if (security < 1) {
throw new InvalidSecurityLevelException();
}
@ -70,7 +70,7 @@ public class Signing {
while (security-- > 0) {
for (int i = 0; i < 27; i++) {
curl.squeeze(key, offset, HASH_LENGTH);
offset += seed.length;
offset += HASH_LENGTH;
}
}
return key;

View File

@ -3,6 +3,8 @@ package jota;
import jota.error.InvalidAddressException;
import jota.error.InvalidSecurityLevelException;
import jota.model.Bundle;
import jota.pow.ICurl;
import jota.pow.SpongeFactory;
import jota.utils.*;
import org.junit.Test;
@ -28,6 +30,17 @@ public class SigningTest {
assertEquals(SIXTH_ADDR, IotaAPIUtils.newAddress(TEST_SEED, 2, 5, true, null));
}
@Test
public void testLongSeedKeyGeneration() throws InvalidSecurityLevelException {
ICurl curl = SpongeFactory.create(SpongeFactory.Mode.KERL);
Signing signing = new Signing(curl);
String seed = "EV9QRJFJZVFNLYUFXWKXMCRRPNAZYQVEYB9VEPUHQNXJCWKZFVUCTQJFCUAMXAHMMIUQUJDG9UGGQBPIY";
int[] key1 = signing.key(Converter.trits(seed), 0, 1);
int[] key2 = signing.key(Converter.trits(seed+seed), 0, 1);
int[] key3 = signing.key(Converter.trits(seed+seed+seed), 0, 1);
}
@Test
public void testSigning() throws InvalidAddressException, InvalidSecurityLevelException {
// we can sign any hash, so for convenience we will sign the first