3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 15:22:16 +00:00

Added buffer to MnemonicCode, it was modifying it's key argument (stretching in place).

This commit is contained in:
Ken Sedgwick 2013-11-23 22:10:17 -08:00 committed by Mike Hearn
parent ff678d116f
commit 02ce88e6a3

View File

@ -194,11 +194,13 @@ public class MnemonicCode {
// Set block size to input size (that's why Rijndael is used, not AES). // Set block size to input size (that's why Rijndael is used, not AES).
byte[] mnemonic = {'m', 'n', 'e', 'm', 'o', 'n', 'i', 'c'}; byte[] mnemonic = {'m', 'n', 'e', 'm', 'o', 'n', 'i', 'c'};
byte[] key = Sha256Hash.create(mnemonic).getBytes(); byte[] key = Sha256Hash.create(mnemonic).getBytes();
byte[] buffer = new byte[data.length];
System.arraycopy(data, 0, buffer, 0, data.length);
RijndaelEngine cipher = new RijndaelEngine(len); RijndaelEngine cipher = new RijndaelEngine(len);
cipher.init(true, new KeyParameter(key)); cipher.init(true, new KeyParameter(key));
for (int ii = 0; ii < 10000; ++ii) for (int ii = 0; ii < 10000; ++ii)
cipher.processBlock(data, 0, data, 0); cipher.processBlock(buffer, 0, buffer, 0);
return data; return buffer;
} }
private byte[] unstretch(int len, byte[] data) { private byte[] unstretch(int len, byte[] data) {
@ -206,11 +208,13 @@ public class MnemonicCode {
// use the same parameters as used in step 3 of encryption. // use the same parameters as used in step 3 of encryption.
byte[] mnemonic = {'m', 'n', 'e', 'm', 'o', 'n', 'i', 'c'}; byte[] mnemonic = {'m', 'n', 'e', 'm', 'o', 'n', 'i', 'c'};
byte[] key = Sha256Hash.create(mnemonic).getBytes(); byte[] key = Sha256Hash.create(mnemonic).getBytes();
byte[] buffer = new byte[data.length];
System.arraycopy(data, 0, buffer, 0, data.length);
RijndaelEngine cipher = new RijndaelEngine(len); RijndaelEngine cipher = new RijndaelEngine(len);
cipher.init(false, new KeyParameter(key)); cipher.init(false, new KeyParameter(key));
for (int ii = 0; ii < 10000; ++ii) for (int ii = 0; ii < 10000; ++ii)
cipher.processBlock(data, 0, data, 0); cipher.processBlock(buffer, 0, buffer, 0);
return data; return buffer;
} }
private boolean[] checksum(boolean[] bits) { private boolean[] checksum(boolean[] bits) {