Skip to content

Commit 8f53ac6

Browse files
committed
fixing the bugs
1 parent e335f95 commit 8f53ac6

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎spotbugs-exclude.xml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,7 @@
178178
<Match>
179179
<Bug pattern="HARD_CODE_KEY" />
180180
</Match>
181+
<Match>
182+
<Bug pattern="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS" />
183+
</Match>
181184
</FindBugsFilter>

‎src/main/java/com/thealgorithms/ciphers/LamportSignature.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public boolean verify(byte[] message, byte[] signature) {
9595
byte[] revealedSecret = Arrays.copyOfRange(signature, bit * SECRET_BYTES, (bit + 1) * SECRET_BYTES);
9696
byte[] expectedHash = publicKey[bit][value];
9797
byte[] actualHash = sha256(revealedSecret);
98-
if (!Arrays.equals(actualHash, expectedHash)) {
98+
if (!MessageDigest.isEqual(actualHash, expectedHash)) {
9999
return false;
100100
}
101101
}

‎src/test/java/com/thealgorithms/ciphers/LamportSignatureTest.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.junit.jupiter.api.Assertions.assertTrue;
77

88
import java.nio.charset.StandardCharsets;
9+
import java.util.Arrays;
910
import org.junit.jupiter.api.Test;
1011

1112
class LamportSignatureTest {
@@ -87,4 +88,14 @@ void testPublicKeyMatchesPrivateKeyHash() {
8788
}
8889
}
8990
}
91+
92+
@Test
93+
void testSha256SliceHelperMatchesRangeHash() {
94+
byte[] message = "hello lamport".getBytes(StandardCharsets.UTF_8);
95+
96+
byte[] expected = LamportSignature.sha256(Arrays.copyOfRange(message, 2, 12));
97+
byte[] actual = LamportSignature.sha256(message, 2, 10);
98+
99+
assertArrayEquals(expected, actual);
100+
}
90101
}

0 commit comments

Comments
 (0)