Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8012606

Wrongly calculated digest using OracleUcrypto

    Details

      Description

      FULL PRODUCT VERSION :
      java version " 1.7.0_21 "
      Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      SunOS bo-server 5.10 Generic_147440-10 sun4v sparc SUNW,SPARC-Enterprise-T5120

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Crypto provider information:

      Cipher.AES/ECB/NoPadding - com.oracle.security.ucrypto.NativeCipher$AesEcbNoPadding
      MessageDigest.SHA-256 - com.oracle.security.ucrypto.NativeDigest$SHA256
      Alg.Alias.MessageDigest.SHA-1 - SHA
      Cipher.AES/CBC/NoPadding - com.oracle.security.ucrypto.NativeCipher$AesCbcNoPadding
      Provider.id className - com.oracle.security.ucrypto.UcryptoProvider
      MessageDigest.SHA-512 - com.oracle.security.ucrypto.NativeDigest$SHA512
      Provider.id version - 1.0
      MessageDigest.SHA-384 - com.oracle.security.ucrypto.NativeDigest$SHA384
      MessageDigest.MD5 - com.oracle.security.ucrypto.NativeDigest$MD5
      Cipher.AES/ECB/PKCS5Padding - com.oracle.security.ucrypto.NativeCipherWithJavaPadding$AesEcbPKCS5
      Alg.Alias.MessageDigest.SHA1 - SHA
      Provider.id name - OracleUcrypto
      MessageDigest.SHA - com.oracle.security.ucrypto.NativeDigest$SHA1
      Cipher.AES/CBC/PKCS5Padding - com.oracle.security.ucrypto.NativeCipherWithJavaPadding$AesCbcPKCS5
      AlgorithmParameters.GCM - com.oracle.security.ucrypto.GCMParameters
      Provider.id info - Provider using Oracle Ucrypto API
      SHA-384 - OracleUcrypto: MessageDigest.SHA-384 -> com.oracle.security.ucrypto.NativeDigest$SHA384

      SHA - OracleUcrypto: MessageDigest.SHA -> com.oracle.security.ucrypto.NativeDigest$SHA1
        aliases: [SHA1, SHA-1]

      SHA-256 - OracleUcrypto: MessageDigest.SHA-256 -> com.oracle.security.ucrypto.NativeDigest$SHA256

      SHA-512 - OracleUcrypto: MessageDigest.SHA-512 -> com.oracle.security.ucrypto.NativeDigest$SHA512

      AES/CBC/PKCS5Padding - OracleUcrypto: Cipher.AES/CBC/PKCS5Padding -> com.oracle.security.ucrypto.NativeCipherWithJav

      AES/ECB/PKCS5Padding - OracleUcrypto: Cipher.AES/ECB/PKCS5Padding -> com.oracle.security.ucrypto.NativeCipherWithJav

      AES/CBC/NoPadding - OracleUcrypto: Cipher.AES/CBC/NoPadding -> com.oracle.security.ucrypto.NativeCipher$AesCbcNoPadd

      GCM - OracleUcrypto: AlgorithmParameters.GCM -> com.oracle.security.ucrypto.GCMParameters

      MD5 - OracleUcrypto: MessageDigest.MD5 -> com.oracle.security.ucrypto.NativeDigest$MD5

      AES/ECB/NoPadding - OracleUcrypto: Cipher.AES/ECB/NoPadding -> com.oracle.security.ucrypto.NativeCipher$AesEcbNoPadd


      A DESCRIPTION OF THE PROBLEM :
      SHA-1 digest function (and maybe other function, I've tested only SHA-1) seems to be broken using a quite large file (I have tested a ~600MB file) with OracleUCrypto provider (hardware implementation) and sparcv9 64-bit jvm.

      This is the only combination that produces a wrong hash. Using OracleUCrypto with 32-bit jvm works ok, the same using SUN provider (software implementation) with both 64-bit or 32-bit jvm.

      This is the code I've tested:

      File f = new File( " largefile " );
      FileInputStream fis = new FileInputStream();
      byte[] buffer = new byte[(int)f.length()];
      fis.read(buffer);

      MessageDigest md = MessageDigest.getInstance( " SHA-1 " , " OracleUcrypto " );
      byte[] hash = md.digest(buffer); // WRONG HASH!


      Another thing I've noticed is that processing digest in streaming works ok:

      File f = new File( " largefile " );
      FileInputStream fis = new FileInputStream();
      byte[] buffer = new byte[(int)f.length()];
      fis.read(buffer);

      ByteArrayInputStream bais = new ByteArrayInputStream(buf);
      int ch;
      MessageDigest md = MessageDigest.getInstance( " SHA-1 " , " OracleUcrypto " );
      DigestInputStream dis= new DigestInputStream(bais, md);
      buffer = new byte[10*1024*1024];
      while ((ch = dis.read(buffer)) != -1);

      byte[] hash = md.digest(); // OK!


      It seems like Ucrypto has problem processing large byte array ...

      Thanks




      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No errors

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      File f = new File( " largefile " );
      FileInputStream fis = new FileInputStream();
      byte[] buffer = new byte[(int)f.length()];
      fis.read(buffer);

      MessageDigest md = MessageDigest.getInstance( " SHA-1 " , " OracleUcrypto " );
      byte[] hash = md.digest(buffer); // WRONG HASH!

      MessageDigest md = MessageDigest.getInstance( " SHA-1 " , " SUN " );
      byte[] hash2 = md.digest(buffer); // OK!
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Process digest in streaming

        Attachments

          Activity

            People

            • Assignee:
              valeriep Valerie Peng
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: