3
0
mirror of https://github.com/Qortal/AT.git synced 2025-01-30 19:02:14 +00:00

Store/use MSB of B for RMD160/HASH160 function codes.

Previously used LSB of B but wasn't updated since switch to big-endian.
This commit is contained in:
catbref 2020-04-14 15:06:51 +01:00
parent aadf987514
commit 6dc717f3de
2 changed files with 11 additions and 11 deletions

View File

@ -593,9 +593,9 @@ public enum FunctionCode {
ByteBuffer digestByteBuffer = ByteBuffer.wrap(digest); ByteBuffer digestByteBuffer = ByteBuffer.wrap(digest);
state.b1 = (long) digestByteBuffer.getInt() & 0xffffffffL; state.b1 = digestByteBuffer.getLong();
state.b2 = digestByteBuffer.getLong(); state.b2 = digestByteBuffer.getLong();
state.b3 = digestByteBuffer.getLong(); state.b3 = ((long) digestByteBuffer.getInt()) << 32; // MSB of B3
state.b4 = 0L; state.b4 = 0L;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new ExecutionException("No RIPEMD160 message digest service available", e); throw new ExecutionException("No RIPEMD160 message digest service available", e);
@ -619,9 +619,9 @@ public enum FunctionCode {
ByteBuffer digestByteBuffer = ByteBuffer.allocate(digester.getDigestLength()); ByteBuffer digestByteBuffer = ByteBuffer.allocate(digester.getDigestLength());
digestByteBuffer.putInt((int) (state.b1 & 0xffffffffL)); digestByteBuffer.putLong(state.b1);
digestByteBuffer.putLong(state.b2); digestByteBuffer.putLong(state.b2);
digestByteBuffer.putLong(state.b3); digestByteBuffer.putInt((int) (state.b3 >>> 32)); // MSB of B3
// NOTE: b4 ignored // NOTE: b4 ignored
byte[] expectedDigest = digestByteBuffer.array(); byte[] expectedDigest = digestByteBuffer.array();
@ -713,9 +713,9 @@ public enum FunctionCode {
ByteBuffer digestByteBuffer = ByteBuffer.wrap(rmd160Digest); ByteBuffer digestByteBuffer = ByteBuffer.wrap(rmd160Digest);
state.b1 = (long) digestByteBuffer.getInt() & 0xffffffffL; state.b1 = digestByteBuffer.getLong();
state.b2 = digestByteBuffer.getLong(); state.b2 = digestByteBuffer.getLong();
state.b3 = digestByteBuffer.getLong(); state.b3 = ((long) digestByteBuffer.getInt()) << 32; // MSB of B3
state.b4 = 0L; state.b4 = 0L;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new ExecutionException("No SHA-256 or RIPEMD160 message digest service available", e); throw new ExecutionException("No SHA-256 or RIPEMD160 message digest service available", e);
@ -742,9 +742,9 @@ public enum FunctionCode {
ByteBuffer digestByteBuffer = ByteBuffer.allocate(rmd160Digester.getDigestLength()); ByteBuffer digestByteBuffer = ByteBuffer.allocate(rmd160Digester.getDigestLength());
digestByteBuffer.putInt((int) (state.b1 & 0xffffffffL)); digestByteBuffer.putLong(state.b1);
digestByteBuffer.putLong(state.b2); digestByteBuffer.putLong(state.b2);
digestByteBuffer.putLong(state.b3); digestByteBuffer.putInt((int) (state.b3 >>> 32)); // MSB of B3
// NOTE: b4 ignored // NOTE: b4 ignored
byte[] expectedDigest = digestByteBuffer.array(); byte[] expectedDigest = digestByteBuffer.array();

View File

@ -131,15 +131,15 @@ public class HashingFunctionCodeTests extends ExecutableTest {
int numLongs = (expected.length() + 15) / 16; int numLongs = (expected.length() + 15) / 16;
for (int longIndex = 0; longIndex < numLongs; ++longIndex) { for (int longIndex = 0; longIndex < numLongs; ++longIndex) {
final int endIndex = expected.length() - (numLongs - longIndex - 1) * 16; final int beginIndex = longIndex * 16;
final int beginIndex = Math.max(0, endIndex - 16); final int endIndex = Math.min(expected.length(), beginIndex + 16);
String hexChars = expected.substring(beginIndex, endIndex); String hexChars = expected.substring(beginIndex, endIndex);
codeByteBuffer.put(OpCode.SET_VAL.value); codeByteBuffer.put(OpCode.SET_VAL.value);
codeByteBuffer.putInt(0); // addr 0 codeByteBuffer.putInt(0); // addr 0
codeByteBuffer.put(new byte[8 - hexChars.length() / 2]); // pad LSB with zeros
codeByteBuffer.put(hexToBytes(hexChars)); codeByteBuffer.put(hexToBytes(hexChars));
codeByteBuffer.put(new byte[8 - hexChars.length() / 2]); // pad LSB with zeros
final FunctionCode bSettingFunction = bSettingFunctions[longIndex]; final FunctionCode bSettingFunction = bSettingFunctions[longIndex];
codeByteBuffer.put(OpCode.EXT_FUN_DAT.value).putShort(bSettingFunction.value).putInt(0); codeByteBuffer.put(OpCode.EXT_FUN_DAT.value).putShort(bSettingFunction.value).putInt(0);