GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Auto-port 5.0: Hash all 8-byte blocks in SipHash.macHash(...) when po… · netty/netty@2ffc6ad

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-classes-quic/src/main/java/io/netty/handler/codec/quic
    • SipHash.java
  • codec-native-quic/src/test/java/io/netty/handler/codec/quic
    • SipHashTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-classes-quic/src/main/java/io/netty/handler/codec/quic/SipHash.java‎

Copy file name to clipboardExpand all lines: codec-classes-quic/src/main/java/io/netty/handler/codec/quic/SipHash.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ long macHash(ByteBuffer input) {
7575
int position = input.position();
7676
int len = remaining - (remaining % Long.BYTES);
7777
boolean needsReverse = input.order() == ByteOrder.BIG_ENDIAN;
78-
for (int offset = position; offset < len; offset += Long.BYTES) {
78+
for (int offset = position; offset < position + len; offset += Long.BYTES) {
7979
long m = input.getLong(offset);
8080
if (needsReverse) {
8181
// We use little-endian as in the paper.
Collapse file

‎codec-native-quic/src/test/java/io/netty/handler/codec/quic/SipHashTest.java‎

Copy file name to clipboardExpand all lines: codec-native-quic/src/test/java/io/netty/handler/codec/quic/SipHashTest.java
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import java.nio.ByteBuffer;
2424
import java.nio.ByteOrder;
25+
import java.util.Arrays;
2526
import java.util.concurrent.ThreadLocalRandom;
2627

2728
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -136,6 +137,25 @@ void testReferenceCases(ReferenceTestParam param) {
136137
assertEquals(param.expectedOutput, h);
137138
}
138139

140+
@ParameterizedTest
141+
@MethodSource("params")
142+
void testReferenceCasesWithPosition(ReferenceTestParam param) {
143+
SipHash hash = new SipHash(2, 4, REFERENCE_SEED);
144+
// Put the input at a non-zero position of a larger buffer.
145+
int position = 13;
146+
byte[] bytes = new byte[position + param.input.length + 7];
147+
Arrays.fill(bytes, (byte) 0x55);
148+
System.arraycopy(param.input, 0, bytes, position, param.input.length);
149+
150+
ByteBuffer heap = ByteBuffer.wrap(bytes, position, param.input.length);
151+
assertEquals(param.expectedOutput, hash.macHash(heap));
152+
153+
ByteBuffer direct = ByteBuffer.allocateDirect(bytes.length);
154+
direct.put(bytes).position(position).limit(position + param.input.length);
155+
assertEquals(param.expectedOutput, hash.macHash(direct));
156+
assertEquals(position, direct.position());
157+
}
158+
139159
@Test
140160
void testHash() {
141161
byte[] bytes = new byte[64];

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.