jdk/src/java.base/share/classes/sun/security/provider/CtrDrbg.java
changeset 38853 971a7101da5b
parent 38462 e3d8ddb3512c
child 39481 63ceb7ef04d4
equal deleted inserted replaced
38852:21057752f324 38853:971a7101da5b
    26 package sun.security.provider;
    26 package sun.security.provider;
    27 
    27 
    28 import javax.crypto.Cipher;
    28 import javax.crypto.Cipher;
    29 import javax.crypto.NoSuchPaddingException;
    29 import javax.crypto.NoSuchPaddingException;
    30 import javax.crypto.spec.SecretKeySpec;
    30 import javax.crypto.spec.SecretKeySpec;
    31 import java.io.IOException;
       
    32 import java.security.*;
    31 import java.security.*;
    33 import java.util.Arrays;
    32 import java.util.Arrays;
    34 import java.util.Locale;
    33 import java.util.Locale;
    35 
    34 
    36 public class CtrDrbg extends AbstractDrbg {
    35 public class CtrDrbg extends AbstractDrbg {
    37 
    36 
    38     private static final long serialVersionUID = 9L;
       
    39     private static final int AES_LIMIT;
    37     private static final int AES_LIMIT;
    40 
    38 
    41     static {
    39     static {
    42         try {
    40         try {
    43             AES_LIMIT = Cipher.getMaxAllowedKeyLength("AES");
    41             AES_LIMIT = Cipher.getMaxAllowedKeyLength("AES");
    45             // should not happen
    43             // should not happen
    46             throw new AssertionError("Cannot detect AES", e);
    44             throw new AssertionError("Cannot detect AES", e);
    47         }
    45         }
    48     }
    46     }
    49 
    47 
    50     private transient Cipher cipher;
    48     private Cipher cipher;
    51 
    49 
    52     private String cipherAlg;
    50     private String cipherAlg;
    53     private String keyAlg;
    51     private String keyAlg;
    54 
    52 
    55     private int ctrLen;
    53     private int ctrLen;
    56     private int blockLen;
    54     private int blockLen;
    57     private int keyLen;
    55     private int keyLen;
    58     private int seedLen;
    56     private int seedLen;
    59 
    57 
    60     private transient byte[] v;
    58     private byte[] v;
    61     private transient byte[] k;
    59     private byte[] k;
    62 
    60 
    63     public CtrDrbg(SecureRandomParameters params) {
    61     public CtrDrbg(SecureRandomParameters params) {
    64         mechName = "CTR_DRBG";
    62         mechName = "CTR_DRBG";
    65         configure(params);
    63         configure(params);
    66     }
    64     }
   163      */
   161      */
   164     @Override
   162     @Override
   165     protected void initEngine() {
   163     protected void initEngine() {
   166         try {
   164         try {
   167             /*
   165             /*
   168              * Use the local SUN implementation to avoid native
   166              * Use the local SunJCE implementation to avoid native
   169              * performance overhead.
   167              * performance overhead.
   170              */
   168              */
   171             cipher = Cipher.getInstance(cipherAlg, "SunJCE");
   169             cipher = Cipher.getInstance(cipherAlg, "SunJCE");
   172         } catch (NoSuchProviderException | NoSuchAlgorithmException
   170         } catch (NoSuchProviderException | NoSuchAlgorithmException
   173                 | NoSuchPaddingException e) {
   171                 | NoSuchPaddingException e) {
   461         //status();
   459         //status();
   462 
   460 
   463         // Step 8. Return
   461         // Step 8. Return
   464     }
   462     }
   465 
   463 
   466     private void readObject(java.io.ObjectInputStream s)
       
   467             throws IOException, ClassNotFoundException {
       
   468         s.defaultReadObject ();
       
   469         initEngine();
       
   470     }
       
   471 
       
   472     @Override
   464     @Override
   473     public String toString() {
   465     public String toString() {
   474         return super.toString() + ","
   466         return super.toString() + ","
   475                 + (usedf ? "use_df" : "no_df");
   467                 + (usedf ? "use_df" : "no_df");
   476     }
   468     }