Browse Source

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

Previously used LSB of B but wasn't updated since switch to big-endian.
master
catbref 4 years ago
parent
commit
6dc717f3de
  1. 16
      Java/src/main/java/org/ciyam/at/FunctionCode.java
  2. 6
      Java/src/test/java/org/ciyam/at/HashingFunctionCodeTests.java

16
Java/src/main/java/org/ciyam/at/FunctionCode.java

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

6
Java/src/test/java/org/ciyam/at/HashingFunctionCodeTests.java

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

Loading…
Cancel
Save