Skip to content
This repository was archived by the owner on Jul 25, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/test/java/com/codahale/shamir/GF256Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,22 @@ void eval() {
assertThat(GF256.eval(new byte[] {1, 0, 2, 3}, (byte) 2)).isEqualTo((byte) 17);
}

private static class ZeroLastByteFirstTWoAttemptsSecureRandom extends SecureRandom {
private int counter = 2;

@Override
public void nextBytes(byte[] b) {
super.nextBytes(b);
if (counter > 0) {
b[b.length - 1] = 0;
counter--;
}
}
}

@Test
void generate() {
final SecureRandom random = new SecureRandom();
final SecureRandom random = new ZeroLastByteFirstTWoAttemptsSecureRandom();
final byte[] p = GF256.generate(random, 5, (byte) 20);
assertThat(p[0]).isEqualTo((byte) 20);
assertThat(p.length).isEqualTo(6);
Expand Down