< prev index next >

src/java.base/share/classes/sun/security/provider/SHA3.java

Print this page
rev 60737 : 8252204: AArch64: Implement SHA3 accelerator/intrinsic
Reviewed-by: duke
Contributed-by: dongbo4@huawei.com

@@ -23,10 +23,11 @@
  * questions.
  */
 
 package sun.security.provider;
 
+import jdk.internal.HotSpotIntrinsicCandidate;
 import static sun.security.provider.ByteArrayAccess.*;
 import java.nio.*;
 import java.util.*;
 import java.security.*;
 

@@ -71,15 +72,25 @@
     SHA3(String name, int digestLength, byte suffix, int c) {
         super(name, digestLength, (WIDTH - c));
         this.suffix = suffix;
     }
 
+    private void implCompressCheck(byte[] b, int ofs) {
+        Objects.requireNonNull(b);
+    }
+
     /**
      * Core compression function. Processes blockSize bytes at a time
      * and updates the state of this object.
      */
     void implCompress(byte[] b, int ofs) {
+        implCompressCheck(b, ofs);
+        implCompress0(b, ofs);
+    }
+
+    @HotSpotIntrinsicCandidate
+    private void implCompress0(byte[] b, int ofs) {
         for (int i = 0; i < buffer.length; i++) {
             state[i] ^= b[ofs++];
         }
         keccak();
     }

@@ -92,14 +103,11 @@
         int numOfPadding =
             setPaddingBytes(suffix, buffer, (int)(bytesProcessed % buffer.length));
         if (numOfPadding < 1) {
             throw new ProviderException("Incorrect pad size: " + numOfPadding);
         }
-        for (int i = 0; i < buffer.length; i++) {
-            state[i] ^= buffer[i];
-        }
-        keccak();
+        implCompress(buffer, 0);
         System.arraycopy(state, 0, out, ofs, engineGetDigestLength());
     }
 
     /**
      * Resets the internal state to start a new hash.
< prev index next >