Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/bouncycastle/crypto/tls/DTLSReplayWindow.java')
-rw-r--r--src/main/java/org/bouncycastle/crypto/tls/DTLSReplayWindow.java28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/main/java/org/bouncycastle/crypto/tls/DTLSReplayWindow.java b/src/main/java/org/bouncycastle/crypto/tls/DTLSReplayWindow.java
index b8809487..98e050ce 100644
--- a/src/main/java/org/bouncycastle/crypto/tls/DTLSReplayWindow.java
+++ b/src/main/java/org/bouncycastle/crypto/tls/DTLSReplayWindow.java
@@ -2,10 +2,11 @@ package org.bouncycastle.crypto.tls;
/**
* RFC 4347 4.1.2.5 Anti-replay
- *
+ * <p/>
* Support fast rejection of duplicate records by maintaining a sliding receive window
*/
-class DTLSReplayWindow {
+class DTLSReplayWindow
+{
private static final long VALID_SEQ_MASK = 0x0000FFFFFFFFFFFFL;
@@ -16,22 +17,28 @@ class DTLSReplayWindow {
/**
* Check whether a received record with the given sequence number should be rejected as a duplicate.
- *
- * @param seq the 48-bit DTLSPlainText.sequence_number field of a received record.
+ *
+ * @param seq the 48-bit DTLSPlainText.sequence_number field of a received record.
* @return true if the record should be discarded without further processing.
*/
boolean shouldDiscard(long seq)
{
if ((seq & VALID_SEQ_MASK) != seq)
+ {
return true;
+ }
if (seq <= latestConfirmedSeq)
{
long diff = latestConfirmedSeq - seq;
if (diff >= WINDOW_SIZE)
+ {
return true;
+ }
if ((bitmap & (1L << diff)) != 0)
+ {
return true;
+ }
}
return false;
@@ -39,28 +46,33 @@ class DTLSReplayWindow {
/**
* Report that a received record with the given sequence number passed authentication checks.
- *
+ *
* @param seq the 48-bit DTLSPlainText.sequence_number field of an authenticated record.
*/
void reportAuthenticated(long seq)
{
if ((seq & VALID_SEQ_MASK) != seq)
+ {
throw new IllegalArgumentException("'seq' out of range");
+ }
if (seq <= latestConfirmedSeq)
{
long diff = latestConfirmedSeq - seq;
- if (diff < WINDOW_SIZE) {
+ if (diff < WINDOW_SIZE)
+ {
bitmap |= (1L << diff);
}
}
else
{
long diff = seq - latestConfirmedSeq;
- if (diff >= WINDOW_SIZE) {
+ if (diff >= WINDOW_SIZE)
+ {
bitmap = 1;
}
- else {
+ else
+ {
bitmap <<= diff;
bitmap |= 1;
}