< prev index next >

test/jdk/java/security/MessageDigest/TestSameLength.java

Print this page
rev 59107 : imported patch security


  86             // Get the output
  87             byte[] output = md.digest();
  88 
  89             // Compare input and output
  90             return outputLen == output.length;
  91         } catch (NoSuchAlgorithmException nae) {
  92             if (algo.startsWith("SHA3") && !isSHA3supported()) {
  93                 return true;
  94             }
  95             throw nae;
  96         } catch (Exception ex) {
  97             System.err.println("Testing: " + algo + "/" + dataLen + "/"
  98                     + whichUpdate.toString()
  99                     + " failed with unexpected exception");
 100             ex.printStackTrace();
 101             throw ex;
 102         }
 103     }
 104 
 105     // SHA-3 hash algorithms are only supported by "SUN" provider
 106     // and "OracleUcrypto" provider on Solaris 12.0 or later
 107     // This method checks if system supports SHA-3
 108     private boolean isSHA3supported() {
 109         if (Security.getProvider("SUN") != null) {
 110             return true;
 111         }
 112         if (Security.getProvider("OracleUcrypto") != null
 113                 && "SunOS".equals(System.getProperty("os.name"))
 114                 && System.getProperty("os.version").compareTo("5.12") >= 0) {
 115             return true;
 116         }
 117         return false;
 118     }
 119 
 120     private static enum UpdateMethod {
 121         UPDATE_BYTE {
 122             @Override
 123             public void updateDigest(byte[] data, MessageDigest md,
 124                     long dataLen) {
 125 
 126                 for (int i = 0; i < dataLen; i++) {
 127                     md.update(data[i]);
 128                 }
 129             }
 130         },
 131 
 132         UPDATE_BUFFER {
 133             @Override
 134             public void updateDigest(byte[] data, MessageDigest md,




  86             // Get the output
  87             byte[] output = md.digest();
  88 
  89             // Compare input and output
  90             return outputLen == output.length;
  91         } catch (NoSuchAlgorithmException nae) {
  92             if (algo.startsWith("SHA3") && !isSHA3supported()) {
  93                 return true;
  94             }
  95             throw nae;
  96         } catch (Exception ex) {
  97             System.err.println("Testing: " + algo + "/" + dataLen + "/"
  98                     + whichUpdate.toString()
  99                     + " failed with unexpected exception");
 100             ex.printStackTrace();
 101             throw ex;
 102         }
 103     }
 104 
 105     // SHA-3 hash algorithms are only supported by "SUN" provider

 106     // This method checks if system supports SHA-3
 107     private boolean isSHA3supported() {
 108         if (Security.getProvider("SUN") != null) {





 109             return true;
 110         }
 111         return false;
 112     }
 113 
 114     private static enum UpdateMethod {
 115         UPDATE_BYTE {
 116             @Override
 117             public void updateDigest(byte[] data, MessageDigest md,
 118                     long dataLen) {
 119 
 120                 for (int i = 0; i < dataLen; i++) {
 121                     md.update(data[i]);
 122                 }
 123             }
 124         },
 125 
 126         UPDATE_BUFFER {
 127             @Override
 128             public void updateDigest(byte[] data, MessageDigest md,


< prev index next >