jdk/src/java.base/share/classes/sun/security/provider/SHA5.java
changeset 37796 256c45c4af5d
parent 31671 362e0c0acece
equal deleted inserted replaced
37795:c5dc5ab60139 37796:256c45c4af5d
     1 /*
     1 /*
     2  * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2002, 2016, 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
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package sun.security.provider;
    26 package sun.security.provider;
    27 
    27 
    28 import java.security.*;
       
    29 import java.util.Objects;
    28 import java.util.Objects;
    30 import java.math.BigInteger;
       
    31 
    29 
    32 import jdk.internal.HotSpotIntrinsicCandidate;
    30 import jdk.internal.HotSpotIntrinsicCandidate;
    33 import static sun.security.provider.ByteArrayAccess.*;
    31 import static sun.security.provider.ByteArrayAccess.*;
    34 
    32 
    35 /**
    33 /**
   116 
   114 
   117         i2bBig4((int)(bitsProcessed >>> 32), buffer, 120);
   115         i2bBig4((int)(bitsProcessed >>> 32), buffer, 120);
   118         i2bBig4((int)bitsProcessed, buffer, 124);
   116         i2bBig4((int)bitsProcessed, buffer, 124);
   119         implCompress(buffer, 0);
   117         implCompress(buffer, 0);
   120 
   118 
   121         l2bBig(state, 0, out, ofs, engineGetDigestLength());
   119         int len = engineGetDigestLength();
       
   120         if (len == 28) {
       
   121             // Special case for SHA-512/224
       
   122             l2bBig(state, 0, out, ofs, 24);
       
   123             i2bBig4((int)(state[3] >> 32), out, ofs + 24);
       
   124         } else {
       
   125             l2bBig(state, 0, out, ofs, len);
       
   126         }
   122     }
   127     }
   123 
   128 
   124     /**
   129     /**
   125      * logical function ch(x,y,z) as defined in spec:
   130      * logical function ch(x,y,z) as defined in spec:
   126      * @return (x and y) xor ((complement x) and z)
   131      * @return (x and y) xor ((complement x) and z)
   304 
   309 
   305         public SHA384() {
   310         public SHA384() {
   306             super("SHA-384", 48, INITIAL_HASHES);
   311             super("SHA-384", 48, INITIAL_HASHES);
   307         }
   312         }
   308     }
   313     }
       
   314     public static final class SHA512_224 extends SHA5 {
       
   315 
       
   316         private static final long[] INITIAL_HASHES = {
       
   317                 0x8C3D37C819544DA2L, 0x73E1996689DCD4D6L,
       
   318                 0x1DFAB7AE32FF9C82L, 0x679DD514582F9FCFL,
       
   319                 0x0F6D2B697BD44DA8L, 0x77E36F7304C48942L,
       
   320                 0x3F9D85A86A1D36C8L, 0x1112E6AD91D692A1L
       
   321         };
       
   322 
       
   323         public SHA512_224() {
       
   324             super("SHA-512/224", 28, INITIAL_HASHES);
       
   325         }
       
   326     }
       
   327 
       
   328     public static final class SHA512_256 extends SHA5 {
       
   329 
       
   330         private static final long[] INITIAL_HASHES = {
       
   331                 0x22312194FC2BF72CL, 0x9F555FA3C84C64C2L,
       
   332                 0x2393B86B6F53B151L, 0x963877195940EABDL,
       
   333                 0x96283EE2A88EFFE3L, 0xBE5E1E2553863992L,
       
   334                 0x2B0199FC2C85B8AAL, 0x0EB72DDC81C52CA2L
       
   335         };
       
   336 
       
   337         public SHA512_256() {
       
   338             super("SHA-512/256", 32, INITIAL_HASHES);
       
   339         }
       
   340     }
   309 }
   341 }