This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
[PAN-2842] Blake 2b tweaks #1862
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2e9725d
[PAN-2842] Blake 2b tweaks
shemnon ae05fa7
spotless
shemnon 5cac1e5
* missed some conformance tests
shemnon f6f3bc7
another test to update after endian switch
shemnon 4c9cd45
Merge branch 'master' into istanbul
shemnon 53ba495
Merge branch 'master' into istanbul
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,21 +27,21 @@ public class Blake2bfMessageDigestTest { | |
private Blake2bfMessageDigest messageDigest; | ||
|
||
// output when input is all 0 | ||
private byte[] blake2bfAllZero = | ||
private static final byte[] BLAKE2F_ALL_ZERO = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where are these test cases coming from? Is there a spec we can link to? Would the tests be clearer if kept these values as hexary strings? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests are not as useful as the precompiled test vectors. Those have more coverage. As far as I can tell they were calculated from the blake RFC. |
||
new byte[] { | ||
106, 9, -26, 103, -13, -68, -55, 8, -69, 103, -82, -123, -124, -54, -89, 59, 60, 110, -13, | ||
114, -2, -108, -8, 43, -91, 79, -11, 58, 95, 29, 54, -15, 81, 14, 82, 127, -83, -26, -126, | ||
-47, -101, 5, 104, -116, 43, 62, 108, 31, 31, -125, -39, -85, -5, 65, -67, 107, 91, -32, | ||
-51, 25, 19, 126, 33, 121 | ||
8, -55, -68, -13, 103, -26, 9, 106, 59, -89, -54, -124, -123, -82, 103, -69, 43, -8, -108, | ||
-2, 114, -13, 110, 60, -15, 54, 29, 95, 58, -11, 79, -91, -47, -126, -26, -83, 127, 82, 14, | ||
81, 31, 108, 62, 43, -116, 104, 5, -101, 107, -67, 65, -5, -85, -39, -125, 31, 121, 33, 126, | ||
19, 25, -51, -32, 91 | ||
}; | ||
|
||
// output when input is all 0 for 2147483648 rounds | ||
private byte[] blake2bfAllZeroNegativeRounds = | ||
// output when input is all 0 for 4294967295 rounds | ||
private static final byte[] BLAKE2F_ALL_ZERO_NEGATIVE_ROUNDS = | ||
new byte[] { | ||
118, 127, 109, 29, 115, -124, -99, -111, 81, 112, 35, 60, -89, 75, 21, 18, -97, -73, 19, | ||
-102, 40, -8, 78, 110, -43, 124, 66, 83, -89, 69, 69, 57, -25, -105, 123, 117, 115, 115, 78, | ||
-92, 123, 87, 14, -127, -94, -1, -74, 25, -125, 48, 54, -78, -82, -75, 84, -26, -38, -42, | ||
-93, 120, -61, 7, -58, 38 | ||
-111, -99, -124, 115, 29, 109, 127, 118, 18, 21, 75, -89, 60, 35, 112, 81, 110, 78, -8, 40, | ||
-102, 19, -73, -97, 57, 69, 69, -89, 83, 66, 124, -43, -92, 78, 115, 115, 117, 123, -105, | ||
-25, 25, -74, -1, -94, -127, 14, 87, 123, -26, 84, -75, -82, -78, 54, 48, -125, 38, -58, 7, | ||
-61, 120, -93, -42, -38 | ||
}; | ||
|
||
@Before | ||
|
@@ -54,32 +54,32 @@ public void digestIfUpdatedCorrectlyWithBytes() { | |
for (int i = 0; i < 213; i++) { | ||
messageDigest.update((byte) 0); | ||
} | ||
assertThat(messageDigest.digest()).isEqualTo(blake2bfAllZero); | ||
assertThat(messageDigest.digest()).isEqualTo(BLAKE2F_ALL_ZERO); | ||
} | ||
|
||
@Test | ||
public void digestIfUpdatedCorrectlyWithByteArray() { | ||
byte[] update = new byte[213]; | ||
final byte[] update = new byte[213]; | ||
messageDigest.update(update, 0, 213); | ||
assertThat(messageDigest.digest()).isEqualTo(blake2bfAllZero); | ||
assertThat(messageDigest.digest()).isEqualTo(BLAKE2F_ALL_ZERO); | ||
} | ||
|
||
@Test | ||
public void digestIfUpdatedCorrectlyMixed() { | ||
byte[] update = new byte[213]; | ||
final byte[] update = new byte[213]; | ||
messageDigest.update((byte) 0); | ||
messageDigest.update(update, 2, 211); | ||
messageDigest.update((byte) 0); | ||
assertThat(messageDigest.digest()).isEqualTo(blake2bfAllZero); | ||
assertThat(messageDigest.digest()).isEqualTo(BLAKE2F_ALL_ZERO); | ||
} | ||
|
||
@Test | ||
public void digestWithNegativeRounds() { | ||
// equal to Integer.MAX_VALUE + 1 (2147483648) as uint | ||
byte[] rounds = Pack.intToBigEndian(Integer.MIN_VALUE); | ||
public void digestWithMaxRounds() { | ||
// equal to unsigned int max value (4294967295, or signed -1) | ||
final byte[] rounds = Pack.intToBigEndian(Integer.MIN_VALUE); | ||
messageDigest.update(rounds, 0, 4); | ||
messageDigest.update(new byte[213], 0, 209); | ||
assertThat(messageDigest.digest()).isEqualTo(blake2bfAllZeroNegativeRounds); | ||
assertThat(messageDigest.digest()).isEqualTo(BLAKE2F_ALL_ZERO_NEGATIVE_ROUNDS); | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
|
@@ -99,14 +99,14 @@ public void throwsIfBufferUpdatedWithMoreThat213Bytes() { | |
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void throwsIfBufferUpdatedLargeByteArray() { | ||
byte[] update = new byte[213]; | ||
final byte[] update = new byte[213]; | ||
messageDigest.update((byte) 0); | ||
messageDigest.update(update, 0, 213); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void throwsIfEmptyBufferUpdatedLargeByteArray() { | ||
byte[] update = new byte[214]; | ||
final byte[] update = new byte[214]; | ||
messageDigest.update(update, 0, 214); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty bizarre that the payload is a mix of big endian and little endian values :\
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. But that's what some web3/solidity folks asked for in the EIP and got.