Skip to content
This repository was archived by the owner on Sep 29, 2021. It is now read-only.

Commit a175714

Browse files
author
jnimeh
committed
8221345: Better Poly1305 support
Reviewed-by: apetcher, mschoene, rhalade
1 parent c414215 commit a175714

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/java.base/share/classes/com/sun/crypto/provider/ChaCha20Cipher.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1363,8 +1363,11 @@ public int doFinal(byte[] in, int inOff, int inLen, byte[] out,
13631363
// Calculate and compare the tag. Only do the decryption
13641364
// if and only if the tag matches.
13651365
authFinalizeData(ctPlusTag, 0, ctLen, tag, 0);
1366-
if (Arrays.compare(ctPlusTag, ctLen, ctPlusTagLen,
1367-
tag, 0, tag.length) != 0) {
1366+
long tagCompare = ((long)asLongView.get(ctPlusTag, ctLen) ^
1367+
(long)asLongView.get(tag, 0)) |
1368+
((long)asLongView.get(ctPlusTag, ctLen + Long.BYTES) ^
1369+
(long)asLongView.get(tag, Long.BYTES));
1370+
if (tagCompare != 0) {
13681371
throw new AEADBadTagException("Tag mismatch");
13691372
}
13701373
chaCha20Transform(ctPlusTag, 0, ctLen, out, outOff);

0 commit comments

Comments
 (0)