Skip to content

Commit 9d44dd0

Browse files
vpaprotskJamil Nimeh
authored and
Jamil Nimeh
committed
8297972: Poly1305 Endianness on ByteBuffer not enforced
Reviewed-by: jnimeh
1 parent facd415 commit 9d44dd0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/java.base/share/classes/sun/security/util/math/intpoly/IntegerPolynomial1305.java

+3
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,16 @@ protected void square(long[] a, long[] r) {
127127
@Override
128128
protected void encode(ByteBuffer buf, int length, byte highByte,
129129
long[] result) {
130+
ByteOrder currOrder = buf.order();
131+
buf.order(ByteOrder.LITTLE_ENDIAN);
130132
if (length == 16) {
131133
long low = buf.getLong();
132134
long high = buf.getLong();
133135
encode(high, low, highByte, result);
134136
} else {
135137
super.encode(buf, length, highByte, result);
136138
}
139+
buf.order(currOrder);
137140
}
138141

139142
protected void encode(long high, long low, byte highByte, long[] result) {

test/jdk/com/sun/crypto/provider/Cipher/ChaCha20/unittest/java.base/com/sun/crypto/provider/Poly1305IntrinsicFuzzTest.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,17 @@ static void fastUpdate(Poly1305 authenticator, Random rnd, byte[] message, int o
103103
authenticator.engineUpdate(message, offset, len);
104104
break;
105105
case 1: // ByteArray with backing array
106-
buf = ByteBuffer.wrap(message, offset, len)
107-
.order(java.nio.ByteOrder.LITTLE_ENDIAN);
106+
buf = ByteBuffer.wrap(message, offset, len);
108107
authenticator.engineUpdate(buf);
109108
break;
110109
case 2: // ByteArray with backing array (non-zero position)
111110
buf = ByteBuffer.wrap(message, 0, len+offset)
112-
.order(java.nio.ByteOrder.LITTLE_ENDIAN)
113111
.position(offset);
114112
authenticator.engineUpdate(buf);
115113
break;
116114
case 3: // ByteArray without backing array (wont be sent to intrinsic)
117115
buf = ByteBuffer.wrap(message, offset, len)
118-
.asReadOnlyBuffer()
119-
.order(java.nio.ByteOrder.LITTLE_ENDIAN);
116+
.asReadOnlyBuffer();
120117
authenticator.engineUpdate(buf);
121118
break;
122119
}

0 commit comments

Comments
 (0)