< prev index next >

test/jdk/java/security/MessageDigest/TestSameValue.java

Print this page
rev 59107 : imported patch security


  74                                 "Test failed at algorithm/provider/numUpdate:"
  75                                         + algorithm + "/" + md.getProvider()
  76                                         + "/" + updateMethod);
  77                     }
  78                 }
  79             } catch (NoSuchAlgorithmException nae) {
  80                 if (algorithm.startsWith("SHA3") && !isSHA3supported()) {
  81                     continue;
  82                 } else {
  83                     throw nae;
  84                 }
  85             }
  86         }
  87 
  88         out.println("All "
  89                 + algorithmArr.length * UpdateDigestMethod.values().length
  90                 + " tests Passed");
  91     }
  92 
  93     // SHA-3 hash algorithms are only supported by "SUN" provider
  94     // and "OracleUcrypto" provider on Solaris 12.0 or later
  95     // This method checks if system supports SHA-3
  96     private boolean isSHA3supported() {
  97         if (Security.getProvider("SUN") != null) {
  98             return true;
  99         }
 100         if (Security.getProvider("OracleUcrypto") != null
 101                 && "SunOS".equals(System.getProperty("os.name"))
 102                 && System.getProperty("os.version").compareTo("5.12") >= 0) {
 103             return true;
 104         }
 105         return false;
 106     }
 107 
 108     private static enum UpdateDigestMethod {
 109 
 110         /*
 111          * update the data one by one using method update(byte input) then do
 112          * digest (giving the output buffer, offset, and the number of bytes to
 113          * put in the output buffer)
 114          */
 115         UPDATE_DIGEST_BUFFER {
 116             @Override
 117             public byte[] updateDigest(byte[] data, MessageDigest md)
 118                     throws DigestException {
 119                 for (byte element : data) {
 120                     md.update(element);
 121                 }
 122                 byte[] output = new byte[md.getDigestLength()];




  74                                 "Test failed at algorithm/provider/numUpdate:"
  75                                         + algorithm + "/" + md.getProvider()
  76                                         + "/" + updateMethod);
  77                     }
  78                 }
  79             } catch (NoSuchAlgorithmException nae) {
  80                 if (algorithm.startsWith("SHA3") && !isSHA3supported()) {
  81                     continue;
  82                 } else {
  83                     throw nae;
  84                 }
  85             }
  86         }
  87 
  88         out.println("All "
  89                 + algorithmArr.length * UpdateDigestMethod.values().length
  90                 + " tests Passed");
  91     }
  92 
  93     // SHA-3 hash algorithms are only supported by "SUN" provider

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





  97             return true;
  98         }
  99         return false;
 100     }
 101 
 102     private static enum UpdateDigestMethod {
 103 
 104         /*
 105          * update the data one by one using method update(byte input) then do
 106          * digest (giving the output buffer, offset, and the number of bytes to
 107          * put in the output buffer)
 108          */
 109         UPDATE_DIGEST_BUFFER {
 110             @Override
 111             public byte[] updateDigest(byte[] data, MessageDigest md)
 112                     throws DigestException {
 113                 for (byte element : data) {
 114                     md.update(element);
 115                 }
 116                 byte[] output = new byte[md.getDigestLength()];


< prev index next >