src/java.base/share/classes/com/sun/crypto/provider/ChaCha20Cipher.java
changeset 55710 18130ed28231
parent 50323 25d711fca885
child 57791 34bbd91b1522
equal deleted inserted replaced
55709:ce3598fceb87 55710:18130ed28231
     1 /*
     1 /*
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
  1361             }
  1361             }
  1362 
  1362 
  1363             // Calculate and compare the tag.  Only do the decryption
  1363             // Calculate and compare the tag.  Only do the decryption
  1364             // if and only if the tag matches.
  1364             // if and only if the tag matches.
  1365             authFinalizeData(ctPlusTag, 0, ctLen, tag, 0);
  1365             authFinalizeData(ctPlusTag, 0, ctLen, tag, 0);
  1366             if (Arrays.compare(ctPlusTag, ctLen, ctPlusTagLen,
  1366             long tagCompare = ((long)asLongView.get(ctPlusTag, ctLen) ^
  1367                     tag, 0, tag.length) != 0) {
  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) {
  1368                 throw new AEADBadTagException("Tag mismatch");
  1371                 throw new AEADBadTagException("Tag mismatch");
  1369             }
  1372             }
  1370             chaCha20Transform(ctPlusTag, 0, ctLen, out, outOff);
  1373             chaCha20Transform(ctPlusTag, 0, ctLen, out, outOff);
  1371             aadDone = false;
  1374             aadDone = false;
  1372 
  1375