Skip to content

Commit

Permalink
v 0.6.4, minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelGorny committed Dec 4, 2020
1 parent 5dcc34d commit d6495ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.pawelgorny</groupId>
<artifactId>lostword</artifactId>
<version>0.6.3</version>
<version>0.6.4</version>
<packaging>jar</packaging>

<dependencies>
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/com/pawelgorny/lostword/WorkerKnownPosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.bouncycastle.crypto.macs.HMac;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -61,6 +60,17 @@ private void checkUnknown(int position) throws InterruptedException {
List<String> mnemonic = new ArrayList<>(configuration.getWORDS());
List<List<String>> DICTIONARY = split();
int nextPosition = getNextUnknown(1+position, configuration.getWORDS());

final List<MessageDigest> SHA_256_DIGESTS= new ArrayList<>(THREADS);
final List<HMac> SHA_512_DIGESTS= new ArrayList<>(THREADS);
for (int t=0; t<THREADS; t++){
try {
SHA_512_DIGESTS.add(createHmacSha512Digest());
SHA_256_DIGESTS.add(MessageDigest.getInstance("SHA-256"));
}catch (Exception e){
}
}

for (int w0=configuration.getKnownStart(); RESULT==null && w0<DICTIONARY_SIZE; w0++){
String processedWord = Configuration.MNEMONIC_CODE.getWordList().get(w0);
System.out.println("Processing word "+(w0+1)+"/"+DICTIONARY_SIZE+" on position "+(position+1)+"! '"+processedWord+"' "+SDF.format(new Date()));
Expand All @@ -72,17 +82,13 @@ private void checkUnknown(int position) throws InterruptedException {
final List<String> SEED = new ArrayList<>(mnemonic);
final List<String> WORDS_TO_WORK = DICTIONARY.get(t);
final boolean REPORTER = t==0;
final int T_NUMBER=t;
executorService.submit(() -> {
if (REPORTER) {
start = System.currentTimeMillis();
}
final HMac LOCAL_SHA_512_DIGEST = createHmacSha512Digest();
final MessageDigest LOCAL_SHA_256_DIGEST;
try {
LOCAL_SHA_256_DIGEST = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException var1) {
throw new RuntimeException(var1);
}
final HMac LOCAL_SHA_512_DIGEST = SHA_512_DIGESTS.get(T_NUMBER);
final MessageDigest LOCAL_SHA_256_DIGEST = SHA_256_DIGESTS.get(T_NUMBER);
try {
int WORKING_POSITION_PLUS = WORKING_POSITION+1;
for (int bipPosition = 0; RESULT == null && bipPosition < WORDS_TO_WORK.size(); bipPosition++) {
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/com/pawelgorny/lostword/util/PBKDF2SHA512.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ public static byte[] derive(byte[] mnemonicBytes, byte[] salt, int c, int dkLen)
SecretKeySpec key = new SecretKeySpec(mnemonicBytes, mac.getAlgorithm());
mac.init(key);

for(int i = 1; i <= 4; ++i) {
byte[] T = F(salt, c, i, mac);
baos.write(T);
}
byte[] T = F(salt, c, (byte)1, mac);
baos.write(T);

// for(byte i = 1; i <= 4; ++i) {
// byte[] T = F(salt, c, i, mac);
// baos.write(T);
// break;
// }
} catch (Exception var9) {
throw new RuntimeException(var9);
}
Expand All @@ -30,17 +34,18 @@ public static byte[] derive(byte[] mnemonicBytes, byte[] salt, int c, int dkLen)
return var10;
}

private static byte[] F(byte[] salt, int c, int i, Mac mac) throws Exception {
private static byte[] F(byte[] salt, int c, byte i, Mac mac) throws Exception {
byte[] U_LAST = null;
byte[] U_XOR = null;
for(int j = 0; j < c; ++j) {
byte[] baU;
if(j == 0) {
baU = salt;
byte[] var12 = INT(i);
// byte[] var12 = INT(i);
byte[] baU1 = new byte[12];
System.arraycopy(baU, 0, baU1, 0, 8);
System.arraycopy(var12, 0, baU1, 8, 4);
// System.arraycopy(var12, 0, baU1, 8, 4);
baU1[11] = i;
U_XOR = mac.doFinal(baU1);
U_LAST = U_XOR;
} else {
Expand Down

0 comments on commit d6495ec

Please sign in to comment.